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