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