0
|
1 /* Random utility Lisp functions.
|
|
2 Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
23
|
|
24 /* This file has been Mule-ized. */
|
|
25
|
|
26 /* Note: FSF 19.30 has bool vectors. We have bit vectors. */
|
|
27
|
|
28 /* Hacked on for Mule by Ben Wing, December 1994, January 1995. */
|
|
29
|
|
30 #include <config.h>
|
|
31
|
|
32 /* Note on some machines this defines `vector' as a typedef,
|
|
33 so make sure we don't use that name in this file. */
|
|
34 #undef vector
|
|
35 #define vector *****
|
|
36
|
|
37 #include "lisp.h"
|
|
38
|
|
39 #include "buffer.h"
|
|
40 #include "bytecode.h"
|
|
41 #include "commands.h"
|
|
42 #include "device.h"
|
|
43 #include "events.h"
|
|
44 #include "extents.h"
|
|
45 #include "frame.h"
|
|
46 #include "systime.h"
|
|
47
|
140
|
48 /* NOTE: This symbol is also used in lread.c */
|
|
49 #define FEATUREP_SYNTAX
|
|
50
|
0
|
51 Lisp_Object Qstring_lessp;
|
|
52 Lisp_Object Qidentity;
|
|
53
|
|
54 static Lisp_Object mark_bit_vector (Lisp_Object, void (*) (Lisp_Object));
|
|
55 static void print_bit_vector (Lisp_Object, Lisp_Object, int);
|
|
56 static int bit_vector_equal (Lisp_Object o1, Lisp_Object o2, int depth);
|
|
57 static unsigned long bit_vector_hash (Lisp_Object obj, int depth);
|
|
58 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bit-vector", bit_vector,
|
|
59 mark_bit_vector, print_bit_vector, 0,
|
|
60 bit_vector_equal, bit_vector_hash,
|
|
61 struct Lisp_Bit_Vector);
|
|
62
|
|
63 static Lisp_Object
|
|
64 mark_bit_vector (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
65 {
|
|
66 return (Qnil);
|
|
67 }
|
|
68
|
|
69 static void
|
|
70 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
71 {
|
|
72 int i;
|
|
73 struct Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
|
|
74 int len = bit_vector_length (v);
|
|
75 int last = len;
|
|
76
|
|
77 if (INTP (Vprint_length))
|
|
78 last = min (len, XINT (Vprint_length));
|
|
79 write_c_string ("#*", printcharfun);
|
|
80 for (i = 0; i < last; i++)
|
|
81 {
|
|
82 if (bit_vector_bit (v, i))
|
|
83 write_c_string ("1", printcharfun);
|
|
84 else
|
|
85 write_c_string ("0", printcharfun);
|
|
86 }
|
|
87
|
|
88 if (last != len)
|
|
89 write_c_string ("...", printcharfun);
|
|
90 }
|
|
91
|
|
92 static int
|
|
93 bit_vector_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
94 {
|
|
95 struct Lisp_Bit_Vector *v1 = XBIT_VECTOR (o1);
|
|
96 struct Lisp_Bit_Vector *v2 = XBIT_VECTOR (o2);
|
|
97
|
|
98 if (bit_vector_length (v1) != bit_vector_length (v2))
|
|
99 return 0;
|
|
100
|
|
101 return !memcmp (v1->bits, v2->bits,
|
|
102 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) *
|
|
103 sizeof (long));
|
|
104 }
|
|
105
|
|
106 static unsigned long
|
|
107 bit_vector_hash (Lisp_Object obj, int depth)
|
|
108 {
|
|
109 struct Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
|
|
110 return HASH2 (bit_vector_length (v),
|
|
111 memory_hash (v->bits,
|
|
112 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) *
|
|
113 sizeof (long)));
|
|
114 }
|
|
115
|
20
|
116 DEFUN ("identity", Fidentity, 1, 1, 0, /*
|
0
|
117 Return the argument unchanged.
|
20
|
118 */
|
|
119 (arg))
|
0
|
120 {
|
|
121 return arg;
|
|
122 }
|
|
123
|
|
124 extern long get_random (void);
|
|
125 extern void seed_random (long arg);
|
|
126
|
20
|
127 DEFUN ("random", Frandom, 0, 1, 0, /*
|
0
|
128 Return a pseudo-random number.
|
102
|
129 All integers representable in Lisp are equally likely.
|
|
130 On most systems, this is 28 bits' worth.
|
|
131 With positive integer argument N, return random number in interval [0,N).
|
0
|
132 With argument t, set the random number seed from the current time and pid.
|
20
|
133 */
|
|
134 (limit))
|
0
|
135 {
|
|
136 EMACS_INT val;
|
|
137 Lisp_Object lispy_val;
|
|
138 unsigned long denominator;
|
|
139
|
|
140 if (EQ (limit, Qt))
|
|
141 seed_random (getpid () + time (NULL));
|
|
142 if (NATNUMP (limit) && !ZEROP (limit))
|
|
143 {
|
|
144 /* Try to take our random number from the higher bits of VAL,
|
|
145 not the lower, since (says Gentzel) the low bits of `random'
|
|
146 are less random than the higher ones. We do this by using the
|
|
147 quotient rather than the remainder. At the high end of the RNG
|
|
148 it's possible to get a quotient larger than limit; discarding
|
|
149 these values eliminates the bias that would otherwise appear
|
|
150 when using a large limit. */
|
|
151 denominator = ((unsigned long)1 << VALBITS) / XINT (limit);
|
|
152 do
|
|
153 val = get_random () / denominator;
|
|
154 while (val >= XINT (limit));
|
|
155 }
|
|
156 else
|
|
157 val = get_random ();
|
|
158 XSETINT (lispy_val, val);
|
|
159 return lispy_val;
|
|
160 }
|
|
161
|
|
162 /* Random data-structure functions */
|
|
163
|
|
164 #ifdef LOSING_BYTECODE
|
|
165
|
|
166 /* #### Delete this shit */
|
|
167
|
|
168 /* Charcount is a misnomer here as we might be dealing with the
|
|
169 length of a vector or list, but emphasizes that we're not dealing
|
|
170 with Bytecounts in strings */
|
|
171 static Charcount
|
|
172 length_with_bytecode_hack (Lisp_Object seq)
|
|
173 {
|
|
174 if (!COMPILED_FUNCTIONP (seq))
|
|
175 return (XINT (Flength (seq)));
|
|
176 else
|
|
177 {
|
|
178 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (seq);
|
|
179 int intp = b->flags.interactivep;
|
|
180 int domainp = b->flags.domainp;
|
|
181
|
|
182 if (intp)
|
|
183 return (COMPILED_INTERACTIVE + 1);
|
|
184 else if (domainp)
|
|
185 return (COMPILED_DOMAIN + 1);
|
|
186 else
|
|
187 return (COMPILED_DOC_STRING + 1);
|
|
188 }
|
|
189 }
|
|
190
|
|
191 #endif /* LOSING_BYTECODE */
|
|
192
|
|
193 void
|
|
194 check_losing_bytecode (CONST char *function, Lisp_Object seq)
|
|
195 {
|
|
196 if (COMPILED_FUNCTIONP (seq))
|
|
197 error_with_frob
|
|
198 (seq,
|
|
199 "As of 19.14, `%s' no longer works with compiled-function objects",
|
|
200 function);
|
|
201 }
|
|
202
|
20
|
203 DEFUN ("length", Flength, 1, 1, 0, /*
|
0
|
204 Return the length of vector, bit vector, list or string SEQUENCE.
|
20
|
205 */
|
|
206 (obj))
|
0
|
207 {
|
|
208 Lisp_Object tail;
|
|
209 int i;
|
|
210
|
|
211 retry:
|
|
212 if (STRINGP (obj))
|
|
213 return (make_int (string_char_length (XSTRING (obj))));
|
|
214 else if (VECTORP (obj))
|
|
215 return (make_int (vector_length (XVECTOR (obj))));
|
|
216 else if (BIT_VECTORP (obj))
|
|
217 return (make_int (bit_vector_length (XBIT_VECTOR (obj))));
|
|
218 else if (CONSP (obj))
|
|
219 {
|
|
220 for (i = 0, tail = obj; !NILP (tail); i++)
|
|
221 {
|
|
222 QUIT;
|
|
223 tail = Fcdr (tail);
|
|
224 }
|
|
225
|
|
226 return (make_int (i));
|
|
227 }
|
|
228 else if (NILP (obj))
|
|
229 {
|
|
230 return (Qzero);
|
|
231 }
|
|
232 else
|
|
233 {
|
|
234 check_losing_bytecode ("length", obj);
|
|
235 obj = wrong_type_argument (Qsequencep, obj);
|
|
236 goto retry;
|
|
237 }
|
|
238 }
|
|
239
|
|
240 /* This does not check for quits. That is safe
|
|
241 since it must terminate. */
|
|
242
|
20
|
243 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /*
|
0
|
244 Return the length of a list, but avoid error or infinite loop.
|
|
245 This function never gets an error. If LIST is not really a list,
|
|
246 it returns 0. If LIST is circular, it returns a finite value
|
|
247 which is at least the number of distinct elements.
|
20
|
248 */
|
|
249 (list))
|
0
|
250 {
|
|
251 Lisp_Object tail, halftail, length;
|
|
252 int len = 0;
|
|
253
|
|
254 /* halftail is used to detect circular lists. */
|
|
255 halftail = list;
|
|
256 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
257 {
|
|
258 if (EQ (tail, halftail) && len != 0)
|
|
259 break;
|
|
260 len++;
|
|
261 if ((len & 1) == 0)
|
|
262 halftail = XCDR (halftail);
|
|
263 }
|
|
264
|
|
265 XSETINT (length, len);
|
|
266 return length;
|
|
267 }
|
|
268
|
|
269 /*** string functions. ***/
|
|
270
|
20
|
271 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /*
|
0
|
272 T if two strings have identical contents.
|
|
273 Case is significant. Text properties are ignored.
|
|
274 (Under XEmacs, `equal' also ignores text properties and extents in
|
|
275 strings, but this is not the case under FSF Emacs.)
|
|
276 Symbols are also allowed; their print names are used instead.
|
20
|
277 */
|
70
|
278 (s1, s2))
|
0
|
279 {
|
|
280 int len;
|
|
281
|
|
282 if (SYMBOLP (s1))
|
|
283 XSETSTRING (s1, XSYMBOL (s1)->name);
|
|
284 if (SYMBOLP (s2))
|
|
285 XSETSTRING (s2, XSYMBOL (s2)->name);
|
|
286 CHECK_STRING (s1);
|
|
287 CHECK_STRING (s2);
|
|
288
|
14
|
289 len = XSTRING_LENGTH (s1);
|
|
290 if (len != XSTRING_LENGTH (s2) ||
|
|
291 memcmp (XSTRING_DATA (s1), XSTRING_DATA (s2), len))
|
0
|
292 return Qnil;
|
|
293 return Qt;
|
|
294 }
|
|
295
|
|
296
|
20
|
297 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /*
|
0
|
298 T if first arg string is less than second in lexicographic order.
|
70
|
299 If I18N2 support (but not Mule support) was compiled in, ordering is
|
|
300 determined by the locale. (Case is significant for the default C locale.)
|
|
301 In all other cases, comparison is simply done on a character-by-
|
|
302 character basis using the numeric value of a character. (Note that
|
|
303 this may not produce particularly meaningful results under Mule if
|
|
304 characters from different charsets are being compared.)
|
|
305
|
0
|
306 Symbols are also allowed; their print names are used instead.
|
70
|
307
|
|
308 The reason that the I18N2 locale-specific collation is not used under
|
|
309 Mule is that the locale model of internationalization does not handle
|
|
310 multiple charsets and thus has no hope of working properly under Mule.
|
|
311 What we really should do is create a collation table over all built-in
|
|
312 charsets. This is extremely difficult to do from scratch, however.
|
|
313
|
|
314 Unicode is a good first step towards solving this problem. In fact,
|
|
315 it is quite likely that a collation table exists (or will exist) for
|
|
316 Unicode. When Unicode support is added to XEmacs/Mule, this problem
|
|
317 may be solved.
|
20
|
318 */
|
|
319 (s1, s2))
|
0
|
320 {
|
|
321 struct Lisp_String *p1, *p2;
|
|
322 Charcount end, len2;
|
|
323
|
|
324 if (SYMBOLP (s1))
|
|
325 XSETSTRING (s1, XSYMBOL (s1)->name);
|
|
326 if (SYMBOLP (s2))
|
|
327 XSETSTRING (s2, XSYMBOL (s2)->name);
|
|
328 CHECK_STRING (s1);
|
|
329 CHECK_STRING (s2);
|
|
330
|
|
331 p1 = XSTRING (s1);
|
|
332 p2 = XSTRING (s2);
|
|
333 end = string_char_length (XSTRING (s1));
|
|
334 len2 = string_char_length (XSTRING (s2));
|
|
335 if (end > len2)
|
|
336 end = len2;
|
|
337
|
|
338 {
|
|
339 int i;
|
|
340
|
70
|
341 #if defined (I18N2) && !defined (MULE)
|
|
342 /* There is no hope of this working under Mule. Even if we converted
|
|
343 the data into an external format so that strcoll() processed it
|
|
344 properly, it would still not work because strcoll() does not
|
|
345 handle multiple locales. This is the fundamental flaw in the
|
|
346 locale model. */
|
0
|
347 Bytecount bcend = charcount_to_bytecount (string_data (p1), end);
|
|
348 /* Compare strings using collation order of locale. */
|
|
349 /* Need to be tricky to handle embedded nulls. */
|
|
350
|
|
351 for (i = 0; i < bcend; i += strlen((char *) string_data (p1) + i) + 1)
|
|
352 {
|
|
353 int val = strcoll ((char *) string_data (p1) + i,
|
|
354 (char *) string_data (p2) + i);
|
|
355 if (val < 0)
|
|
356 return Qt;
|
|
357 if (val > 0)
|
|
358 return Qnil;
|
|
359 }
|
70
|
360 #else /* not I18N2, or MULE */
|
|
361 /* #### It is not really necessary to do this: We could compare
|
|
362 byte-by-byte and still get a reasonable comparison, since this
|
|
363 would compare characters with a charset in the same way.
|
|
364 With a little rearrangement of the leading bytes, we could
|
|
365 make most inter-charset comparisons work out the same, too;
|
|
366 even if some don't, this is not a big deal because inter-charset
|
|
367 comparisons aren't really well-defined anyway. */
|
0
|
368 for (i = 0; i < end; i++)
|
|
369 {
|
|
370 if (string_char (p1, i) != string_char (p2, i))
|
|
371 return string_char (p1, i) < string_char (p2, i) ? Qt : Qnil;
|
|
372 }
|
70
|
373 #endif /* not I18N2, or MULE */
|
0
|
374 /* Can't do i < len2 because then comparison between "foo" and "foo^@"
|
|
375 won't work right in I18N2 case */
|
|
376 return ((end < len2) ? Qt : Qnil);
|
|
377 }
|
|
378 }
|
|
379
|
20
|
380 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /*
|
0
|
381 Return STRING's tick counter, incremented for each change to the string.
|
|
382 Each string has a tick counter which is incremented each time the contents
|
|
383 of the string are changed (e.g. with `aset'). It wraps around occasionally.
|
20
|
384 */
|
|
385 (string))
|
0
|
386 {
|
|
387 struct Lisp_String *s;
|
|
388
|
|
389 CHECK_STRING (string);
|
|
390 s = XSTRING (string);
|
|
391 if (CONSP (s->plist) && INTP (XCAR (s->plist)))
|
|
392 return XCAR (s->plist);
|
|
393 else
|
|
394 return Qzero;
|
|
395 }
|
|
396
|
|
397 void
|
|
398 bump_string_modiff (Lisp_Object str)
|
|
399 {
|
|
400 struct Lisp_String *s = XSTRING (str);
|
|
401 Lisp_Object *ptr = &s->plist;
|
|
402
|
|
403 #ifdef I18N3
|
|
404 /* #### remove the `string-translatable' property from the string,
|
|
405 if there is one. */
|
|
406 #endif
|
|
407 /* skip over extent info if it's there */
|
|
408 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
|
|
409 ptr = &XCDR (*ptr);
|
|
410 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
|
|
411 XSETINT (XCAR (*ptr), 1+XINT (XCAR (*ptr)));
|
|
412 else
|
|
413 *ptr = Fcons (make_int (1), *ptr);
|
|
414 }
|
|
415
|
|
416
|
|
417 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector };
|
|
418 static Lisp_Object concat (int nargs, Lisp_Object *args,
|
|
419 enum concat_target_type target_type,
|
|
420 int last_special);
|
|
421
|
|
422 Lisp_Object
|
|
423 concat2 (Lisp_Object s1, Lisp_Object s2)
|
|
424 {
|
|
425 Lisp_Object args[2];
|
|
426 args[0] = s1;
|
|
427 args[1] = s2;
|
|
428 return concat (2, args, c_string, 0);
|
|
429 }
|
|
430
|
|
431 Lisp_Object
|
|
432 concat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
|
|
433 {
|
|
434 Lisp_Object args[3];
|
|
435 args[0] = s1;
|
|
436 args[1] = s2;
|
|
437 args[2] = s3;
|
|
438 return concat (3, args, c_string, 0);
|
|
439 }
|
|
440
|
|
441 Lisp_Object
|
|
442 vconcat2 (Lisp_Object s1, Lisp_Object s2)
|
|
443 {
|
|
444 Lisp_Object args[2];
|
|
445 args[0] = s1;
|
|
446 args[1] = s2;
|
|
447 return concat (2, args, c_vector, 0);
|
|
448 }
|
|
449
|
|
450 Lisp_Object
|
|
451 vconcat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
|
|
452 {
|
|
453 Lisp_Object args[3];
|
|
454 args[0] = s1;
|
|
455 args[1] = s2;
|
|
456 args[2] = s3;
|
|
457 return concat (3, args, c_vector, 0);
|
|
458 }
|
|
459
|
20
|
460 DEFUN ("append", Fappend, 0, MANY, 0, /*
|
0
|
461 Concatenate all the arguments and make the result a list.
|
|
462 The result is a list whose elements are the elements of all the arguments.
|
|
463 Each argument may be a list, vector, bit vector, or string.
|
|
464 The last argument is not copied, just used as the tail of the new list.
|
20
|
465 */
|
|
466 (int nargs, Lisp_Object *args))
|
0
|
467 {
|
|
468 return concat (nargs, args, c_cons, 1);
|
|
469 }
|
|
470
|
20
|
471 DEFUN ("concat", Fconcat, 0, MANY, 0, /*
|
0
|
472 Concatenate all the arguments and make the result a string.
|
|
473 The result is a string whose elements are the elements of all the arguments.
|
120
|
474 Each argument may be a string or a list or vector of characters.
|
0
|
475
|
|
476 Do not use individual integers as arguments!
|
|
477 The behavior of `concat' in that case will be changed later!
|
|
478 If your program passes an integer as an argument to `concat',
|
|
479 you should change it right away not to do so.
|
20
|
480 */
|
|
481 (int nargs, Lisp_Object *args))
|
0
|
482 {
|
|
483 return concat (nargs, args, c_string, 0);
|
|
484 }
|
|
485
|
20
|
486 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /*
|
0
|
487 Concatenate all the arguments and make the result a vector.
|
|
488 The result is a vector whose elements are the elements of all the arguments.
|
|
489 Each argument may be a list, vector, bit vector, or string.
|
20
|
490 */
|
|
491 (int nargs, Lisp_Object *args))
|
0
|
492 {
|
|
493 return concat (nargs, args, c_vector, 0);
|
|
494 }
|
|
495
|
20
|
496 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /*
|
0
|
497 Concatenate all the arguments and make the result a bit vector.
|
|
498 The result is a bit vector whose elements are the elements of all the
|
|
499 arguments. Each argument may be a list, vector, bit vector, or string.
|
20
|
500 */
|
|
501 (int nargs, Lisp_Object *args))
|
0
|
502 {
|
|
503 return concat (nargs, args, c_bit_vector, 0);
|
|
504 }
|
|
505
|
20
|
506 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /*
|
0
|
507 Return a copy of a list, vector, bit vector or string.
|
|
508 The elements of a list or vector are not copied; they are shared
|
|
509 with the original.
|
20
|
510 */
|
|
511 (arg))
|
0
|
512 {
|
|
513 again:
|
|
514 if (NILP (arg)) return arg;
|
|
515 /* We handle conses separately because concat() is big and hairy and
|
|
516 doesn't handle (copy-sequence '(a b . c)) and it's easier to redo this
|
|
517 than to fix concat() without worrying about breaking other things.
|
|
518 */
|
|
519 if (CONSP (arg))
|
|
520 {
|
|
521 Lisp_Object rest = arg;
|
|
522 Lisp_Object head, tail;
|
|
523 tail = Qnil;
|
|
524 while (CONSP (rest))
|
|
525 {
|
|
526 Lisp_Object new = Fcons (XCAR (rest), XCDR (rest));
|
|
527 if (NILP (tail))
|
|
528 head = tail = new;
|
|
529 else
|
|
530 XCDR (tail) = new, tail = new;
|
|
531 rest = XCDR (rest);
|
|
532 QUIT;
|
|
533 }
|
|
534 if (!NILP (tail))
|
|
535 XCDR (tail) = rest;
|
|
536 return head;
|
|
537 }
|
|
538 else if (STRINGP (arg))
|
|
539 return concat (1, &arg, c_string, 0);
|
|
540 else if (VECTORP (arg))
|
|
541 return concat (1, &arg, c_vector, 0);
|
|
542 else if (BIT_VECTORP (arg))
|
|
543 return concat (1, &arg, c_bit_vector, 0);
|
|
544 else
|
|
545 {
|
|
546 check_losing_bytecode ("copy-sequence", arg);
|
|
547 arg = wrong_type_argument (Qsequencep, arg);
|
|
548 goto again;
|
|
549 }
|
|
550 }
|
|
551
|
|
552 struct merge_string_extents_struct
|
|
553 {
|
|
554 Lisp_Object string;
|
|
555 Bytecount entry_offset;
|
|
556 Bytecount entry_length;
|
|
557 };
|
|
558
|
|
559 static Lisp_Object
|
|
560 concat (int nargs, Lisp_Object *args,
|
|
561 enum concat_target_type target_type,
|
|
562 int last_special)
|
|
563 {
|
|
564 Lisp_Object val;
|
|
565 Lisp_Object tail = Qnil;
|
|
566 int toindex;
|
|
567 int argnum;
|
|
568 Lisp_Object last_tail;
|
|
569 Lisp_Object prev;
|
|
570 struct merge_string_extents_struct *args_mse = 0;
|
|
571 Bufbyte *string_result = 0;
|
|
572 Bufbyte *string_result_ptr = 0;
|
|
573 struct gcpro gcpro1;
|
|
574
|
|
575 /* The modus operandi in Emacs is "caller gc-protects args".
|
|
576 However, concat is called many times in Emacs on freshly
|
|
577 created stuff. So we help those callers out by protecting
|
|
578 the args ourselves to save them a lot of temporary-variable
|
|
579 grief. */
|
|
580
|
|
581 GCPRO1 (args[0]);
|
|
582 gcpro1.nvars = nargs;
|
|
583
|
|
584 #ifdef I18N3
|
|
585 /* #### if the result is a string and any of the strings have a string
|
|
586 for the `string-translatable' property, then concat should also
|
|
587 concat the args but use the `string-translatable' strings, and store
|
|
588 the result in the returned string's `string-translatable' property. */
|
|
589 #endif
|
|
590 if (target_type == c_string)
|
|
591 {
|
|
592 args_mse = ((struct merge_string_extents_struct *)
|
|
593 alloca (nargs *
|
|
594 sizeof (struct merge_string_extents_struct)));
|
|
595 }
|
|
596
|
|
597 /* In append, the last arg isn't treated like the others */
|
|
598 if (last_special && nargs > 0)
|
|
599 {
|
|
600 nargs--;
|
|
601 last_tail = args[nargs];
|
|
602 }
|
|
603 else
|
|
604 last_tail = Qnil;
|
|
605
|
|
606 /* Check and coerce the arguments. */
|
|
607 for (argnum = 0; argnum < nargs; argnum++)
|
|
608 {
|
|
609 Lisp_Object seq = args[argnum];
|
|
610 if (CONSP (seq) || NILP (seq))
|
|
611 ;
|
|
612 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq))
|
|
613 ;
|
|
614 #ifdef LOSING_BYTECODE
|
|
615 else if (COMPILED_FUNCTIONP (seq))
|
|
616 /* Urk! We allow this, for "compatibility"... */
|
|
617 ;
|
|
618 #endif
|
|
619 else if (INTP (seq))
|
|
620 /* This is too revolting to think about but maintains
|
|
621 compatibility with FSF (and lots and lots of old code). */
|
|
622 args[argnum] = Fnumber_to_string (seq);
|
|
623 else
|
|
624 {
|
|
625 check_losing_bytecode ("concat", seq);
|
|
626 args[argnum] = wrong_type_argument (Qsequencep, seq);
|
|
627 }
|
|
628
|
|
629 if (args_mse)
|
|
630 {
|
|
631 if (STRINGP (seq))
|
|
632 args_mse[argnum].string = seq;
|
|
633 else
|
|
634 args_mse[argnum].string = Qnil;
|
|
635 }
|
|
636 }
|
|
637
|
|
638 {
|
|
639 /* Charcount is a misnomer here as we might be dealing with the
|
|
640 length of a vector or list, but emphasizes that we're not dealing
|
|
641 with Bytecounts in strings */
|
|
642 Charcount total_length;
|
|
643
|
|
644 for (argnum = 0, total_length = 0; argnum < nargs; argnum++)
|
|
645 {
|
|
646 #ifdef LOSING_BYTECODE
|
|
647 Charcount thislen = length_with_bytecode_hack (args[argnum]);
|
|
648 #else
|
|
649 Charcount thislen = XINT (Flength (args[argnum]));
|
|
650 #endif
|
|
651 total_length += thislen;
|
|
652 }
|
|
653
|
|
654 switch (target_type)
|
|
655 {
|
|
656 case c_cons:
|
|
657 if (total_length == 0)
|
|
658 /* In append, if all but last arg are nil, return last arg */
|
|
659 RETURN_UNGCPRO (last_tail);
|
|
660 val = Fmake_list (make_int (total_length), Qnil);
|
|
661 break;
|
|
662 case c_vector:
|
|
663 val = make_vector (total_length, Qnil);
|
|
664 break;
|
|
665 case c_bit_vector:
|
|
666 val = make_bit_vector (total_length, Qzero);
|
|
667 break;
|
|
668 case c_string:
|
|
669 /* We don't make the string yet because we don't know the
|
|
670 actual number of bytes. This loop was formerly written
|
|
671 to call Fmake_string() here and then call set_string_char()
|
|
672 for each char. This seems logical enough but is waaaaaaaay
|
|
673 slow -- set_string_char() has to scan the whole string up
|
|
674 to the place where the substitution is called for in order
|
|
675 to find the place to change, and may have to do some
|
|
676 realloc()ing in order to make the char fit properly.
|
|
677 O(N^2) yuckage. */
|
|
678 val = Qnil;
|
|
679 string_result = (Bufbyte *) alloca (total_length * MAX_EMCHAR_LEN);
|
|
680 string_result_ptr = string_result;
|
|
681 break;
|
|
682 default:
|
|
683 abort ();
|
|
684 }
|
|
685 }
|
|
686
|
|
687
|
|
688 if (CONSP (val))
|
|
689 tail = val, toindex = -1; /* -1 in toindex is flag we are
|
|
690 making a list */
|
|
691 else
|
|
692 toindex = 0;
|
|
693
|
|
694 prev = Qnil;
|
|
695
|
|
696 for (argnum = 0; argnum < nargs; argnum++)
|
|
697 {
|
|
698 Charcount thisleni = 0;
|
|
699 Charcount thisindex = 0;
|
|
700 Lisp_Object seq = args[argnum];
|
|
701 Bufbyte *string_source_ptr = 0;
|
|
702 Bufbyte *string_prev_result_ptr = string_result_ptr;
|
|
703
|
|
704 if (!CONSP (seq))
|
|
705 {
|
|
706 #ifdef LOSING_BYTECODE
|
|
707 thisleni = length_with_bytecode_hack (seq);
|
|
708 #else
|
|
709 thisleni = XINT (Flength (seq));
|
|
710 #endif
|
|
711 }
|
|
712 if (STRINGP (seq))
|
14
|
713 string_source_ptr = XSTRING_DATA (seq);
|
0
|
714
|
|
715 while (1)
|
|
716 {
|
|
717 Lisp_Object elt;
|
|
718
|
|
719 /* We've come to the end of this arg, so exit. */
|
|
720 if (NILP (seq))
|
|
721 break;
|
|
722
|
|
723 /* Fetch next element of `seq' arg into `elt' */
|
|
724 if (CONSP (seq))
|
|
725 {
|
|
726 elt = Fcar (seq);
|
|
727 seq = Fcdr (seq);
|
|
728 }
|
|
729 else
|
|
730 {
|
|
731 if (thisindex >= thisleni)
|
|
732 break;
|
|
733
|
|
734 if (STRINGP (seq))
|
|
735 {
|
|
736 elt = make_char (charptr_emchar (string_source_ptr));
|
|
737 INC_CHARPTR (string_source_ptr);
|
|
738 }
|
|
739 else if (VECTORP (seq))
|
|
740 elt = vector_data (XVECTOR (seq))[thisindex];
|
|
741 else if (BIT_VECTORP (seq))
|
|
742 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq),
|
|
743 thisindex));
|
|
744 else
|
|
745 elt = Felt (seq, make_int (thisindex));
|
|
746 thisindex++;
|
|
747 }
|
|
748
|
|
749 /* Store into result */
|
|
750 if (toindex < 0)
|
|
751 {
|
|
752 /* toindex negative means we are making a list */
|
|
753 XCAR (tail) = elt;
|
|
754 prev = tail;
|
|
755 tail = XCDR (tail);
|
|
756 }
|
|
757 else if (VECTORP (val))
|
|
758 vector_data (XVECTOR (val))[toindex++] = elt;
|
|
759 else if (BIT_VECTORP (val))
|
|
760 {
|
|
761 CHECK_BIT (elt);
|
|
762 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt));
|
|
763 }
|
|
764 else
|
|
765 {
|
|
766 CHECK_CHAR_COERCE_INT (elt);
|
|
767 string_result_ptr += set_charptr_emchar (string_result_ptr,
|
|
768 XCHAR (elt));
|
|
769 }
|
|
770 }
|
|
771 if (args_mse)
|
|
772 {
|
|
773 args_mse[argnum].entry_offset =
|
|
774 string_prev_result_ptr - string_result;
|
|
775 args_mse[argnum].entry_length =
|
|
776 string_result_ptr - string_prev_result_ptr;
|
|
777 }
|
|
778 }
|
|
779
|
|
780 /* Now we finally make the string. */
|
|
781 if (target_type == c_string)
|
|
782 {
|
|
783 val = make_string (string_result, string_result_ptr - string_result);
|
|
784 for (argnum = 0; argnum < nargs; argnum++)
|
|
785 {
|
|
786 if (STRINGP (args_mse[argnum].string))
|
|
787 copy_string_extents (val, args_mse[argnum].string,
|
|
788 args_mse[argnum].entry_offset, 0,
|
|
789 args_mse[argnum].entry_length);
|
|
790 }
|
|
791 }
|
|
792
|
|
793 if (!NILP (prev))
|
|
794 XCDR (prev) = last_tail;
|
|
795
|
|
796 RETURN_UNGCPRO (val);
|
|
797 }
|
|
798
|
20
|
799 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /*
|
0
|
800 Return a copy of ALIST.
|
|
801 This is an alist which represents the same mapping from objects to objects,
|
|
802 but does not share the alist structure with ALIST.
|
|
803 The objects mapped (cars and cdrs of elements of the alist)
|
|
804 are shared, however.
|
|
805 Elements of ALIST that are not conses are also shared.
|
20
|
806 */
|
|
807 (alist))
|
0
|
808 {
|
|
809 Lisp_Object tem;
|
|
810
|
|
811 CHECK_LIST (alist);
|
|
812 if (NILP (alist))
|
|
813 return alist;
|
|
814 alist = concat (1, &alist, c_cons, 0);
|
|
815 for (tem = alist; CONSP (tem); tem = XCDR (tem))
|
|
816 {
|
|
817 Lisp_Object car;
|
|
818 car = XCAR (tem);
|
|
819
|
|
820 if (CONSP (car))
|
|
821 XCAR (tem) = Fcons (XCAR (car), XCDR (car));
|
|
822 }
|
|
823 return alist;
|
|
824 }
|
|
825
|
20
|
826 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /*
|
0
|
827 Return a copy of a list and substructures.
|
|
828 The argument is copied, and any lists contained within it are copied
|
|
829 recursively. Circularities and shared substructures are not preserved.
|
|
830 Second arg VECP causes vectors to be copied, too. Strings and bit vectors
|
|
831 are not copied.
|
20
|
832 */
|
|
833 (arg, vecp))
|
0
|
834 {
|
|
835 if (CONSP (arg))
|
|
836 {
|
|
837 Lisp_Object rest;
|
|
838 rest = arg = Fcopy_sequence (arg);
|
|
839 while (CONSP (rest))
|
|
840 {
|
|
841 Lisp_Object elt = XCAR (rest);
|
|
842 QUIT;
|
|
843 if (CONSP (elt) || VECTORP (elt))
|
|
844 XCAR (rest) = Fcopy_tree (elt, vecp);
|
|
845 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */
|
|
846 XCDR (rest) = Fcopy_tree (XCDR (rest), vecp);
|
|
847 rest = XCDR (rest);
|
|
848 }
|
|
849 }
|
|
850 else if (VECTORP (arg) && ! NILP (vecp))
|
|
851 {
|
|
852 int i = vector_length (XVECTOR (arg));
|
|
853 int j;
|
|
854 arg = Fcopy_sequence (arg);
|
|
855 for (j = 0; j < i; j++)
|
|
856 {
|
|
857 Lisp_Object elt = vector_data (XVECTOR (arg)) [j];
|
|
858 QUIT;
|
|
859 if (CONSP (elt) || VECTORP (elt))
|
|
860 vector_data (XVECTOR (arg)) [j] = Fcopy_tree (elt, vecp);
|
|
861 }
|
|
862 }
|
|
863 return arg;
|
|
864 }
|
|
865
|
20
|
866 DEFUN ("substring", Fsubstring, 2, 3, 0, /*
|
0
|
867 Return a substring of STRING, starting at index FROM and ending before TO.
|
|
868 TO may be nil or omitted; then the substring runs to the end of STRING.
|
|
869 If FROM or TO is negative, it counts from the end.
|
|
870 Relevant parts of the string-extent-data are copied in the new string.
|
20
|
871 */
|
|
872 (string, from, to))
|
0
|
873 {
|
|
874 Charcount ccfr, ccto;
|
|
875 Bytecount bfr, bto;
|
|
876 Lisp_Object val;
|
|
877
|
|
878 CHECK_STRING (string);
|
|
879 /* Historically, FROM could not be omitted. Whatever ... */
|
|
880 CHECK_INT (from);
|
|
881 get_string_range_char (string, from, to, &ccfr, &ccto,
|
|
882 GB_HISTORICAL_STRING_BEHAVIOR);
|
14
|
883 bfr = charcount_to_bytecount (XSTRING_DATA (string), ccfr);
|
|
884 bto = charcount_to_bytecount (XSTRING_DATA (string), ccto);
|
|
885 val = make_string (XSTRING_DATA (string) + bfr, bto - bfr);
|
0
|
886 /* Copy any applicable extent information into the new string: */
|
|
887 copy_string_extents (val, string, 0, bfr, bto - bfr);
|
|
888 return (val);
|
|
889 }
|
|
890
|
20
|
891 DEFUN ("subseq", Fsubseq, 2, 3, 0, /*
|
0
|
892 Return a subsequence of SEQ, starting at index FROM and ending before TO.
|
|
893 TO may be nil or omitted; then the subsequence runs to the end of SEQ.
|
|
894 If FROM or TO is negative, it counts from the end.
|
|
895 The resulting subsequence is always the same type as the original
|
|
896 sequence.
|
|
897 If SEQ is a string, relevant parts of the string-extent-data are copied
|
|
898 in the new string.
|
20
|
899 */
|
|
900 (seq, from, to))
|
0
|
901 {
|
|
902 int len, f, t;
|
|
903
|
|
904 if (STRINGP (seq))
|
|
905 return Fsubstring (seq, from, to);
|
|
906
|
|
907 if (CONSP (seq) || NILP (seq))
|
|
908 ;
|
|
909 else if (VECTORP (seq) || BIT_VECTORP (seq))
|
|
910 ;
|
|
911 else
|
|
912 {
|
|
913 check_losing_bytecode ("subseq", seq);
|
|
914 seq = wrong_type_argument (Qsequencep, seq);
|
|
915 }
|
|
916
|
|
917 len = XINT (Flength (seq));
|
|
918 CHECK_INT (from);
|
|
919 f = XINT (from);
|
|
920 if (f < 0)
|
|
921 f = len + f;
|
|
922 if (NILP (to))
|
|
923 t = len;
|
|
924 else
|
|
925 {
|
|
926 CHECK_INT (to);
|
|
927 t = XINT (to);
|
|
928 if (t < 0)
|
|
929 t = len + t;
|
|
930 }
|
|
931
|
|
932 if (!(0 <= f && f <= t && t <= len))
|
|
933 args_out_of_range_3 (seq, make_int (f), make_int (t));
|
|
934
|
|
935 if (VECTORP (seq))
|
|
936 {
|
|
937 Lisp_Object result = make_vector (t - f, Qnil);
|
|
938 int i;
|
|
939 Lisp_Object *in_elts = vector_data (XVECTOR (seq));
|
|
940 Lisp_Object *out_elts = vector_data (XVECTOR (result));
|
|
941
|
|
942 for (i = f; i < t; i++)
|
|
943 out_elts[i - f] = in_elts[i];
|
|
944 return result;
|
|
945 }
|
|
946
|
|
947 if (CONSP (seq))
|
|
948 {
|
|
949 Lisp_Object result = Qnil;
|
|
950 int i;
|
|
951
|
|
952 seq = Fnthcdr (make_int (f), seq);
|
|
953
|
|
954 for (i = f; i < t; i++)
|
|
955 {
|
|
956 result = Fcons (Fcar (seq), result);
|
|
957 seq = Fcdr (seq);
|
|
958 }
|
|
959
|
|
960 return Fnreverse (result);
|
|
961 }
|
|
962
|
|
963 /* bit vector */
|
|
964 {
|
|
965 Lisp_Object result = make_bit_vector (t - f, Qzero);
|
|
966 int i;
|
|
967
|
|
968 for (i = f; i < t; i++)
|
|
969 set_bit_vector_bit (XBIT_VECTOR (result), i - f,
|
|
970 bit_vector_bit (XBIT_VECTOR (seq), i));
|
|
971 return result;
|
|
972 }
|
|
973 }
|
|
974
|
|
975
|
20
|
976 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /*
|
0
|
977 Take cdr N times on LIST, returns the result.
|
20
|
978 */
|
|
979 (n, list))
|
0
|
980 {
|
|
981 REGISTER int i, num;
|
|
982 CHECK_INT (n);
|
|
983 num = XINT (n);
|
|
984 for (i = 0; i < num && !NILP (list); i++)
|
|
985 {
|
|
986 QUIT;
|
|
987 list = Fcdr (list);
|
|
988 }
|
|
989 return list;
|
|
990 }
|
|
991
|
20
|
992 DEFUN ("nth", Fnth, 2, 2, 0, /*
|
0
|
993 Return the Nth element of LIST.
|
|
994 N counts from zero. If LIST is not that long, nil is returned.
|
20
|
995 */
|
|
996 (n, list))
|
0
|
997 {
|
|
998 return Fcar (Fnthcdr (n, list));
|
|
999 }
|
|
1000
|
20
|
1001 DEFUN ("elt", Felt, 2, 2, 0, /*
|
0
|
1002 Return element of SEQUENCE at index N.
|
20
|
1003 */
|
|
1004 (seq, n))
|
0
|
1005 {
|
|
1006 retry:
|
|
1007 CHECK_INT_COERCE_CHAR (n); /* yuck! */
|
|
1008 if (CONSP (seq) || NILP (seq))
|
|
1009 {
|
|
1010 Lisp_Object tem = Fnthcdr (n, seq);
|
|
1011 /* #### Utterly, completely, fucking disgusting.
|
|
1012 * #### The whole point of "elt" is that it operates on
|
|
1013 * #### sequences, and does error- (bounds-) checking.
|
|
1014 */
|
|
1015 if (CONSP (tem))
|
|
1016 return (XCAR (tem));
|
|
1017 else
|
|
1018 #if 1
|
|
1019 /* This is The Way It Has Always Been. */
|
|
1020 return Qnil;
|
|
1021 #else
|
|
1022 /* This is The Way Mly Says It Should Be. */
|
|
1023 args_out_of_range (seq, n);
|
|
1024 #endif
|
|
1025 }
|
|
1026 else if (STRINGP (seq)
|
|
1027 || VECTORP (seq)
|
|
1028 || BIT_VECTORP (seq))
|
|
1029 return (Faref (seq, n));
|
|
1030 #ifdef LOSING_BYTECODE
|
|
1031 else if (COMPILED_FUNCTIONP (seq))
|
|
1032 {
|
|
1033 int idx = XINT (n);
|
|
1034 if (idx < 0)
|
|
1035 {
|
|
1036 lose:
|
|
1037 args_out_of_range (seq, n);
|
|
1038 }
|
|
1039 /* Utter perversity */
|
|
1040 {
|
|
1041 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (seq);
|
|
1042 switch (idx)
|
|
1043 {
|
|
1044 case COMPILED_ARGLIST:
|
|
1045 return (b->arglist);
|
|
1046 case COMPILED_BYTECODE:
|
|
1047 return (b->bytecodes);
|
|
1048 case COMPILED_CONSTANTS:
|
|
1049 return (b->constants);
|
|
1050 case COMPILED_STACK_DEPTH:
|
|
1051 return (make_int (b->maxdepth));
|
|
1052 case COMPILED_DOC_STRING:
|
|
1053 return (compiled_function_documentation (b));
|
|
1054 case COMPILED_DOMAIN:
|
|
1055 return (compiled_function_domain (b));
|
|
1056 case COMPILED_INTERACTIVE:
|
|
1057 if (b->flags.interactivep)
|
|
1058 return (compiled_function_interactive (b));
|
|
1059 /* if we return nil, can't tell interactive with no args
|
|
1060 from noninteractive. */
|
|
1061 goto lose;
|
|
1062 default:
|
|
1063 goto lose;
|
|
1064 }
|
|
1065 }
|
|
1066 }
|
|
1067 #endif /* LOSING_BYTECODE */
|
|
1068 else
|
|
1069 {
|
|
1070 check_losing_bytecode ("elt", seq);
|
|
1071 seq = wrong_type_argument (Qsequencep, seq);
|
|
1072 goto retry;
|
|
1073 }
|
|
1074 }
|
|
1075
|
20
|
1076 DEFUN ("member", Fmember, 2, 2, 0, /*
|
0
|
1077 Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
|
|
1078 The value is actually the tail of LIST whose car is ELT.
|
20
|
1079 */
|
|
1080 (elt, list))
|
0
|
1081 {
|
|
1082 REGISTER Lisp_Object tail, tem;
|
|
1083 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1084 {
|
|
1085 tem = Fcar (tail);
|
|
1086 if (! NILP (Fequal (elt, tem)))
|
|
1087 return tail;
|
|
1088 QUIT;
|
|
1089 }
|
|
1090 return Qnil;
|
|
1091 }
|
|
1092
|
70
|
1093 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
|
|
1094 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
|
|
1095 The value is actually the tail of LIST whose car is ELT.
|
|
1096 This function is provided only for byte-code compatibility with v19.
|
|
1097 Do not use it.
|
|
1098 */
|
|
1099 (elt, list))
|
|
1100 {
|
|
1101 REGISTER Lisp_Object tail, tem;
|
|
1102 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1103 {
|
|
1104 tem = Fcar (tail);
|
|
1105 if (! NILP (Fold_equal (elt, tem)))
|
|
1106 return tail;
|
|
1107 QUIT;
|
|
1108 }
|
|
1109 return Qnil;
|
|
1110 }
|
|
1111
|
20
|
1112 DEFUN ("memq", Fmemq, 2, 2, 0, /*
|
0
|
1113 Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
|
|
1114 The value is actually the tail of LIST whose car is ELT.
|
20
|
1115 */
|
|
1116 (elt, list))
|
0
|
1117 {
|
|
1118 REGISTER Lisp_Object tail, tem;
|
|
1119 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1120 {
|
|
1121 tem = Fcar (tail);
|
70
|
1122 if (EQ_WITH_EBOLA_NOTICE (elt, tem)) return tail;
|
|
1123 QUIT;
|
|
1124 }
|
|
1125 return Qnil;
|
|
1126 }
|
|
1127
|
|
1128 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
|
|
1129 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
|
|
1130 The value is actually the tail of LIST whose car is ELT.
|
|
1131 This function is provided only for byte-code compatibility with v19.
|
|
1132 Do not use it.
|
|
1133 */
|
|
1134 (elt, list))
|
|
1135 {
|
|
1136 REGISTER Lisp_Object tail, tem;
|
|
1137 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1138 {
|
|
1139 tem = Fcar (tail);
|
0
|
1140 if (HACKEQ_UNSAFE (elt, tem)) return tail;
|
|
1141 QUIT;
|
|
1142 }
|
|
1143 return Qnil;
|
|
1144 }
|
|
1145
|
|
1146 Lisp_Object
|
|
1147 memq_no_quit (Lisp_Object elt, Lisp_Object list)
|
|
1148 {
|
|
1149 REGISTER Lisp_Object tail, tem;
|
|
1150 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1151 {
|
|
1152 tem = XCAR (tail);
|
70
|
1153 if (EQ_WITH_EBOLA_NOTICE (elt, tem)) return tail;
|
0
|
1154 }
|
|
1155 return Qnil;
|
|
1156 }
|
|
1157
|
20
|
1158 DEFUN ("assoc", Fassoc, 2, 2, 0, /*
|
0
|
1159 Return non-nil if KEY is `equal' to the car of an element of LIST.
|
|
1160 The value is actually the element of LIST whose car equals KEY.
|
20
|
1161 */
|
|
1162 (key, list))
|
0
|
1163 {
|
|
1164 /* This function can GC. */
|
|
1165 REGISTER Lisp_Object tail, elt, tem;
|
|
1166 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1167 {
|
|
1168 elt = Fcar (tail);
|
|
1169 if (!CONSP (elt)) continue;
|
|
1170 tem = Fequal (Fcar (elt), key);
|
|
1171 if (!NILP (tem)) return elt;
|
|
1172 QUIT;
|
|
1173 }
|
|
1174 return Qnil;
|
|
1175 }
|
|
1176
|
70
|
1177 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
|
|
1178 Return non-nil if KEY is `old-equal' to the car of an element of LIST.
|
|
1179 The value is actually the element of LIST whose car equals KEY.
|
|
1180 */
|
|
1181 (key, list))
|
|
1182 {
|
|
1183 /* This function can GC. */
|
|
1184 REGISTER Lisp_Object tail, elt, tem;
|
|
1185 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1186 {
|
|
1187 elt = Fcar (tail);
|
|
1188 if (!CONSP (elt)) continue;
|
|
1189 tem = Fold_equal (Fcar (elt), key);
|
|
1190 if (!NILP (tem)) return elt;
|
|
1191 QUIT;
|
|
1192 }
|
|
1193 return Qnil;
|
|
1194 }
|
|
1195
|
0
|
1196 Lisp_Object
|
|
1197 assoc_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1198 {
|
|
1199 int speccount = specpdl_depth ();
|
|
1200 specbind (Qinhibit_quit, Qt);
|
|
1201 return (unbind_to (speccount, Fassoc (key, list)));
|
|
1202 }
|
|
1203
|
20
|
1204 DEFUN ("assq", Fassq, 2, 2, 0, /*
|
0
|
1205 Return non-nil if KEY is `eq' to the car of an element of LIST.
|
|
1206 The value is actually the element of LIST whose car is KEY.
|
|
1207 Elements of LIST that are not conses are ignored.
|
20
|
1208 */
|
|
1209 (key, list))
|
0
|
1210 {
|
|
1211 REGISTER Lisp_Object tail, elt, tem;
|
|
1212 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1213 {
|
|
1214 elt = Fcar (tail);
|
|
1215 if (!CONSP (elt)) continue;
|
|
1216 tem = Fcar (elt);
|
70
|
1217 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
|
1218 QUIT;
|
|
1219 }
|
|
1220 return Qnil;
|
|
1221 }
|
|
1222
|
|
1223 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
|
|
1224 Return non-nil if KEY is `old-eq' to the car of an element of LIST.
|
|
1225 The value is actually the element of LIST whose car is KEY.
|
|
1226 Elements of LIST that are not conses are ignored.
|
|
1227 This function is provided only for byte-code compatibility with v19.
|
|
1228 Do not use it.
|
|
1229 */
|
|
1230 (key, list))
|
|
1231 {
|
|
1232 REGISTER Lisp_Object tail, elt, tem;
|
|
1233 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1234 {
|
|
1235 elt = Fcar (tail);
|
|
1236 if (!CONSP (elt)) continue;
|
|
1237 tem = Fcar (elt);
|
0
|
1238 if (HACKEQ_UNSAFE (key, tem)) return elt;
|
|
1239 QUIT;
|
|
1240 }
|
|
1241 return Qnil;
|
|
1242 }
|
|
1243
|
|
1244 /* Like Fassq but never report an error and do not allow quits.
|
|
1245 Use only on lists known never to be circular. */
|
|
1246
|
|
1247 Lisp_Object
|
|
1248 assq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1249 {
|
|
1250 /* This cannot GC. */
|
|
1251 REGISTER Lisp_Object tail, elt, tem;
|
|
1252 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1253 {
|
|
1254 elt = XCAR (tail);
|
|
1255 if (!CONSP (elt)) continue;
|
|
1256 tem = XCAR (elt);
|
70
|
1257 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
0
|
1258 }
|
|
1259 return Qnil;
|
|
1260 }
|
|
1261
|
20
|
1262 DEFUN ("rassoc", Frassoc, 2, 2, 0, /*
|
0
|
1263 Return non-nil if KEY is `equal' to the cdr of an element of LIST.
|
|
1264 The value is actually the element of LIST whose cdr equals KEY.
|
20
|
1265 */
|
|
1266 (key, list))
|
0
|
1267 {
|
|
1268 REGISTER Lisp_Object tail;
|
|
1269 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1270 {
|
|
1271 REGISTER Lisp_Object elt, tem;
|
|
1272 elt = Fcar (tail);
|
|
1273 if (!CONSP (elt)) continue;
|
|
1274 tem = Fequal (Fcdr (elt), key);
|
|
1275 if (!NILP (tem)) return elt;
|
|
1276 QUIT;
|
|
1277 }
|
|
1278 return Qnil;
|
|
1279 }
|
|
1280
|
70
|
1281 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
|
|
1282 Return non-nil if KEY is `old-equal' to the cdr of an element of LIST.
|
|
1283 The value is actually the element of LIST whose cdr equals KEY.
|
|
1284 */
|
|
1285 (key, list))
|
|
1286 {
|
|
1287 REGISTER Lisp_Object tail;
|
|
1288 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1289 {
|
|
1290 REGISTER Lisp_Object elt, tem;
|
|
1291 elt = Fcar (tail);
|
|
1292 if (!CONSP (elt)) continue;
|
|
1293 tem = Fold_equal (Fcdr (elt), key);
|
|
1294 if (!NILP (tem)) return elt;
|
|
1295 QUIT;
|
|
1296 }
|
|
1297 return Qnil;
|
|
1298 }
|
|
1299
|
20
|
1300 DEFUN ("rassq", Frassq, 2, 2, 0, /*
|
0
|
1301 Return non-nil if KEY is `eq' to the cdr of an element of LIST.
|
|
1302 The value is actually the element of LIST whose cdr is KEY.
|
20
|
1303 */
|
|
1304 (key, list))
|
0
|
1305 {
|
|
1306 REGISTER Lisp_Object tail, elt, tem;
|
|
1307 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1308 {
|
|
1309 elt = Fcar (tail);
|
|
1310 if (!CONSP (elt)) continue;
|
|
1311 tem = Fcdr (elt);
|
70
|
1312 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
|
1313 QUIT;
|
|
1314 }
|
|
1315 return Qnil;
|
|
1316 }
|
|
1317
|
|
1318 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /*
|
|
1319 Return non-nil if KEY is `old-eq' to the cdr of an element of LIST.
|
|
1320 The value is actually the element of LIST whose cdr is KEY.
|
|
1321 */
|
|
1322 (key, list))
|
|
1323 {
|
|
1324 REGISTER Lisp_Object tail, elt, tem;
|
|
1325 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1326 {
|
|
1327 elt = Fcar (tail);
|
|
1328 if (!CONSP (elt)) continue;
|
|
1329 tem = Fcdr (elt);
|
0
|
1330 if (HACKEQ_UNSAFE (key, tem)) return elt;
|
|
1331 QUIT;
|
|
1332 }
|
|
1333 return Qnil;
|
|
1334 }
|
|
1335
|
|
1336 Lisp_Object
|
|
1337 rassq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1338 {
|
|
1339 REGISTER Lisp_Object tail, elt, tem;
|
|
1340 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1341 {
|
|
1342 elt = XCAR (tail);
|
|
1343 if (!CONSP (elt)) continue;
|
|
1344 tem = XCDR (elt);
|
70
|
1345 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
0
|
1346 }
|
|
1347 return Qnil;
|
|
1348 }
|
|
1349
|
|
1350
|
20
|
1351 DEFUN ("delete", Fdelete, 2, 2, 0, /*
|
0
|
1352 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1353 The modified LIST is returned. Comparison is done with `equal'.
|
|
1354 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1355 effect; therefore, write `(setq foo (delete element foo))' to be sure
|
|
1356 of changing the value of `foo'.
|
20
|
1357 */
|
|
1358 (elt, list))
|
0
|
1359 {
|
|
1360 REGISTER Lisp_Object tail, prev;
|
|
1361
|
|
1362 tail = list;
|
|
1363 prev = Qnil;
|
|
1364 while (!NILP (tail))
|
|
1365 {
|
|
1366 if (!NILP (Fequal (elt, Fcar (tail))))
|
|
1367 {
|
|
1368 if (NILP (prev))
|
|
1369 list = Fcdr (tail);
|
|
1370 else
|
|
1371 Fsetcdr (prev, Fcdr (tail));
|
|
1372 }
|
|
1373 else
|
|
1374 prev = tail;
|
|
1375 tail = Fcdr (tail);
|
|
1376 QUIT;
|
|
1377 }
|
|
1378 return list;
|
|
1379 }
|
|
1380
|
70
|
1381 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
|
|
1382 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1383 The modified LIST is returned. Comparison is done with `old-equal'.
|
|
1384 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1385 effect; therefore, write `(setq foo (delete element foo))' to be sure
|
|
1386 of changing the value of `foo'.
|
|
1387 */
|
|
1388 (elt, list))
|
|
1389 {
|
|
1390 REGISTER Lisp_Object tail, prev;
|
|
1391
|
|
1392 tail = list;
|
|
1393 prev = Qnil;
|
|
1394 while (!NILP (tail))
|
|
1395 {
|
|
1396 if (!NILP (Fold_equal (elt, Fcar (tail))))
|
|
1397 {
|
|
1398 if (NILP (prev))
|
|
1399 list = Fcdr (tail);
|
|
1400 else
|
|
1401 Fsetcdr (prev, Fcdr (tail));
|
|
1402 }
|
|
1403 else
|
|
1404 prev = tail;
|
|
1405 tail = Fcdr (tail);
|
|
1406 QUIT;
|
|
1407 }
|
|
1408 return list;
|
|
1409 }
|
|
1410
|
20
|
1411 DEFUN ("delq", Fdelq, 2, 2, 0, /*
|
0
|
1412 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1413 The modified LIST is returned. Comparison is done with `eq'.
|
|
1414 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1415 effect; therefore, write `(setq foo (delq element foo))' to be sure of
|
|
1416 changing the value of `foo'.
|
20
|
1417 */
|
|
1418 (elt, list))
|
0
|
1419 {
|
|
1420 REGISTER Lisp_Object tail, prev;
|
|
1421 REGISTER Lisp_Object tem;
|
|
1422
|
|
1423 tail = list;
|
|
1424 prev = Qnil;
|
|
1425 while (!NILP (tail))
|
|
1426 {
|
|
1427 tem = Fcar (tail);
|
70
|
1428 if (EQ_WITH_EBOLA_NOTICE (elt, tem))
|
|
1429 {
|
|
1430 if (NILP (prev))
|
|
1431 list = Fcdr (tail);
|
|
1432 else
|
|
1433 Fsetcdr (prev, Fcdr (tail));
|
|
1434 }
|
|
1435 else
|
|
1436 prev = tail;
|
|
1437 tail = Fcdr (tail);
|
|
1438 QUIT;
|
|
1439 }
|
|
1440 return list;
|
|
1441 }
|
|
1442
|
|
1443 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
|
|
1444 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1445 The modified LIST is returned. Comparison is done with `old-eq'.
|
|
1446 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1447 effect; therefore, write `(setq foo (delq element foo))' to be sure of
|
|
1448 changing the value of `foo'.
|
|
1449 */
|
|
1450 (elt, list))
|
|
1451 {
|
|
1452 REGISTER Lisp_Object tail, prev;
|
|
1453 REGISTER Lisp_Object tem;
|
|
1454
|
|
1455 tail = list;
|
|
1456 prev = Qnil;
|
|
1457 while (!NILP (tail))
|
|
1458 {
|
|
1459 tem = Fcar (tail);
|
0
|
1460 if (HACKEQ_UNSAFE (elt, tem))
|
|
1461 {
|
|
1462 if (NILP (prev))
|
|
1463 list = Fcdr (tail);
|
|
1464 else
|
|
1465 Fsetcdr (prev, Fcdr (tail));
|
|
1466 }
|
|
1467 else
|
|
1468 prev = tail;
|
|
1469 tail = Fcdr (tail);
|
|
1470 QUIT;
|
|
1471 }
|
|
1472 return list;
|
|
1473 }
|
|
1474
|
|
1475 /* no quit, no errors; be careful */
|
|
1476
|
|
1477 Lisp_Object
|
|
1478 delq_no_quit (Lisp_Object elt, Lisp_Object list)
|
|
1479 {
|
|
1480 REGISTER Lisp_Object tail, prev;
|
|
1481 REGISTER Lisp_Object tem;
|
|
1482
|
|
1483 tail = list;
|
|
1484 prev = Qnil;
|
|
1485 while (CONSP (tail))
|
|
1486 {
|
|
1487 tem = XCAR (tail);
|
70
|
1488 if (EQ_WITH_EBOLA_NOTICE (elt, tem))
|
0
|
1489 {
|
|
1490 if (NILP (prev))
|
|
1491 list = XCDR (tail);
|
|
1492 else
|
|
1493 XCDR (prev) = XCDR (tail);
|
|
1494 }
|
|
1495 else
|
|
1496 prev = tail;
|
|
1497 tail = XCDR (tail);
|
|
1498 }
|
|
1499 return list;
|
|
1500 }
|
|
1501
|
|
1502 /* Be VERY careful with this. This is like delq_no_quit() but
|
|
1503 also calls free_cons() on the removed conses. You must be SURE
|
|
1504 that no pointers to the freed conses remain around (e.g.
|
|
1505 someone else is pointing to part of the list). This function
|
|
1506 is useful on internal lists that are used frequently and where
|
|
1507 the actual list doesn't escape beyond known code bounds. */
|
|
1508
|
|
1509 Lisp_Object
|
|
1510 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list)
|
|
1511 {
|
|
1512 REGISTER Lisp_Object tail, prev;
|
|
1513 REGISTER Lisp_Object tem;
|
|
1514
|
|
1515 tail = list;
|
|
1516 prev = Qnil;
|
|
1517 while (CONSP (tail))
|
|
1518 {
|
|
1519 Lisp_Object cons_to_free = Qnil;
|
|
1520 tem = XCAR (tail);
|
70
|
1521 if (EQ_WITH_EBOLA_NOTICE (elt, tem))
|
0
|
1522 {
|
|
1523 if (NILP (prev))
|
|
1524 list = XCDR (tail);
|
|
1525 else
|
|
1526 XCDR (prev) = XCDR (tail);
|
|
1527 cons_to_free = tail;
|
|
1528 }
|
|
1529 else
|
|
1530 prev = tail;
|
|
1531 tail = XCDR (tail);
|
|
1532 if (!NILP (cons_to_free))
|
|
1533 free_cons (XCONS (cons_to_free));
|
|
1534 }
|
|
1535 return list;
|
|
1536 }
|
|
1537
|
20
|
1538 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /*
|
0
|
1539 Delete by side effect any elements of LIST whose car is `equal' to KEY.
|
|
1540 The modified LIST is returned. If the first member of LIST has a car
|
|
1541 that is `equal' to KEY, there is no way to remove it by side effect;
|
|
1542 therefore, write `(setq foo (remassoc key foo))' to be sure of changing
|
|
1543 the value of `foo'.
|
20
|
1544 */
|
|
1545 (key, list))
|
0
|
1546 {
|
|
1547 REGISTER Lisp_Object tail, prev;
|
|
1548
|
|
1549 tail = list;
|
|
1550 prev = Qnil;
|
|
1551 while (!NILP (tail))
|
|
1552 {
|
|
1553 Lisp_Object elt = Fcar (tail);
|
|
1554 if (CONSP (elt) && ! NILP (Fequal (key, Fcar (elt))))
|
|
1555 {
|
|
1556 if (NILP (prev))
|
|
1557 list = Fcdr (tail);
|
|
1558 else
|
|
1559 Fsetcdr (prev, Fcdr (tail));
|
|
1560 }
|
|
1561 else
|
|
1562 prev = tail;
|
|
1563 tail = Fcdr (tail);
|
|
1564 QUIT;
|
|
1565 }
|
|
1566 return list;
|
|
1567 }
|
|
1568
|
|
1569 Lisp_Object
|
|
1570 remassoc_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1571 {
|
|
1572 int speccount = specpdl_depth ();
|
|
1573 specbind (Qinhibit_quit, Qt);
|
|
1574 return (unbind_to (speccount, Fremassoc (key, list)));
|
|
1575 }
|
|
1576
|
20
|
1577 DEFUN ("remassq", Fremassq, 2, 2, 0, /*
|
0
|
1578 Delete by side effect any elements of LIST whose car is `eq' to KEY.
|
|
1579 The modified LIST is returned. If the first member of LIST has a car
|
|
1580 that is `eq' to KEY, there is no way to remove it by side effect;
|
|
1581 therefore, write `(setq foo (remassq key foo))' to be sure of changing
|
|
1582 the value of `foo'.
|
20
|
1583 */
|
|
1584 (key, list))
|
0
|
1585 {
|
|
1586 REGISTER Lisp_Object tail, prev;
|
|
1587
|
|
1588 tail = list;
|
|
1589 prev = Qnil;
|
|
1590 while (!NILP (tail))
|
|
1591 {
|
|
1592 Lisp_Object elt = Fcar (tail);
|
70
|
1593 if (CONSP (elt) && EQ_WITH_EBOLA_NOTICE (key, Fcar (elt)))
|
0
|
1594 {
|
|
1595 if (NILP (prev))
|
|
1596 list = Fcdr (tail);
|
|
1597 else
|
|
1598 Fsetcdr (prev, Fcdr (tail));
|
|
1599 }
|
|
1600 else
|
|
1601 prev = tail;
|
|
1602 tail = Fcdr (tail);
|
|
1603 QUIT;
|
|
1604 }
|
|
1605 return list;
|
|
1606 }
|
|
1607
|
|
1608 /* no quit, no errors; be careful */
|
|
1609
|
|
1610 Lisp_Object
|
|
1611 remassq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1612 {
|
|
1613 REGISTER Lisp_Object tail, prev;
|
|
1614 REGISTER Lisp_Object tem;
|
|
1615
|
|
1616 tail = list;
|
|
1617 prev = Qnil;
|
|
1618 while (CONSP (tail))
|
|
1619 {
|
|
1620 tem = XCAR (tail);
|
70
|
1621 if (CONSP (tem) && EQ_WITH_EBOLA_NOTICE (key, XCAR (tem)))
|
0
|
1622 {
|
|
1623 if (NILP (prev))
|
|
1624 list = XCDR (tail);
|
|
1625 else
|
|
1626 XCDR (prev) = XCDR (tail);
|
|
1627 }
|
|
1628 else
|
|
1629 prev = tail;
|
|
1630 tail = XCDR (tail);
|
|
1631 }
|
|
1632 return list;
|
|
1633 }
|
|
1634
|
20
|
1635 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /*
|
0
|
1636 Delete by side effect any elements of LIST whose cdr is `equal' to VALUE.
|
|
1637 The modified LIST is returned. If the first member of LIST has a car
|
|
1638 that is `equal' to VALUE, there is no way to remove it by side effect;
|
|
1639 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing
|
|
1640 the value of `foo'.
|
20
|
1641 */
|
|
1642 (value, list))
|
0
|
1643 {
|
|
1644 REGISTER Lisp_Object tail, prev;
|
|
1645
|
|
1646 tail = list;
|
|
1647 prev = Qnil;
|
|
1648 while (!NILP (tail))
|
|
1649 {
|
|
1650 Lisp_Object elt = Fcar (tail);
|
|
1651 if (CONSP (elt) && ! NILP (Fequal (value, Fcdr (elt))))
|
|
1652 {
|
|
1653 if (NILP (prev))
|
|
1654 list = Fcdr (tail);
|
|
1655 else
|
|
1656 Fsetcdr (prev, Fcdr (tail));
|
|
1657 }
|
|
1658 else
|
|
1659 prev = tail;
|
|
1660 tail = Fcdr (tail);
|
|
1661 QUIT;
|
|
1662 }
|
|
1663 return list;
|
|
1664 }
|
|
1665
|
20
|
1666 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /*
|
0
|
1667 Delete by side effect any elements of LIST whose cdr is `eq' to VALUE.
|
|
1668 The modified LIST is returned. If the first member of LIST has a car
|
|
1669 that is `eq' to VALUE, there is no way to remove it by side effect;
|
|
1670 therefore, write `(setq foo (remrassq value foo))' to be sure of changing
|
|
1671 the value of `foo'.
|
20
|
1672 */
|
|
1673 (value, list))
|
0
|
1674 {
|
|
1675 REGISTER Lisp_Object tail, prev;
|
|
1676
|
|
1677 tail = list;
|
|
1678 prev = Qnil;
|
|
1679 while (!NILP (tail))
|
|
1680 {
|
|
1681 Lisp_Object elt = Fcar (tail);
|
70
|
1682 if (CONSP (elt) && EQ_WITH_EBOLA_NOTICE (value, Fcdr (elt)))
|
0
|
1683 {
|
|
1684 if (NILP (prev))
|
|
1685 list = Fcdr (tail);
|
|
1686 else
|
|
1687 Fsetcdr (prev, Fcdr (tail));
|
|
1688 }
|
|
1689 else
|
|
1690 prev = tail;
|
|
1691 tail = Fcdr (tail);
|
|
1692 QUIT;
|
|
1693 }
|
|
1694 return list;
|
|
1695 }
|
|
1696
|
|
1697 /* no quit, no errors; be careful */
|
|
1698
|
|
1699 Lisp_Object
|
|
1700 remrassq_no_quit (Lisp_Object value, Lisp_Object list)
|
|
1701 {
|
|
1702 REGISTER Lisp_Object tail, prev;
|
|
1703 REGISTER Lisp_Object tem;
|
|
1704
|
|
1705 tail = list;
|
|
1706 prev = Qnil;
|
|
1707 while (CONSP (tail))
|
|
1708 {
|
|
1709 tem = XCAR (tail);
|
70
|
1710 if (CONSP (tem) && EQ_WITH_EBOLA_NOTICE (value, XCDR (tem)))
|
0
|
1711 {
|
|
1712 if (NILP (prev))
|
|
1713 list = XCDR (tail);
|
|
1714 else
|
|
1715 XCDR (prev) = XCDR (tail);
|
|
1716 }
|
|
1717 else
|
|
1718 prev = tail;
|
|
1719 tail = XCDR (tail);
|
|
1720 }
|
|
1721 return list;
|
|
1722 }
|
|
1723
|
20
|
1724 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /*
|
0
|
1725 Reverse LIST by modifying cdr pointers.
|
|
1726 Returns the beginning of the reversed list.
|
20
|
1727 */
|
|
1728 (list))
|
0
|
1729 {
|
|
1730 Lisp_Object prev, tail, next;
|
|
1731 struct gcpro gcpro1, gcpro2;
|
|
1732
|
|
1733 /* We gcpro our args; see `nconc' */
|
|
1734 prev = Qnil;
|
|
1735 tail = list;
|
|
1736 GCPRO2 (prev, tail);
|
|
1737 while (!NILP (tail))
|
|
1738 {
|
|
1739 QUIT;
|
|
1740 next = Fcdr (tail);
|
|
1741 Fsetcdr (tail, prev);
|
|
1742 prev = tail;
|
|
1743 tail = next;
|
|
1744 }
|
|
1745 UNGCPRO;
|
|
1746 return prev;
|
|
1747 }
|
|
1748
|
20
|
1749 DEFUN ("reverse", Freverse, 1, 1, 0, /*
|
0
|
1750 Reverse LIST, copying. Returns the beginning of the reversed list.
|
|
1751 See also the function `nreverse', which is used more often.
|
20
|
1752 */
|
|
1753 (list))
|
0
|
1754 {
|
|
1755 Lisp_Object length;
|
|
1756 Lisp_Object *vec;
|
|
1757 Lisp_Object tail;
|
|
1758 REGISTER int i;
|
|
1759
|
|
1760 length = Flength (list);
|
|
1761 vec = (Lisp_Object *) alloca (XINT (length) * sizeof (Lisp_Object));
|
|
1762 for (i = XINT (length) - 1, tail = list; i >= 0; i--, tail = Fcdr (tail))
|
|
1763 vec[i] = Fcar (tail);
|
|
1764
|
|
1765 return Flist (XINT (length), vec);
|
|
1766 }
|
|
1767
|
|
1768 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1769 Lisp_Object lisp_arg,
|
|
1770 int (*pred_fn) (Lisp_Object, Lisp_Object,
|
|
1771 Lisp_Object lisp_arg));
|
|
1772
|
|
1773 Lisp_Object
|
|
1774 list_sort (Lisp_Object list,
|
|
1775 Lisp_Object lisp_arg,
|
|
1776 int (*pred_fn) (Lisp_Object, Lisp_Object,
|
|
1777 Lisp_Object lisp_arg))
|
|
1778 {
|
|
1779 Lisp_Object front, back;
|
|
1780 Lisp_Object len, tem;
|
|
1781 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1782 int length;
|
|
1783
|
|
1784 front = list;
|
|
1785 len = Flength (list);
|
|
1786 length = XINT (len);
|
|
1787 if (length < 2)
|
|
1788 return list;
|
|
1789
|
|
1790 XSETINT (len, (length / 2) - 1);
|
|
1791 tem = Fnthcdr (len, list);
|
|
1792 back = Fcdr (tem);
|
|
1793 Fsetcdr (tem, Qnil);
|
|
1794
|
|
1795 GCPRO3 (front, back, lisp_arg);
|
|
1796 front = list_sort (front, lisp_arg, pred_fn);
|
|
1797 back = list_sort (back, lisp_arg, pred_fn);
|
|
1798 UNGCPRO;
|
|
1799 return list_merge (front, back, lisp_arg, pred_fn);
|
|
1800 }
|
|
1801
|
|
1802
|
|
1803 static int
|
|
1804 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2,
|
|
1805 Lisp_Object pred)
|
|
1806 {
|
|
1807 Lisp_Object tmp;
|
|
1808
|
|
1809 /* prevents the GC from happening in call2 */
|
|
1810 int speccount = specpdl_depth ();
|
|
1811 /* Emacs' GC doesn't actually relocate pointers, so this probably
|
|
1812 isn't strictly necessary */
|
|
1813 record_unwind_protect (restore_gc_inhibit,
|
|
1814 make_int (gc_currently_forbidden));
|
|
1815 gc_currently_forbidden = 1;
|
|
1816 tmp = call2 (pred, obj1, obj2);
|
|
1817 unbind_to (speccount, Qnil);
|
|
1818
|
|
1819 if (NILP (tmp))
|
|
1820 return -1;
|
|
1821 else
|
|
1822 return 1;
|
|
1823 }
|
|
1824
|
20
|
1825 DEFUN ("sort", Fsort, 2, 2, 0, /*
|
0
|
1826 Sort LIST, stably, comparing elements using PREDICATE.
|
|
1827 Returns the sorted list. LIST is modified by side effects.
|
|
1828 PREDICATE is called with two elements of LIST, and should return T
|
|
1829 if the first element is \"less\" than the second.
|
20
|
1830 */
|
|
1831 (list, pred))
|
0
|
1832 {
|
|
1833 return list_sort (list, pred, merge_pred_function);
|
|
1834 }
|
|
1835
|
|
1836 Lisp_Object
|
|
1837 merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1838 Lisp_Object pred)
|
|
1839 {
|
|
1840 return list_merge (org_l1, org_l2, pred, merge_pred_function);
|
|
1841 }
|
|
1842
|
|
1843
|
|
1844 static Lisp_Object
|
|
1845 list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1846 Lisp_Object lisp_arg,
|
|
1847 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg))
|
|
1848 {
|
|
1849 Lisp_Object value;
|
|
1850 Lisp_Object tail;
|
|
1851 Lisp_Object tem;
|
|
1852 Lisp_Object l1, l2;
|
|
1853 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1854
|
|
1855 l1 = org_l1;
|
|
1856 l2 = org_l2;
|
|
1857 tail = Qnil;
|
|
1858 value = Qnil;
|
|
1859
|
|
1860 /* It is sufficient to protect org_l1 and org_l2.
|
|
1861 When l1 and l2 are updated, we copy the new values
|
|
1862 back into the org_ vars. */
|
|
1863
|
|
1864 GCPRO4 (org_l1, org_l2, lisp_arg, value);
|
|
1865
|
|
1866 while (1)
|
|
1867 {
|
|
1868 if (NILP (l1))
|
|
1869 {
|
|
1870 UNGCPRO;
|
|
1871 if (NILP (tail))
|
|
1872 return l2;
|
|
1873 Fsetcdr (tail, l2);
|
|
1874 return value;
|
|
1875 }
|
|
1876 if (NILP (l2))
|
|
1877 {
|
|
1878 UNGCPRO;
|
|
1879 if (NILP (tail))
|
|
1880 return l1;
|
|
1881 Fsetcdr (tail, l1);
|
|
1882 return value;
|
|
1883 }
|
|
1884
|
|
1885 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0)
|
|
1886 {
|
|
1887 tem = l1;
|
|
1888 l1 = Fcdr (l1);
|
|
1889 org_l1 = l1;
|
|
1890 }
|
|
1891 else
|
|
1892 {
|
|
1893 tem = l2;
|
|
1894 l2 = Fcdr (l2);
|
|
1895 org_l2 = l2;
|
|
1896 }
|
|
1897 if (NILP (tail))
|
|
1898 value = tem;
|
|
1899 else
|
|
1900 Fsetcdr (tail, tem);
|
|
1901 tail = tem;
|
|
1902 }
|
|
1903 }
|
|
1904
|
|
1905
|
|
1906 /************************************************************************/
|
|
1907 /* property-list functions */
|
|
1908 /************************************************************************/
|
|
1909
|
|
1910 /* For properties of text, we need to do order-insensitive comparison of
|
|
1911 plists. That is, we need to compare two plists such that they are the
|
|
1912 same if they have the same set of keys, and equivalent values.
|
|
1913 So (a 1 b 2) would be equal to (b 2 a 1).
|
|
1914
|
|
1915 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc.
|
|
1916 LAXP means use `equal' for comparisons.
|
|
1917 */
|
|
1918 int
|
|
1919 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present,
|
|
1920 int laxp, int depth)
|
|
1921 {
|
|
1922 int eqp = (depth == -1); /* -1 as depth means us eq, not equal. */
|
|
1923 int la, lb, m, i, fill;
|
|
1924 Lisp_Object *keys, *vals;
|
|
1925 char *flags;
|
|
1926 Lisp_Object rest;
|
|
1927
|
|
1928 if (NILP (a) && NILP (b))
|
|
1929 return 0;
|
|
1930
|
|
1931 Fcheck_valid_plist (a);
|
|
1932 Fcheck_valid_plist (b);
|
|
1933
|
|
1934 la = XINT (Flength (a));
|
|
1935 lb = XINT (Flength (b));
|
|
1936 m = (la > lb ? la : lb);
|
|
1937 fill = 0;
|
|
1938 keys = (Lisp_Object *) alloca (m * sizeof (Lisp_Object));
|
|
1939 vals = (Lisp_Object *) alloca (m * sizeof (Lisp_Object));
|
|
1940 flags = (char *) alloca (m * sizeof (char));
|
|
1941
|
|
1942 /* First extract the pairs from A. */
|
|
1943 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest)))
|
|
1944 {
|
|
1945 Lisp_Object k = XCAR (rest);
|
|
1946 Lisp_Object v = XCAR (XCDR (rest));
|
|
1947 /* Maybe be Ebolified. */
|
|
1948 if (nil_means_not_present && NILP (v)) continue;
|
|
1949 keys [fill] = k;
|
|
1950 vals [fill] = v;
|
|
1951 flags[fill] = 0;
|
|
1952 fill++;
|
|
1953 }
|
|
1954 /* Now iterate over B, and stop if we find something that's not in A,
|
|
1955 or that doesn't match. As we match, mark them. */
|
|
1956 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest)))
|
|
1957 {
|
|
1958 Lisp_Object k = XCAR (rest);
|
|
1959 Lisp_Object v = XCAR (XCDR (rest));
|
|
1960 /* Maybe be Ebolified. */
|
|
1961 if (nil_means_not_present && NILP (v)) continue;
|
|
1962 for (i = 0; i < fill; i++)
|
|
1963 {
|
|
1964 if (!laxp ? EQ (k, keys [i]) : internal_equal (k, keys [i], depth))
|
|
1965 {
|
|
1966 if ((eqp
|
70
|
1967 /* We narrowly escaped being Ebolified here. */
|
|
1968 ? !EQ_WITH_EBOLA_NOTICE (v, vals [i])
|
0
|
1969 : !internal_equal (v, vals [i], depth)))
|
|
1970 /* a property in B has a different value than in A */
|
|
1971 goto MISMATCH;
|
|
1972 flags [i] = 1;
|
|
1973 break;
|
|
1974 }
|
|
1975 }
|
|
1976 if (i == fill)
|
|
1977 /* there are some properties in B that are not in A */
|
|
1978 goto MISMATCH;
|
|
1979 }
|
|
1980 /* Now check to see that all the properties in A were also in B */
|
|
1981 for (i = 0; i < fill; i++)
|
|
1982 if (flags [i] == 0)
|
|
1983 goto MISMATCH;
|
|
1984
|
|
1985 /* Ok. */
|
|
1986 return 0;
|
|
1987
|
|
1988 MISMATCH:
|
|
1989 return 1;
|
|
1990 }
|
|
1991
|
20
|
1992 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /*
|
0
|
1993 Return non-nil if property lists A and B are `eq'.
|
|
1994 A property list is an alternating list of keywords and values.
|
|
1995 This function does order-insensitive comparisons of the property lists:
|
|
1996 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
1997 Comparison between values is done using `eq'. See also `plists-equal'.
|
|
1998 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
1999 a nil value is ignored. This feature is a virus that has infected
|
16
|
2000 old Lisp implementations, but should not be used except for backward
|
|
2001 compatibility.
|
20
|
2002 */
|
|
2003 (a, b, nil_means_not_present))
|
0
|
2004 {
|
|
2005 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1)
|
|
2006 ? Qnil : Qt);
|
|
2007 }
|
|
2008
|
20
|
2009 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /*
|
0
|
2010 Return non-nil if property lists A and B are `equal'.
|
|
2011 A property list is an alternating list of keywords and values. This
|
|
2012 function does order-insensitive comparisons of the property lists: For
|
|
2013 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2014 Comparison between values is done using `equal'. See also `plists-eq'.
|
|
2015 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2016 a nil value is ignored. This feature is a virus that has infected
|
16
|
2017 old Lisp implementations, but should not be used except for backward
|
|
2018 compatibility.
|
20
|
2019 */
|
|
2020 (a, b, nil_means_not_present))
|
0
|
2021 {
|
|
2022 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1)
|
|
2023 ? Qnil : Qt);
|
|
2024 }
|
|
2025
|
|
2026
|
20
|
2027 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /*
|
0
|
2028 Return non-nil if lax property lists A and B are `eq'.
|
|
2029 A property list is an alternating list of keywords and values.
|
|
2030 This function does order-insensitive comparisons of the property lists:
|
|
2031 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2032 Comparison between values is done using `eq'. See also `plists-equal'.
|
|
2033 A lax property list is like a regular one except that comparisons between
|
|
2034 keywords is done using `equal' instead of `eq'.
|
|
2035 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2036 a nil value is ignored. This feature is a virus that has infected
|
16
|
2037 old Lisp implementations, but should not be used except for backward
|
|
2038 compatibility.
|
20
|
2039 */
|
|
2040 (a, b, nil_means_not_present))
|
0
|
2041 {
|
|
2042 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1)
|
|
2043 ? Qnil : Qt);
|
|
2044 }
|
|
2045
|
20
|
2046 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /*
|
0
|
2047 Return non-nil if lax property lists A and B are `equal'.
|
|
2048 A property list is an alternating list of keywords and values. This
|
|
2049 function does order-insensitive comparisons of the property lists: For
|
|
2050 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2051 Comparison between values is done using `equal'. See also `plists-eq'.
|
|
2052 A lax property list is like a regular one except that comparisons between
|
|
2053 keywords is done using `equal' instead of `eq'.
|
|
2054 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2055 a nil value is ignored. This feature is a virus that has infected
|
16
|
2056 old Lisp implementations, but should not be used except for backward
|
|
2057 compatibility.
|
20
|
2058 */
|
|
2059 (a, b, nil_means_not_present))
|
0
|
2060 {
|
|
2061 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1)
|
|
2062 ? Qnil : Qt);
|
|
2063 }
|
|
2064
|
|
2065 /* Return the value associated with key PROPERTY in property list PLIST.
|
|
2066 Return nil if key not found. This function is used for internal
|
|
2067 property lists that cannot be directly manipulated by the user.
|
|
2068 */
|
|
2069
|
|
2070 Lisp_Object
|
|
2071 internal_plist_get (Lisp_Object plist, Lisp_Object property)
|
|
2072 {
|
|
2073 Lisp_Object tail = plist;
|
|
2074
|
|
2075 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
|
|
2076 {
|
|
2077 struct Lisp_Cons *c = XCONS (tail);
|
|
2078 if (EQ (c->car, property))
|
|
2079 return XCAR (c->cdr);
|
|
2080 }
|
|
2081
|
|
2082 return Qunbound;
|
|
2083 }
|
|
2084
|
|
2085 /* Set PLIST's value for PROPERTY to VALUE. Analogous to
|
|
2086 internal_plist_get(). */
|
|
2087
|
|
2088 void
|
|
2089 internal_plist_put (Lisp_Object *plist, Lisp_Object property,
|
|
2090 Lisp_Object value)
|
|
2091 {
|
|
2092 Lisp_Object tail = *plist;
|
|
2093
|
|
2094 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
|
|
2095 {
|
|
2096 struct Lisp_Cons *c = XCONS (tail);
|
|
2097 if (EQ (c->car, property))
|
|
2098 {
|
|
2099 XCAR (c->cdr) = value;
|
|
2100 return;
|
|
2101 }
|
|
2102 }
|
|
2103
|
|
2104 *plist = Fcons (property, Fcons (value, *plist));
|
|
2105 }
|
|
2106
|
|
2107 int
|
|
2108 internal_remprop (Lisp_Object *plist, Lisp_Object property)
|
|
2109 {
|
|
2110 Lisp_Object tail = *plist;
|
|
2111
|
|
2112 if (NILP (tail))
|
|
2113 return 0;
|
|
2114
|
|
2115 if (EQ (XCAR (tail), property))
|
|
2116 {
|
|
2117 *plist = XCDR (XCDR (tail));
|
|
2118 return 1;
|
|
2119 }
|
|
2120
|
|
2121 for (tail = XCDR (tail); !NILP (XCDR (tail));
|
|
2122 tail = XCDR (XCDR (tail)))
|
|
2123 {
|
|
2124 struct Lisp_Cons *c = XCONS (tail);
|
|
2125 if (EQ (XCAR (c->cdr), property))
|
|
2126 {
|
|
2127 c->cdr = XCDR (XCDR (c->cdr));
|
|
2128 return 1;
|
|
2129 }
|
|
2130 }
|
|
2131
|
|
2132 return 0;
|
|
2133 }
|
|
2134
|
|
2135 /* Called on a malformed property list. BADPLACE should be some
|
|
2136 place where truncating will form a good list -- i.e. we shouldn't
|
|
2137 result in a list with an odd length. */
|
|
2138
|
|
2139 static Lisp_Object
|
|
2140 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
|
|
2141 {
|
|
2142 if (ERRB_EQ (errb, ERROR_ME))
|
|
2143 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace));
|
|
2144 else
|
|
2145 {
|
|
2146 if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2147 {
|
|
2148 warn_when_safe_lispobj
|
|
2149 (Qlist, Qwarning,
|
|
2150 list2 (build_string
|
|
2151 ("Malformed property list -- list has been truncated"),
|
|
2152 *plist));
|
|
2153 *badplace = Qnil;
|
|
2154 }
|
|
2155 return Qunbound;
|
|
2156 }
|
|
2157 }
|
|
2158
|
|
2159 /* Called on a circular property list. BADPLACE should be some place
|
|
2160 where truncating will result in an even-length list, as above.
|
|
2161 If doesn't particularly matter where we truncate -- anywhere we
|
|
2162 truncate along the entire list will break the circularity, because
|
|
2163 it will create a terminus and the list currently doesn't have one.
|
|
2164 */
|
|
2165
|
|
2166 static Lisp_Object
|
|
2167 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
|
|
2168 {
|
|
2169 if (ERRB_EQ (errb, ERROR_ME))
|
|
2170 /* #### Eek, this will probably result in another error
|
|
2171 when PLIST is printed out */
|
|
2172 return Fsignal (Qcircular_property_list, list1 (*plist));
|
|
2173 else
|
|
2174 {
|
|
2175 if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2176 {
|
|
2177 warn_when_safe_lispobj
|
|
2178 (Qlist, Qwarning,
|
|
2179 list2 (build_string
|
|
2180 ("Circular property list -- list has been truncated"),
|
|
2181 *plist));
|
|
2182 *badplace = Qnil;
|
|
2183 }
|
|
2184 return Qunbound;
|
|
2185 }
|
|
2186 }
|
|
2187
|
|
2188 /* Advance the tortoise pointer by two (one iteration of a property-list
|
|
2189 loop) and the hare pointer by four and verify that no malformations
|
|
2190 or circularities exist. If so, return zero and store a value into
|
|
2191 RETVAL that should be returned by the calling function. Otherwise,
|
|
2192 return 1. See external_plist_get().
|
|
2193 */
|
|
2194
|
|
2195 static int
|
|
2196 advance_plist_pointers (Lisp_Object *plist,
|
|
2197 Lisp_Object **tortoise, Lisp_Object **hare,
|
|
2198 Error_behavior errb, Lisp_Object *retval)
|
|
2199 {
|
|
2200 int i;
|
|
2201 Lisp_Object *tortsave = *tortoise;
|
|
2202
|
|
2203 /* Note that our "fixing" may be more brutal than necessary,
|
|
2204 but it's the user's own problem, not ours. if they went in and
|
|
2205 manually fucked up a plist. */
|
|
2206
|
|
2207 for (i = 0; i < 2; i++)
|
|
2208 {
|
|
2209 /* This is a standard iteration of a defensive-loop-checking
|
|
2210 loop. We just do it twice because we want to advance past
|
|
2211 both the property and its value.
|
|
2212
|
|
2213 If the pointer indirection is confusing you, remember that
|
|
2214 one level of indirection on the hare and tortoise pointers
|
|
2215 is only due to pass-by-reference for this function. The other
|
|
2216 level is so that the plist can be fixed in place. */
|
|
2217
|
|
2218 /* When we reach the end of a well-formed plist, **HARE is
|
|
2219 nil. In that case, we don't do anything at all except
|
|
2220 advance TORTOISE by one. Otherwise, we advance HARE
|
|
2221 by two (making sure it's OK to do so), then advance
|
|
2222 TORTOISE by one (it will always be OK to do so because
|
|
2223 the HARE is always ahead of the TORTOISE and will have
|
|
2224 already verified the path), then make sure TORTOISE and
|
|
2225 HARE don't contain the same non-nil object -- if the
|
|
2226 TORTOISE and the HARE ever meet, then obviously we're
|
|
2227 in a circularity, and if we're in a circularity, then
|
|
2228 the TORTOISE and the HARE can't cross paths without
|
|
2229 meeting, since the HARE only gains one step over the
|
|
2230 TORTOISE per iteration. */
|
|
2231
|
|
2232 if (!NILP (**hare))
|
|
2233 {
|
|
2234 Lisp_Object *haresave = *hare;
|
|
2235 if (!CONSP (**hare))
|
|
2236 {
|
|
2237 *retval = bad_bad_bunny (plist, haresave, errb);
|
|
2238 return 0;
|
|
2239 }
|
|
2240 *hare = &XCDR (**hare);
|
|
2241 /* In a non-plist, we'd check here for a nil value for
|
|
2242 **HARE, which is OK (it just means the list has an
|
|
2243 odd number of elements). In a plist, it's not OK
|
|
2244 for the list to have an odd number of elements. */
|
|
2245 if (!CONSP (**hare))
|
|
2246 {
|
|
2247 *retval = bad_bad_bunny (plist, haresave, errb);
|
|
2248 return 0;
|
|
2249 }
|
|
2250 *hare = &XCDR (**hare);
|
|
2251 }
|
|
2252
|
|
2253 *tortoise = &XCDR (**tortoise);
|
|
2254 if (!NILP (**hare) && EQ (**tortoise, **hare))
|
|
2255 {
|
|
2256 *retval = bad_bad_turtle (plist, tortsave, errb);
|
|
2257 return 0;
|
|
2258 }
|
|
2259 }
|
|
2260
|
|
2261 return 1;
|
|
2262 }
|
|
2263
|
|
2264 /* Return the value of PROPERTY from PLIST, or Qunbound if
|
|
2265 property is not on the list.
|
|
2266
|
|
2267 PLIST is a Lisp-accessible property list, meaning that it
|
|
2268 has to be checked for malformations and circularities.
|
|
2269
|
|
2270 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the
|
|
2271 function will never signal an error; and if ERRB is ERROR_ME_WARN,
|
|
2272 on finding a malformation or a circularity, it issues a warning and
|
|
2273 attempts to silently fix the problem.
|
|
2274
|
|
2275 A pointer to PLIST is passed in so that PLIST can be successfully
|
|
2276 "fixed" even if the error is at the beginning of the plist. */
|
|
2277
|
|
2278 Lisp_Object
|
|
2279 external_plist_get (Lisp_Object *plist, Lisp_Object property,
|
|
2280 int laxp, Error_behavior errb)
|
|
2281 {
|
|
2282 Lisp_Object *tortoise = plist;
|
|
2283 Lisp_Object *hare = plist;
|
|
2284
|
|
2285 while (!NILP (*tortoise))
|
|
2286 {
|
|
2287 Lisp_Object *tortsave = tortoise;
|
|
2288 Lisp_Object retval;
|
|
2289
|
|
2290 /* We do the standard tortoise/hare march. We isolate the
|
|
2291 grungy stuff to do this in advance_plist_pointers(), though.
|
|
2292 To us, all this function does is advance the tortoise
|
|
2293 pointer by two and the hare pointer by four and make sure
|
|
2294 everything's OK. We first advance the pointers and then
|
|
2295 check if a property matched; this ensures that our
|
|
2296 check for a matching property is safe. */
|
|
2297
|
|
2298 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2299 return retval;
|
|
2300
|
|
2301 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2302 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2303 return XCAR (XCDR (*tortsave));
|
|
2304 }
|
|
2305
|
|
2306 return Qunbound;
|
|
2307 }
|
|
2308
|
|
2309 /* Set PLIST's value for PROPERTY to VALUE, given a possibly
|
|
2310 malformed or circular plist. Analogous to external_plist_get(). */
|
|
2311
|
|
2312 void
|
|
2313 external_plist_put (Lisp_Object *plist, Lisp_Object property,
|
|
2314 Lisp_Object value, int laxp, Error_behavior errb)
|
|
2315 {
|
|
2316 Lisp_Object *tortoise = plist;
|
|
2317 Lisp_Object *hare = plist;
|
|
2318
|
|
2319 while (!NILP (*tortoise))
|
|
2320 {
|
|
2321 Lisp_Object *tortsave = tortoise;
|
|
2322 Lisp_Object retval;
|
|
2323
|
|
2324 /* See above */
|
|
2325 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2326 return;
|
|
2327
|
|
2328 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2329 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2330 {
|
|
2331 XCAR (XCDR (*tortsave)) = value;
|
|
2332 return;
|
|
2333 }
|
|
2334 }
|
|
2335
|
|
2336 *plist = Fcons (property, Fcons (value, *plist));
|
|
2337 }
|
|
2338
|
|
2339 int
|
|
2340 external_remprop (Lisp_Object *plist, Lisp_Object property,
|
|
2341 int laxp, Error_behavior errb)
|
|
2342 {
|
|
2343 Lisp_Object *tortoise = plist;
|
|
2344 Lisp_Object *hare = plist;
|
|
2345
|
|
2346 while (!NILP (*tortoise))
|
|
2347 {
|
|
2348 Lisp_Object *tortsave = tortoise;
|
|
2349 Lisp_Object retval;
|
|
2350
|
|
2351 /* See above */
|
|
2352 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2353 return 0;
|
|
2354
|
|
2355 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2356 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2357 {
|
|
2358 /* Now you see why it's so convenient to have that level
|
|
2359 of indirection. */
|
|
2360 *tortsave = XCDR (XCDR (*tortsave));
|
|
2361 return 1;
|
|
2362 }
|
|
2363 }
|
|
2364
|
|
2365 return 0;
|
|
2366 }
|
|
2367
|
20
|
2368 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /*
|
0
|
2369 Extract a value from a property list.
|
|
2370 PLIST is a property list, which is a list of the form
|
|
2371 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
|
|
2372 corresponding to the given PROP, or DEFAULT if PROP is not
|
|
2373 one of the properties on the list.
|
20
|
2374 */
|
|
2375 (plist, prop, defalt)) /* Cant spel in C */
|
0
|
2376 {
|
|
2377 Lisp_Object val = external_plist_get (&plist, prop, 0, ERROR_ME);
|
|
2378 if (UNBOUNDP (val))
|
|
2379 return defalt;
|
|
2380 return val;
|
|
2381 }
|
|
2382
|
20
|
2383 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /*
|
0
|
2384 Change value in PLIST of PROP to VAL.
|
|
2385 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
|
|
2386 PROP2 VALUE2 ...). PROP is usually a symbol and VAL is any object.
|
|
2387 If PROP is already a property on the list, its value is set to VAL,
|
|
2388 otherwise the new PROP VAL pair is added. The new plist is returned;
|
|
2389 use `(setq x (plist-put x prop val))' to be sure to use the new value.
|
|
2390 The PLIST is modified by side effects.
|
20
|
2391 */
|
|
2392 (plist, prop, val))
|
0
|
2393 {
|
|
2394 external_plist_put (&plist, prop, val, 0, ERROR_ME);
|
|
2395 return plist;
|
|
2396 }
|
|
2397
|
20
|
2398 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /*
|
0
|
2399 Remove from PLIST the property PROP and its value.
|
|
2400 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
|
|
2401 PROP2 VALUE2 ...). PROP is usually a symbol. The new plist is
|
|
2402 returned; use `(setq x (plist-remprop x prop val))' to be sure to use
|
|
2403 the new value. The PLIST is modified by side effects.
|
20
|
2404 */
|
|
2405 (plist, prop))
|
0
|
2406 {
|
|
2407 external_remprop (&plist, prop, 0, ERROR_ME);
|
|
2408 return plist;
|
|
2409 }
|
|
2410
|
20
|
2411 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /*
|
0
|
2412 Return t if PROP has a value specified in PLIST.
|
20
|
2413 */
|
|
2414 (plist, prop))
|
0
|
2415 {
|
|
2416 return UNBOUNDP (Fplist_get (plist, prop, Qunbound)) ? Qnil : Qt;
|
|
2417 }
|
|
2418
|
20
|
2419 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /*
|
0
|
2420 Given a plist, signal an error if there is anything wrong with it.
|
|
2421 This means that it's a malformed or circular plist.
|
20
|
2422 */
|
|
2423 (plist))
|
0
|
2424 {
|
|
2425 Lisp_Object *tortoise;
|
|
2426 Lisp_Object *hare;
|
|
2427
|
|
2428 start_over:
|
|
2429 tortoise = &plist;
|
|
2430 hare = &plist;
|
|
2431 while (!NILP (*tortoise))
|
|
2432 {
|
|
2433 Lisp_Object retval;
|
|
2434
|
|
2435 /* See above */
|
|
2436 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME,
|
|
2437 &retval))
|
|
2438 goto start_over;
|
|
2439 }
|
|
2440
|
|
2441 return Qnil;
|
|
2442 }
|
|
2443
|
20
|
2444 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /*
|
0
|
2445 Given a plist, return non-nil if its format is correct.
|
|
2446 If it returns nil, `check-valid-plist' will signal an error when given
|
|
2447 the plist; that means it's a malformed or circular plist or has non-symbols
|
|
2448 as keywords.
|
20
|
2449 */
|
|
2450 (plist))
|
0
|
2451 {
|
|
2452 Lisp_Object *tortoise;
|
|
2453 Lisp_Object *hare;
|
|
2454
|
|
2455 tortoise = &plist;
|
|
2456 hare = &plist;
|
|
2457 while (!NILP (*tortoise))
|
|
2458 {
|
|
2459 Lisp_Object retval;
|
|
2460
|
|
2461 /* See above */
|
|
2462 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT,
|
|
2463 &retval))
|
|
2464 return Qnil;
|
|
2465 }
|
|
2466
|
|
2467 return Qt;
|
|
2468 }
|
|
2469
|
20
|
2470 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /*
|
0
|
2471 Destructively remove any duplicate entries from a plist.
|
|
2472 In such cases, the first entry applies.
|
|
2473
|
|
2474 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2475 a nil value is removed. This feature is a virus that has infected
|
16
|
2476 old Lisp implementations, but should not be used except for backward
|
|
2477 compatibility.
|
0
|
2478
|
|
2479 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
|
|
2480 return value may not be EQ to the passed-in value, so make sure to
|
|
2481 `setq' the value back into where it came from.
|
20
|
2482 */
|
|
2483 (plist, nil_means_not_present))
|
0
|
2484 {
|
|
2485 Lisp_Object head = plist;
|
|
2486
|
|
2487 Fcheck_valid_plist (plist);
|
|
2488
|
|
2489 while (!NILP (plist))
|
|
2490 {
|
|
2491 Lisp_Object prop = Fcar (plist);
|
|
2492 Lisp_Object next = Fcdr (plist);
|
|
2493
|
|
2494 CHECK_CONS (next); /* just make doubly sure we catch any errors */
|
|
2495 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
|
|
2496 {
|
|
2497 if (EQ (head, plist))
|
|
2498 head = Fcdr (next);
|
|
2499 plist = Fcdr (next);
|
|
2500 continue;
|
|
2501 }
|
|
2502 /* external_remprop returns 1 if it removed any property.
|
|
2503 We have to loop till it didn't remove anything, in case
|
|
2504 the property occurs many times. */
|
|
2505 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME));
|
|
2506 plist = Fcdr (next);
|
|
2507 }
|
|
2508
|
|
2509 return head;
|
|
2510 }
|
|
2511
|
20
|
2512 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /*
|
0
|
2513 Extract a value from a lax property list.
|
|
2514
|
|
2515 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2516 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2517 using `equal' instead of `eq'. This function returns the value
|
|
2518 corresponding to the given PROP, or DEFAULT if PROP is not one of the
|
|
2519 properties on the list.
|
20
|
2520 */
|
|
2521 (lax_plist, prop, defalt)) /* Cant spel in C */
|
0
|
2522 {
|
|
2523 Lisp_Object val = external_plist_get (&lax_plist, prop, 1, ERROR_ME);
|
|
2524 if (UNBOUNDP (val))
|
|
2525 return defalt;
|
|
2526 return val;
|
|
2527 }
|
|
2528
|
20
|
2529 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /*
|
0
|
2530 Change value in LAX-PLIST of PROP to VAL.
|
|
2531 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2532 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2533 using `equal' instead of `eq'. PROP is usually a symbol and VAL is
|
|
2534 any object. If PROP is already a property on the list, its value is
|
|
2535 set to VAL, otherwise the new PROP VAL pair is added. The new plist
|
|
2536 is returned; use `(setq x (lax-plist-put x prop val))' to be sure to
|
|
2537 use the new value. The LAX-PLIST is modified by side effects.
|
20
|
2538 */
|
|
2539 (lax_plist, prop, val))
|
0
|
2540 {
|
|
2541 external_plist_put (&lax_plist, prop, val, 1, ERROR_ME);
|
|
2542 return lax_plist;
|
|
2543 }
|
|
2544
|
20
|
2545 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /*
|
0
|
2546 Remove from LAX-PLIST the property PROP and its value.
|
|
2547 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2548 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2549 using `equal' instead of `eq'. PROP is usually a symbol. The new
|
|
2550 plist is returned; use `(setq x (lax-plist-remprop x prop val))' to be
|
|
2551 sure to use the new value. The LAX-PLIST is modified by side effects.
|
20
|
2552 */
|
|
2553 (lax_plist, prop))
|
0
|
2554 {
|
|
2555 external_remprop (&lax_plist, prop, 1, ERROR_ME);
|
|
2556 return lax_plist;
|
|
2557 }
|
|
2558
|
20
|
2559 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /*
|
0
|
2560 Return t if PROP has a value specified in LAX-PLIST.
|
|
2561 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2562 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2563 using `equal' instead of `eq'.
|
20
|
2564 */
|
|
2565 (lax_plist, prop))
|
0
|
2566 {
|
|
2567 return UNBOUNDP (Flax_plist_get (lax_plist, prop, Qunbound)) ? Qnil : Qt;
|
|
2568 }
|
|
2569
|
20
|
2570 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /*
|
0
|
2571 Destructively remove any duplicate entries from a lax plist.
|
|
2572 In such cases, the first entry applies.
|
|
2573
|
|
2574 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2575 a nil value is removed. This feature is a virus that has infected
|
16
|
2576 old Lisp implementations, but should not be used except for backward
|
|
2577 compatibility.
|
0
|
2578
|
|
2579 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
|
|
2580 return value may not be EQ to the passed-in value, so make sure to
|
|
2581 `setq' the value back into where it came from.
|
20
|
2582 */
|
|
2583 (lax_plist, nil_means_not_present))
|
0
|
2584 {
|
|
2585 Lisp_Object head = lax_plist;
|
|
2586
|
|
2587 Fcheck_valid_plist (lax_plist);
|
|
2588
|
|
2589 while (!NILP (lax_plist))
|
|
2590 {
|
|
2591 Lisp_Object prop = Fcar (lax_plist);
|
|
2592 Lisp_Object next = Fcdr (lax_plist);
|
|
2593
|
|
2594 CHECK_CONS (next); /* just make doubly sure we catch any errors */
|
|
2595 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
|
|
2596 {
|
|
2597 if (EQ (head, lax_plist))
|
|
2598 head = Fcdr (next);
|
|
2599 lax_plist = Fcdr (next);
|
|
2600 continue;
|
|
2601 }
|
|
2602 /* external_remprop returns 1 if it removed any property.
|
|
2603 We have to loop till it didn't remove anything, in case
|
|
2604 the property occurs many times. */
|
|
2605 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME));
|
|
2606 lax_plist = Fcdr (next);
|
|
2607 }
|
|
2608
|
|
2609 return head;
|
|
2610 }
|
|
2611
|
|
2612 /* In C because the frame props stuff uses it */
|
|
2613
|
20
|
2614 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /*
|
0
|
2615 Convert association list ALIST into the equivalent property-list form.
|
|
2616 The plist is returned. This converts from
|
|
2617
|
|
2618 \((a . 1) (b . 2) (c . 3))
|
|
2619
|
|
2620 into
|
|
2621
|
|
2622 \(a 1 b 2 c 3)
|
|
2623
|
|
2624 The original alist is destroyed in the process of constructing the plist.
|
|
2625 See also `alist-to-plist'.
|
20
|
2626 */
|
|
2627 (alist))
|
0
|
2628 {
|
|
2629 Lisp_Object head = alist;
|
|
2630 while (!NILP (alist))
|
|
2631 {
|
|
2632 /* remember the alist element. */
|
|
2633 Lisp_Object el = Fcar (alist);
|
|
2634
|
|
2635 Fsetcar (alist, Fcar (el));
|
|
2636 Fsetcar (el, Fcdr (el));
|
|
2637 Fsetcdr (el, Fcdr (alist));
|
|
2638 Fsetcdr (alist, el);
|
|
2639 alist = Fcdr (Fcdr (alist));
|
|
2640 }
|
|
2641
|
|
2642 return head;
|
|
2643 }
|
|
2644
|
|
2645 /* Symbol plists are directly accessible, so we need to protect against
|
|
2646 invalid property list structure */
|
|
2647
|
|
2648 static Lisp_Object
|
|
2649 symbol_getprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object defalt)
|
|
2650 {
|
|
2651 Lisp_Object val = external_plist_get (&XSYMBOL (sym)->plist, propname,
|
|
2652 0, ERROR_ME);
|
|
2653 if (UNBOUNDP (val))
|
|
2654 return defalt;
|
|
2655 return val;
|
|
2656 }
|
|
2657
|
|
2658 static void
|
|
2659 symbol_putprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object value)
|
|
2660 {
|
|
2661 external_plist_put (&XSYMBOL (sym)->plist, propname, value, 0, ERROR_ME);
|
|
2662 }
|
|
2663
|
|
2664 static int
|
|
2665 symbol_remprop (Lisp_Object symbol, Lisp_Object propname)
|
|
2666 {
|
|
2667 return external_remprop (&XSYMBOL (symbol)->plist, propname, 0, ERROR_ME);
|
|
2668 }
|
|
2669
|
|
2670 /* We store the string's extent info as the first element of the string's
|
|
2671 property list; and the string's MODIFF as the first or second element
|
|
2672 of the string's property list (depending on whether the extent info
|
|
2673 is present), but only if the string has been modified. This is ugly
|
|
2674 but it reduces the memory allocated for the string in the vast
|
|
2675 majority of cases, where the string is never modified and has no
|
|
2676 extent info. */
|
|
2677
|
|
2678
|
|
2679 static Lisp_Object *
|
|
2680 string_plist_ptr (struct Lisp_String *s)
|
|
2681 {
|
|
2682 Lisp_Object *ptr = &s->plist;
|
|
2683
|
|
2684 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
|
|
2685 ptr = &XCDR (*ptr);
|
|
2686 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
|
|
2687 ptr = &XCDR (*ptr);
|
|
2688 return ptr;
|
|
2689 }
|
|
2690
|
|
2691 Lisp_Object
|
|
2692 string_getprop (struct Lisp_String *s, Lisp_Object property,
|
|
2693 Lisp_Object defalt)
|
|
2694 {
|
|
2695 Lisp_Object val = external_plist_get (string_plist_ptr (s), property, 0,
|
|
2696 ERROR_ME);
|
|
2697 if (UNBOUNDP (val))
|
|
2698 return defalt;
|
|
2699 return val;
|
|
2700 }
|
|
2701
|
|
2702 void
|
|
2703 string_putprop (struct Lisp_String *s, Lisp_Object property,
|
|
2704 Lisp_Object value)
|
|
2705 {
|
|
2706 external_plist_put (string_plist_ptr (s), property, value, 0, ERROR_ME);
|
|
2707 }
|
|
2708
|
|
2709 static int
|
|
2710 string_remprop (struct Lisp_String *s, Lisp_Object property)
|
|
2711 {
|
|
2712 return external_remprop (string_plist_ptr (s), property, 0, ERROR_ME);
|
|
2713 }
|
|
2714
|
|
2715 static Lisp_Object
|
|
2716 string_plist (struct Lisp_String *s)
|
|
2717 {
|
|
2718 return *string_plist_ptr (s);
|
|
2719 }
|
|
2720
|
20
|
2721 DEFUN ("get", Fget, 2, 3, 0, /*
|
0
|
2722 Return the value of OBJECT's PROPNAME property.
|
|
2723 This is the last VALUE stored with `(put OBJECT PROPNAME VALUE)'.
|
|
2724 If there is no such property, return optional third arg DEFAULT
|
|
2725 (which defaults to `nil'). OBJECT can be a symbol, face, extent,
|
|
2726 or string. See also `put', `remprop', and `object-plist'.
|
20
|
2727 */
|
70
|
2728 (object, propname, defalt)) /* Cant spel in C */
|
0
|
2729 {
|
|
2730 Lisp_Object val;
|
|
2731
|
|
2732 /* Various places in emacs call Fget() and expect it not to quit,
|
|
2733 so don't quit. */
|
|
2734
|
|
2735 /* It's easiest to treat symbols specially because they may not
|
|
2736 be an lrecord */
|
|
2737 if (SYMBOLP (object))
|
|
2738 val = symbol_getprop (object, propname, defalt);
|
|
2739 else if (STRINGP (object))
|
|
2740 val = string_getprop (XSTRING (object), propname, defalt);
|
|
2741 else if (LRECORDP (object))
|
|
2742 {
|
|
2743 CONST struct lrecord_implementation
|
|
2744 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2745 if (imp->getprop)
|
|
2746 {
|
|
2747 val = (imp->getprop) (object, propname);
|
|
2748 if (UNBOUNDP (val))
|
|
2749 val = defalt;
|
|
2750 }
|
|
2751 else
|
|
2752 goto noprops;
|
|
2753 }
|
|
2754 else
|
|
2755 {
|
|
2756 noprops:
|
|
2757 signal_simple_error ("Object type has no properties", object);
|
|
2758 }
|
|
2759
|
|
2760 return val;
|
|
2761 }
|
|
2762
|
20
|
2763 DEFUN ("put", Fput, 3, 3, 0, /*
|
0
|
2764 Store OBJECT's PROPNAME property with value VALUE.
|
|
2765 It can be retrieved with `(get OBJECT PROPNAME)'. OBJECT can be a
|
|
2766 symbol, face, extent, or string.
|
|
2767
|
|
2768 For a string, no properties currently have predefined meanings.
|
|
2769 For the predefined properties for extents, see `set-extent-property'.
|
|
2770 For the predefined properties for faces, see `set-face-property'.
|
|
2771
|
|
2772 See also `get', `remprop', and `object-plist'.
|
20
|
2773 */
|
|
2774 (object, propname, value))
|
0
|
2775 {
|
|
2776 CHECK_SYMBOL (propname);
|
|
2777 CHECK_IMPURE (object);
|
|
2778
|
|
2779 if (SYMBOLP (object))
|
|
2780 symbol_putprop (object, propname, value);
|
|
2781 else if (STRINGP (object))
|
|
2782 string_putprop (XSTRING (object), propname, value);
|
|
2783 else if (LRECORDP (object))
|
|
2784 {
|
|
2785 CONST struct lrecord_implementation
|
|
2786 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2787 if (imp->putprop)
|
|
2788 {
|
|
2789 if (! (imp->putprop) (object, propname, value))
|
|
2790 signal_simple_error ("Can't set property on object", propname);
|
|
2791 }
|
|
2792 else
|
|
2793 goto noprops;
|
|
2794 }
|
|
2795 else
|
|
2796 {
|
|
2797 noprops:
|
|
2798 signal_simple_error ("Object type has no settable properties", object);
|
|
2799 }
|
|
2800
|
|
2801 return value;
|
|
2802 }
|
|
2803
|
|
2804 void
|
|
2805 pure_put (Lisp_Object sym, Lisp_Object prop, Lisp_Object val)
|
|
2806 {
|
|
2807 Fput (sym, prop, Fpurecopy (val));
|
|
2808 }
|
|
2809
|
20
|
2810 DEFUN ("remprop", Fremprop, 2, 2, 0, /*
|
0
|
2811 Remove from OBJECT's property list the property PROPNAME and its
|
|
2812 value. OBJECT can be a symbol, face, extent, or string. Returns
|
|
2813 non-nil if the property list was actually changed (i.e. if PROPNAME
|
|
2814 was present in the property list). See also `get', `put', and
|
|
2815 `object-plist'.
|
20
|
2816 */
|
|
2817 (object, propname))
|
0
|
2818 {
|
|
2819 int retval = 0;
|
|
2820
|
|
2821 CHECK_SYMBOL (propname);
|
|
2822 CHECK_IMPURE (object);
|
|
2823
|
|
2824 if (SYMBOLP (object))
|
|
2825 retval = symbol_remprop (object, propname);
|
|
2826 else if (STRINGP (object))
|
|
2827 retval = string_remprop (XSTRING (object), propname);
|
|
2828 else if (LRECORDP (object))
|
|
2829 {
|
|
2830 CONST struct lrecord_implementation
|
|
2831 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2832 if (imp->remprop)
|
|
2833 {
|
|
2834 retval = (imp->remprop) (object, propname);
|
|
2835 if (retval == -1)
|
|
2836 signal_simple_error ("Can't remove property from object",
|
|
2837 propname);
|
|
2838 }
|
|
2839 else
|
|
2840 goto noprops;
|
|
2841 }
|
|
2842 else
|
|
2843 {
|
|
2844 noprops:
|
|
2845 signal_simple_error ("Object type has no removable properties", object);
|
|
2846 }
|
|
2847
|
|
2848 return retval ? Qt : Qnil;
|
|
2849 }
|
|
2850
|
20
|
2851 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /*
|
0
|
2852 Return a property list of OBJECT's props.
|
|
2853 For a symbol this is equivalent to `symbol-plist'.
|
|
2854 Do not modify the property list directly; this may or may not have
|
|
2855 the desired effects. (In particular, for a property with a special
|
|
2856 interpretation, this will probably have no effect at all.)
|
20
|
2857 */
|
|
2858 (object))
|
0
|
2859 {
|
|
2860 if (SYMBOLP (object))
|
|
2861 return Fsymbol_plist (object);
|
|
2862 else if (STRINGP (object))
|
|
2863 return string_plist (XSTRING (object));
|
|
2864 else if (LRECORDP (object))
|
|
2865 {
|
|
2866 CONST struct lrecord_implementation
|
|
2867 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2868 if (imp->plist)
|
|
2869 return (imp->plist) (object);
|
|
2870 else
|
|
2871 signal_simple_error ("Object type has no properties", object);
|
|
2872 }
|
|
2873 else
|
|
2874 signal_simple_error ("Object type has no properties", object);
|
|
2875
|
|
2876 return Qnil;
|
|
2877 }
|
|
2878
|
|
2879
|
|
2880 int
|
|
2881 internal_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2882 {
|
|
2883 if (depth > 200)
|
|
2884 error ("Stack overflow in equal");
|
|
2885 do_cdr:
|
|
2886 QUIT;
|
70
|
2887 if (EQ_WITH_EBOLA_NOTICE (o1, o2))
|
0
|
2888 return (1);
|
|
2889 /* Note that (equal 20 20.0) should be nil */
|
|
2890 else if (XTYPE (o1) != XTYPE (o2))
|
|
2891 return (0);
|
|
2892 else if (CONSP (o1))
|
|
2893 {
|
|
2894 if (!internal_equal (Fcar (o1), Fcar (o2), depth + 1))
|
|
2895 return (0);
|
|
2896 o1 = Fcdr (o1);
|
|
2897 o2 = Fcdr (o2);
|
|
2898 goto do_cdr;
|
|
2899 }
|
|
2900
|
|
2901 #ifndef LRECORD_VECTOR
|
|
2902 else if (VECTORP (o1))
|
|
2903 {
|
|
2904 int indecks;
|
|
2905 int len = vector_length (XVECTOR (o1));
|
|
2906 if (len != vector_length (XVECTOR (o2)))
|
|
2907 return (0);
|
|
2908 for (indecks = 0; indecks < len; indecks++)
|
|
2909 {
|
|
2910 Lisp_Object v1, v2;
|
|
2911 v1 = vector_data (XVECTOR (o1)) [indecks];
|
|
2912 v2 = vector_data (XVECTOR (o2)) [indecks];
|
|
2913 if (!internal_equal (v1, v2, depth + 1))
|
|
2914 return (0);
|
|
2915 }
|
|
2916 return (1);
|
|
2917 }
|
|
2918 #endif /* !LRECORD_VECTOR */
|
|
2919 else if (STRINGP (o1))
|
|
2920 {
|
14
|
2921 Bytecount len = XSTRING_LENGTH (o1);
|
|
2922 if (len != XSTRING_LENGTH (o2))
|
0
|
2923 return (0);
|
14
|
2924 if (memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len))
|
0
|
2925 return (0);
|
|
2926 return (1);
|
|
2927 }
|
|
2928 else if (LRECORDP (o1))
|
|
2929 {
|
|
2930 CONST struct lrecord_implementation
|
|
2931 *imp1 = XRECORD_LHEADER (o1)->implementation,
|
|
2932 *imp2 = XRECORD_LHEADER (o2)->implementation;
|
|
2933 if (imp1 != imp2)
|
|
2934 return (0);
|
|
2935 else if (imp1->equal == 0)
|
|
2936 /* EQ-ness of the objects was noticed above */
|
|
2937 return (0);
|
|
2938 else
|
|
2939 return ((imp1->equal) (o1, o2, depth));
|
|
2940 }
|
|
2941
|
|
2942 return (0);
|
|
2943 }
|
|
2944
|
70
|
2945 /* Note that we may be calling sub-objects that will use
|
|
2946 internal_equal() (instead of internal_old_equal()). Oh well.
|
|
2947 We will get an Ebola note if there's any possibility of confusion,
|
|
2948 but that seems unlikely. */
|
|
2949
|
|
2950 static int
|
|
2951 internal_old_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2952 {
|
|
2953 if (depth > 200)
|
|
2954 error ("Stack overflow in equal");
|
|
2955 do_cdr:
|
|
2956 QUIT;
|
|
2957 if (HACKEQ_UNSAFE (o1, o2))
|
|
2958 return (1);
|
|
2959 /* Note that (equal 20 20.0) should be nil */
|
|
2960 else if (XTYPE (o1) != XTYPE (o2))
|
|
2961 return (0);
|
|
2962 else if (CONSP (o1))
|
|
2963 {
|
|
2964 if (!internal_old_equal (Fcar (o1), Fcar (o2), depth + 1))
|
|
2965 return (0);
|
|
2966 o1 = Fcdr (o1);
|
|
2967 o2 = Fcdr (o2);
|
|
2968 goto do_cdr;
|
|
2969 }
|
|
2970
|
|
2971 #ifndef LRECORD_VECTOR
|
|
2972 else if (VECTORP (o1))
|
|
2973 {
|
|
2974 int indecks;
|
|
2975 int len = vector_length (XVECTOR (o1));
|
|
2976 if (len != vector_length (XVECTOR (o2)))
|
|
2977 return (0);
|
|
2978 for (indecks = 0; indecks < len; indecks++)
|
|
2979 {
|
|
2980 Lisp_Object v1, v2;
|
|
2981 v1 = vector_data (XVECTOR (o1)) [indecks];
|
|
2982 v2 = vector_data (XVECTOR (o2)) [indecks];
|
|
2983 if (!internal_old_equal (v1, v2, depth + 1))
|
|
2984 return (0);
|
|
2985 }
|
|
2986 return (1);
|
|
2987 }
|
|
2988 #endif /* !LRECORD_VECTOR */
|
|
2989 else if (STRINGP (o1))
|
|
2990 {
|
|
2991 Bytecount len = XSTRING_LENGTH (o1);
|
|
2992 if (len != XSTRING_LENGTH (o2))
|
|
2993 return (0);
|
|
2994 if (memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len))
|
|
2995 return (0);
|
|
2996 return (1);
|
|
2997 }
|
|
2998 else if (LRECORDP (o1))
|
|
2999 {
|
|
3000 CONST struct lrecord_implementation
|
|
3001 *imp1 = XRECORD_LHEADER (o1)->implementation,
|
|
3002 *imp2 = XRECORD_LHEADER (o2)->implementation;
|
|
3003 if (imp1 != imp2)
|
|
3004 return (0);
|
|
3005 else if (imp1->equal == 0)
|
|
3006 /* EQ-ness of the objects was noticed above */
|
|
3007 return (0);
|
|
3008 else
|
|
3009 return ((imp1->equal) (o1, o2, depth));
|
|
3010 }
|
|
3011
|
|
3012 return (0);
|
|
3013 }
|
|
3014
|
20
|
3015 DEFUN ("equal", Fequal, 2, 2, 0, /*
|
0
|
3016 T if two Lisp objects have similar structure and contents.
|
|
3017 They must have the same data type.
|
|
3018 Conses are compared by comparing the cars and the cdrs.
|
|
3019 Vectors and strings are compared element by element.
|
|
3020 Numbers are compared by value. Symbols must match exactly.
|
20
|
3021 */
|
|
3022 (o1, o2))
|
0
|
3023 {
|
|
3024 return ((internal_equal (o1, o2, 0)) ? Qt : Qnil);
|
|
3025 }
|
|
3026
|
70
|
3027 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /*
|
|
3028 T if two Lisp objects have similar structure and contents.
|
|
3029 They must have the same data type.
|
|
3030 \(Note, however, that an exception is made for characters and integers;
|
|
3031 this is known as the \"char-int confoundance disease.\" See `eq' and
|
|
3032 `old-eq'.)
|
|
3033 This function is provided only for byte-code compatibility with v19.
|
|
3034 Do not use it.
|
|
3035 */
|
|
3036 (o1, o2))
|
|
3037 {
|
|
3038 return (internal_old_equal (o1, o2, 0) ? Qt : Qnil);
|
|
3039 }
|
|
3040
|
0
|
3041
|
20
|
3042 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /*
|
0
|
3043 Store each element of ARRAY with ITEM.
|
|
3044 ARRAY is a vector, bit vector, or string.
|
20
|
3045 */
|
|
3046 (array, item))
|
0
|
3047 {
|
|
3048 retry:
|
76
|
3049 if (STRINGP (array))
|
|
3050 {
|
|
3051 Charcount size;
|
|
3052 Charcount i;
|
|
3053 Emchar charval;
|
|
3054 struct Lisp_String *s;
|
|
3055 CHECK_CHAR_COERCE_INT (item);
|
|
3056 CHECK_IMPURE (array);
|
|
3057 charval = XCHAR (item);
|
|
3058 s = XSTRING (array);
|
|
3059 size = string_char_length (s);
|
|
3060 for (i = 0; i < size; i++)
|
|
3061 set_string_char (s, i, charval);
|
|
3062 bump_string_modiff (array);
|
|
3063 }
|
|
3064 else if (VECTORP (array))
|
10
|
3065 {
|
70
|
3066 Lisp_Object *p;
|
|
3067 int size;
|
76
|
3068 int i;
|
10
|
3069 CHECK_IMPURE (array);
|
70
|
3070 size = vector_length (XVECTOR (array));
|
|
3071 p = vector_data (XVECTOR (array));
|
76
|
3072 for (i = 0; i < size; i++)
|
|
3073 p[i] = item;
|
10
|
3074 }
|
76
|
3075 else if (BIT_VECTORP (array))
|
0
|
3076 {
|
|
3077 struct Lisp_Bit_Vector *v;
|
|
3078 int size;
|
76
|
3079 int i;
|
0
|
3080 CHECK_BIT (item);
|
|
3081 CHECK_IMPURE (array);
|
|
3082 v = XBIT_VECTOR (array);
|
|
3083 size = bit_vector_length (v);
|
76
|
3084 for (i = 0; i < size; i++)
|
|
3085 set_bit_vector_bit (v, i, XINT (item));
|
0
|
3086 }
|
|
3087 else
|
|
3088 {
|
|
3089 array = wrong_type_argument (Qarrayp, array);
|
|
3090 goto retry;
|
|
3091 }
|
|
3092 return array;
|
|
3093 }
|
|
3094
|
|
3095 Lisp_Object
|
|
3096 nconc2 (Lisp_Object s1, Lisp_Object s2)
|
|
3097 {
|
|
3098 Lisp_Object args[2];
|
|
3099 args[0] = s1;
|
|
3100 args[1] = s2;
|
|
3101 return Fnconc (2, args);
|
|
3102 }
|
|
3103
|
20
|
3104 DEFUN ("nconc", Fnconc, 0, MANY, 0, /*
|
0
|
3105 Concatenate any number of lists by altering them.
|
|
3106 Only the last argument is not altered, and need not be a list.
|
20
|
3107 */
|
|
3108 (int nargs, Lisp_Object *args))
|
0
|
3109 {
|
|
3110 int argnum;
|
|
3111 Lisp_Object tail, tem, val;
|
|
3112 struct gcpro gcpro1;
|
|
3113
|
|
3114 /* The modus operandi in Emacs is "caller gc-protects args".
|
|
3115 However, nconc (particularly nconc2 ()) is called many times
|
|
3116 in Emacs on freshly created stuff (e.g. you see the idiom
|
|
3117 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those
|
|
3118 callers out by protecting the args ourselves to save them
|
|
3119 a lot of temporary-variable grief. */
|
|
3120
|
|
3121 GCPRO1 (args[0]);
|
|
3122 gcpro1.nvars = nargs;
|
|
3123
|
|
3124 val = Qnil;
|
|
3125
|
|
3126 for (argnum = 0; argnum < nargs; argnum++)
|
|
3127 {
|
|
3128 tem = args[argnum];
|
|
3129 if (NILP (tem)) continue;
|
|
3130
|
|
3131 if (NILP (val))
|
|
3132 val = tem;
|
|
3133
|
|
3134 if (argnum + 1 == nargs) break;
|
|
3135
|
|
3136 if (!CONSP (tem))
|
|
3137 tem = wrong_type_argument (Qlistp, tem);
|
|
3138
|
|
3139 while (CONSP (tem))
|
|
3140 {
|
|
3141 tail = tem;
|
|
3142 tem = Fcdr (tail);
|
|
3143 QUIT;
|
|
3144 }
|
|
3145
|
|
3146 tem = args[argnum + 1];
|
|
3147 Fsetcdr (tail, tem);
|
|
3148 if (NILP (tem))
|
|
3149 args[argnum + 1] = tail;
|
|
3150 }
|
|
3151
|
|
3152 RETURN_UNGCPRO (val);
|
|
3153 }
|
|
3154
|
|
3155
|
|
3156 /* This is the guts of all mapping functions.
|
|
3157 Apply fn to each element of seq, one by one,
|
|
3158 storing the results into elements of vals, a C vector of Lisp_Objects.
|
|
3159 leni is the length of vals, which should also be the length of seq.
|
|
3160
|
|
3161 If VALS is a null pointer, do not accumulate the results. */
|
|
3162
|
|
3163 static void
|
|
3164 mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
|
|
3165 {
|
|
3166 Lisp_Object tail;
|
|
3167 Lisp_Object dummy = Qnil;
|
|
3168 int i;
|
|
3169 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3170 Lisp_Object result;
|
|
3171
|
|
3172 GCPRO3 (dummy, fn, seq);
|
|
3173
|
|
3174 if (vals)
|
|
3175 {
|
|
3176 /* Don't let vals contain any garbage when GC happens. */
|
|
3177 for (i = 0; i < leni; i++)
|
|
3178 vals[i] = Qnil;
|
|
3179 gcpro1.var = vals;
|
|
3180 gcpro1.nvars = leni;
|
|
3181 }
|
|
3182
|
|
3183 /* We need not explicitly protect `tail' because it is used only on
|
|
3184 lists, and 1) lists are not relocated and 2) the list is marked
|
|
3185 via `seq' so will not be freed */
|
|
3186
|
|
3187 if (VECTORP (seq))
|
|
3188 {
|
|
3189 for (i = 0; i < leni; i++)
|
|
3190 {
|
|
3191 dummy = vector_data (XVECTOR (seq))[i];
|
|
3192 result = call1 (fn, dummy);
|
|
3193 if (vals)
|
|
3194 vals[i] = result;
|
|
3195 }
|
|
3196 }
|
|
3197 else if (BIT_VECTORP (seq))
|
|
3198 {
|
|
3199 struct Lisp_Bit_Vector *v = XBIT_VECTOR (seq);
|
|
3200 for (i = 0; i < leni; i++)
|
|
3201 {
|
|
3202 XSETINT (dummy, bit_vector_bit (v, i));
|
|
3203 result = call1 (fn, dummy);
|
|
3204 if (vals)
|
|
3205 vals[i] = result;
|
|
3206 }
|
|
3207 }
|
|
3208 else if (STRINGP (seq))
|
|
3209 {
|
|
3210 for (i = 0; i < leni; i++)
|
|
3211 {
|
|
3212 result = call1 (fn, make_char (string_char (XSTRING (seq), i)));
|
|
3213 if (vals)
|
|
3214 vals[i] = result;
|
|
3215 }
|
|
3216 }
|
|
3217 else /* Must be a list, since Flength did not get an error */
|
|
3218 {
|
|
3219 tail = seq;
|
|
3220 for (i = 0; i < leni; i++)
|
|
3221 {
|
|
3222 result = call1 (fn, Fcar (tail));
|
|
3223 if (vals)
|
|
3224 vals[i] = result;
|
|
3225 tail = Fcdr (tail);
|
|
3226 }
|
|
3227 }
|
|
3228
|
|
3229 UNGCPRO;
|
|
3230 }
|
|
3231
|
20
|
3232 DEFUN ("mapconcat", Fmapconcat, 3, 3, 0, /*
|
0
|
3233 Apply FN to each element of SEQ, and concat the results as strings.
|
|
3234 In between each pair of results, stick in SEP.
|
|
3235 Thus, \" \" as SEP results in spaces between the values returned by FN.
|
20
|
3236 */
|
|
3237 (fn, seq, sep))
|
0
|
3238 {
|
16
|
3239 int len = XINT (Flength (seq));
|
0
|
3240 int nargs;
|
|
3241 Lisp_Object *args;
|
|
3242 int i;
|
|
3243 struct gcpro gcpro1;
|
|
3244
|
16
|
3245 nargs = len + len - 1;
|
0
|
3246 if (nargs < 0) return build_string ("");
|
|
3247
|
|
3248 args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
|
|
3249
|
|
3250 GCPRO1 (sep);
|
16
|
3251 mapcar1 (len, args, fn, seq);
|
0
|
3252 UNGCPRO;
|
|
3253
|
16
|
3254 for (i = len - 1; i >= 0; i--)
|
0
|
3255 args[i + i] = args[i];
|
|
3256
|
|
3257 for (i = 1; i < nargs; i += 2)
|
|
3258 args[i] = sep;
|
|
3259
|
|
3260 return Fconcat (nargs, args);
|
|
3261 }
|
|
3262
|
20
|
3263 DEFUN ("mapcar", Fmapcar, 2, 2, 0, /*
|
0
|
3264 Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
|
|
3265 The result is a list just as long as SEQUENCE.
|
|
3266 SEQUENCE may be a list, a vector, a bit vector, or a string.
|
20
|
3267 */
|
|
3268 (fn, seq))
|
0
|
3269 {
|
16
|
3270 int len = XINT (Flength (seq));
|
|
3271 Lisp_Object *args = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
|
|
3272
|
|
3273 mapcar1 (len, args, fn, seq);
|
|
3274
|
|
3275 return Flist (len, args);
|
0
|
3276 }
|
|
3277
|
20
|
3278 DEFUN ("mapc-internal", Fmapc_internal, 2, 2, 0, /*
|
0
|
3279 Apply FUNCTION to each element of SEQUENCE.
|
|
3280 SEQUENCE may be a list, a vector, a bit vector, or a string.
|
|
3281 This function is like `mapcar' but does not accumulate the results,
|
|
3282 which is more efficient if you do not use the results.
|
20
|
3283 */
|
|
3284 (fn, seq))
|
0
|
3285 {
|
16
|
3286 mapcar1 (XINT (Flength (seq)), 0, fn, seq);
|
0
|
3287
|
|
3288 return Qnil;
|
|
3289 }
|
|
3290
|
|
3291
|
|
3292 /* #### this function doesn't belong in this file! */
|
|
3293
|
20
|
3294 DEFUN ("load-average", Fload_average, 0, 0, 0, /*
|
0
|
3295 Return list of 1 minute, 5 minute and 15 minute load averages.
|
|
3296 Each of the three load averages is multiplied by 100,
|
|
3297 then converted to integer.
|
|
3298
|
|
3299 If the 5-minute or 15-minute load averages are not available, return a
|
|
3300 shortened list, containing only those averages which are available.
|
|
3301
|
118
|
3302 On some systems, this won't work due to permissions on /dev/kmem in
|
|
3303 which case you can't use this.
|
20
|
3304 */
|
|
3305 ())
|
0
|
3306 {
|
|
3307 double load_ave[10]; /* hey, just in case */
|
|
3308 int loads = getloadavg (load_ave, 3);
|
|
3309 Lisp_Object ret;
|
|
3310
|
|
3311 if (loads == -2)
|
|
3312 error ("load-average not implemented for this operating system.");
|
|
3313 else if (loads < 0)
|
|
3314 error ("could not get load-average; check permissions.");
|
|
3315
|
|
3316 ret = Qnil;
|
|
3317 while (loads > 0)
|
|
3318 ret = Fcons (make_int ((int) (load_ave[--loads] * 100.0)), ret);
|
|
3319
|
|
3320 return ret;
|
|
3321 }
|
|
3322
|
|
3323
|
|
3324 Lisp_Object Vfeatures;
|
|
3325
|
140
|
3326 #ifndef FEATUREP_SYNTAX
|
20
|
3327 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /*
|
70
|
3328 Return t if FEATURE is present in this Emacs.
|
|
3329 Use this to conditionalize execution of lisp code based on the
|
|
3330 presence or absence of emacs or environment extensions.
|
|
3331 Use `provide' to declare that a feature is available.
|
|
3332 This function looks at the value of the variable `features'.
|
20
|
3333 */
|
70
|
3334 (feature))
|
0
|
3335 {
|
70
|
3336 CHECK_SYMBOL (feature);
|
|
3337 return NILP (Fmemq (feature, Vfeatures)) ? Qnil : Qt;
|
0
|
3338 }
|
140
|
3339 #endif
|
0
|
3340
|
20
|
3341 DEFUN ("provide", Fprovide, 1, 1, 0, /*
|
0
|
3342 Announce that FEATURE is a feature of the current Emacs.
|
2
|
3343 This function updates the value of the variable `features'.
|
20
|
3344 */
|
|
3345 (feature))
|
0
|
3346 {
|
|
3347 Lisp_Object tem;
|
|
3348 CHECK_SYMBOL (feature);
|
|
3349 if (!NILP (Vautoload_queue))
|
|
3350 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
|
|
3351 tem = Fmemq (feature, Vfeatures);
|
|
3352 if (NILP (tem))
|
|
3353 Vfeatures = Fcons (feature, Vfeatures);
|
|
3354 LOADHIST_ATTACH (Fcons (Qprovide, feature));
|
|
3355 return feature;
|
|
3356 }
|
|
3357
|
20
|
3358 DEFUN ("require", Frequire, 1, 2, 0, /*
|
0
|
3359 If feature FEATURE is not loaded, load it from FILENAME.
|
|
3360 If FEATURE is not a member of the list `features', then the feature
|
|
3361 is not loaded; so load the file FILENAME.
|
|
3362 If FILENAME is omitted, the printname of FEATURE is used as the file name.
|
20
|
3363 */
|
|
3364 (feature, file_name))
|
0
|
3365 {
|
|
3366 Lisp_Object tem;
|
|
3367 CHECK_SYMBOL (feature);
|
|
3368 tem = Fmemq (feature, Vfeatures);
|
|
3369 LOADHIST_ATTACH (Fcons (Qrequire, feature));
|
|
3370 if (!NILP (tem))
|
|
3371 return (feature);
|
|
3372 else
|
|
3373 {
|
|
3374 int speccount = specpdl_depth ();
|
|
3375
|
|
3376 /* Value saved here is to be restored into Vautoload_queue */
|
|
3377 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
3378 Vautoload_queue = Qt;
|
|
3379
|
|
3380 call4 (Qload, NILP (file_name) ? Fsymbol_name (feature) : file_name,
|
|
3381 Qnil, Qt, Qnil);
|
|
3382
|
|
3383 tem = Fmemq (feature, Vfeatures);
|
|
3384 if (NILP (tem))
|
|
3385 error ("Required feature %s was not provided",
|
|
3386 string_data (XSYMBOL (feature)->name));
|
|
3387
|
|
3388 /* Once loading finishes, don't undo it. */
|
|
3389 Vautoload_queue = Qt;
|
|
3390 return (unbind_to (speccount, feature));
|
|
3391 }
|
|
3392 }
|
|
3393
|
|
3394
|
|
3395 Lisp_Object Qyes_or_no_p;
|
|
3396
|
|
3397 void
|
|
3398 syms_of_fns (void)
|
|
3399 {
|
|
3400 defsymbol (&Qstring_lessp, "string-lessp");
|
|
3401 defsymbol (&Qidentity, "identity");
|
|
3402 defsymbol (&Qyes_or_no_p, "yes-or-no-p");
|
|
3403
|
20
|
3404 DEFSUBR (Fidentity);
|
|
3405 DEFSUBR (Frandom);
|
|
3406 DEFSUBR (Flength);
|
|
3407 DEFSUBR (Fsafe_length);
|
|
3408 DEFSUBR (Fstring_equal);
|
|
3409 DEFSUBR (Fstring_lessp);
|
|
3410 DEFSUBR (Fstring_modified_tick);
|
|
3411 DEFSUBR (Fappend);
|
|
3412 DEFSUBR (Fconcat);
|
|
3413 DEFSUBR (Fvconcat);
|
|
3414 DEFSUBR (Fbvconcat);
|
|
3415 DEFSUBR (Fcopy_sequence);
|
|
3416 DEFSUBR (Fcopy_alist);
|
|
3417 DEFSUBR (Fcopy_tree);
|
|
3418 DEFSUBR (Fsubstring);
|
|
3419 DEFSUBR (Fsubseq);
|
|
3420 DEFSUBR (Fnthcdr);
|
|
3421 DEFSUBR (Fnth);
|
|
3422 DEFSUBR (Felt);
|
|
3423 DEFSUBR (Fmember);
|
70
|
3424 DEFSUBR (Fold_member);
|
20
|
3425 DEFSUBR (Fmemq);
|
70
|
3426 DEFSUBR (Fold_memq);
|
20
|
3427 DEFSUBR (Fassoc);
|
70
|
3428 DEFSUBR (Fold_assoc);
|
20
|
3429 DEFSUBR (Fassq);
|
70
|
3430 DEFSUBR (Fold_assq);
|
20
|
3431 DEFSUBR (Frassoc);
|
70
|
3432 DEFSUBR (Fold_rassoc);
|
20
|
3433 DEFSUBR (Frassq);
|
70
|
3434 DEFSUBR (Fold_rassq);
|
20
|
3435 DEFSUBR (Fdelete);
|
70
|
3436 DEFSUBR (Fold_delete);
|
20
|
3437 DEFSUBR (Fdelq);
|
70
|
3438 DEFSUBR (Fold_delq);
|
20
|
3439 DEFSUBR (Fremassoc);
|
|
3440 DEFSUBR (Fremassq);
|
|
3441 DEFSUBR (Fremrassoc);
|
|
3442 DEFSUBR (Fremrassq);
|
|
3443 DEFSUBR (Fnreverse);
|
|
3444 DEFSUBR (Freverse);
|
|
3445 DEFSUBR (Fsort);
|
|
3446 DEFSUBR (Fplists_eq);
|
|
3447 DEFSUBR (Fplists_equal);
|
|
3448 DEFSUBR (Flax_plists_eq);
|
|
3449 DEFSUBR (Flax_plists_equal);
|
|
3450 DEFSUBR (Fplist_get);
|
|
3451 DEFSUBR (Fplist_put);
|
|
3452 DEFSUBR (Fplist_remprop);
|
|
3453 DEFSUBR (Fplist_member);
|
|
3454 DEFSUBR (Fcheck_valid_plist);
|
|
3455 DEFSUBR (Fvalid_plist_p);
|
|
3456 DEFSUBR (Fcanonicalize_plist);
|
|
3457 DEFSUBR (Flax_plist_get);
|
|
3458 DEFSUBR (Flax_plist_put);
|
|
3459 DEFSUBR (Flax_plist_remprop);
|
|
3460 DEFSUBR (Flax_plist_member);
|
|
3461 DEFSUBR (Fcanonicalize_lax_plist);
|
|
3462 DEFSUBR (Fdestructive_alist_to_plist);
|
|
3463 DEFSUBR (Fget);
|
|
3464 DEFSUBR (Fput);
|
|
3465 DEFSUBR (Fremprop);
|
|
3466 DEFSUBR (Fobject_plist);
|
|
3467 DEFSUBR (Fequal);
|
70
|
3468 DEFSUBR (Fold_equal);
|
20
|
3469 DEFSUBR (Ffillarray);
|
|
3470 DEFSUBR (Fnconc);
|
|
3471 DEFSUBR (Fmapcar);
|
|
3472 DEFSUBR (Fmapc_internal);
|
|
3473 DEFSUBR (Fmapconcat);
|
|
3474 DEFSUBR (Fload_average);
|
140
|
3475 #ifndef FEATUREP_SYNTAX
|
20
|
3476 DEFSUBR (Ffeaturep);
|
140
|
3477 #endif
|
20
|
3478 DEFSUBR (Frequire);
|
|
3479 DEFSUBR (Fprovide);
|
0
|
3480 }
|
|
3481
|
|
3482 void
|
|
3483 init_provide_once (void)
|
|
3484 {
|
|
3485 DEFVAR_LISP ("features", &Vfeatures /*
|
|
3486 A list of symbols which are the features of the executing emacs.
|
|
3487 Used by `featurep' and `require', and altered by `provide'.
|
|
3488 */ );
|
|
3489 Vfeatures = Qnil;
|
|
3490 }
|