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);
|
173
|
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))
|
173
|
211 return make_int (XVECTOR_LENGTH (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
|
173
|
222 return make_int (i);
|
0
|
223 }
|
|
224 else if (NILP (obj))
|
|
225 {
|
173
|
226 return Qzero;
|
0
|
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 */
|
173
|
372 return end < len2 ? Qt : Qnil;
|
0
|
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)
|
185
|
576 args_mse = alloca_array (struct merge_string_extents_struct, nargs);
|
0
|
577
|
|
578 /* In append, the last arg isn't treated like the others */
|
|
579 if (last_special && nargs > 0)
|
|
580 {
|
|
581 nargs--;
|
|
582 last_tail = args[nargs];
|
|
583 }
|
|
584 else
|
|
585 last_tail = Qnil;
|
|
586
|
|
587 /* Check and coerce the arguments. */
|
|
588 for (argnum = 0; argnum < nargs; argnum++)
|
|
589 {
|
|
590 Lisp_Object seq = args[argnum];
|
|
591 if (CONSP (seq) || NILP (seq))
|
|
592 ;
|
|
593 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq))
|
|
594 ;
|
|
595 #ifdef LOSING_BYTECODE
|
|
596 else if (COMPILED_FUNCTIONP (seq))
|
|
597 /* Urk! We allow this, for "compatibility"... */
|
|
598 ;
|
|
599 #endif
|
|
600 else if (INTP (seq))
|
|
601 /* This is too revolting to think about but maintains
|
|
602 compatibility with FSF (and lots and lots of old code). */
|
|
603 args[argnum] = Fnumber_to_string (seq);
|
|
604 else
|
|
605 {
|
|
606 check_losing_bytecode ("concat", seq);
|
|
607 args[argnum] = wrong_type_argument (Qsequencep, seq);
|
|
608 }
|
173
|
609
|
0
|
610 if (args_mse)
|
|
611 {
|
|
612 if (STRINGP (seq))
|
|
613 args_mse[argnum].string = seq;
|
|
614 else
|
|
615 args_mse[argnum].string = Qnil;
|
|
616 }
|
|
617 }
|
|
618
|
|
619 {
|
|
620 /* Charcount is a misnomer here as we might be dealing with the
|
|
621 length of a vector or list, but emphasizes that we're not dealing
|
|
622 with Bytecounts in strings */
|
|
623 Charcount total_length;
|
|
624
|
|
625 for (argnum = 0, total_length = 0; argnum < nargs; argnum++)
|
|
626 {
|
|
627 #ifdef LOSING_BYTECODE
|
|
628 Charcount thislen = length_with_bytecode_hack (args[argnum]);
|
|
629 #else
|
|
630 Charcount thislen = XINT (Flength (args[argnum]));
|
|
631 #endif
|
|
632 total_length += thislen;
|
|
633 }
|
|
634
|
|
635 switch (target_type)
|
|
636 {
|
|
637 case c_cons:
|
|
638 if (total_length == 0)
|
|
639 /* In append, if all but last arg are nil, return last arg */
|
|
640 RETURN_UNGCPRO (last_tail);
|
|
641 val = Fmake_list (make_int (total_length), Qnil);
|
|
642 break;
|
|
643 case c_vector:
|
|
644 val = make_vector (total_length, Qnil);
|
|
645 break;
|
|
646 case c_bit_vector:
|
|
647 val = make_bit_vector (total_length, Qzero);
|
|
648 break;
|
|
649 case c_string:
|
|
650 /* We don't make the string yet because we don't know the
|
|
651 actual number of bytes. This loop was formerly written
|
|
652 to call Fmake_string() here and then call set_string_char()
|
|
653 for each char. This seems logical enough but is waaaaaaaay
|
|
654 slow -- set_string_char() has to scan the whole string up
|
|
655 to the place where the substitution is called for in order
|
|
656 to find the place to change, and may have to do some
|
|
657 realloc()ing in order to make the char fit properly.
|
|
658 O(N^2) yuckage. */
|
|
659 val = Qnil;
|
|
660 string_result = (Bufbyte *) alloca (total_length * MAX_EMCHAR_LEN);
|
|
661 string_result_ptr = string_result;
|
|
662 break;
|
|
663 default:
|
|
664 abort ();
|
|
665 }
|
|
666 }
|
|
667
|
|
668
|
|
669 if (CONSP (val))
|
|
670 tail = val, toindex = -1; /* -1 in toindex is flag we are
|
|
671 making a list */
|
|
672 else
|
|
673 toindex = 0;
|
|
674
|
|
675 prev = Qnil;
|
|
676
|
|
677 for (argnum = 0; argnum < nargs; argnum++)
|
|
678 {
|
|
679 Charcount thisleni = 0;
|
|
680 Charcount thisindex = 0;
|
|
681 Lisp_Object seq = args[argnum];
|
|
682 Bufbyte *string_source_ptr = 0;
|
|
683 Bufbyte *string_prev_result_ptr = string_result_ptr;
|
|
684
|
|
685 if (!CONSP (seq))
|
|
686 {
|
|
687 #ifdef LOSING_BYTECODE
|
|
688 thisleni = length_with_bytecode_hack (seq);
|
|
689 #else
|
|
690 thisleni = XINT (Flength (seq));
|
|
691 #endif
|
|
692 }
|
|
693 if (STRINGP (seq))
|
14
|
694 string_source_ptr = XSTRING_DATA (seq);
|
0
|
695
|
|
696 while (1)
|
|
697 {
|
|
698 Lisp_Object elt;
|
|
699
|
|
700 /* We've come to the end of this arg, so exit. */
|
|
701 if (NILP (seq))
|
|
702 break;
|
|
703
|
|
704 /* Fetch next element of `seq' arg into `elt' */
|
|
705 if (CONSP (seq))
|
|
706 {
|
165
|
707 elt = XCAR (seq);
|
|
708 seq = XCDR (seq);
|
0
|
709 }
|
|
710 else
|
|
711 {
|
|
712 if (thisindex >= thisleni)
|
|
713 break;
|
|
714
|
|
715 if (STRINGP (seq))
|
|
716 {
|
|
717 elt = make_char (charptr_emchar (string_source_ptr));
|
|
718 INC_CHARPTR (string_source_ptr);
|
|
719 }
|
|
720 else if (VECTORP (seq))
|
173
|
721 elt = XVECTOR_DATA (seq)[thisindex];
|
0
|
722 else if (BIT_VECTORP (seq))
|
|
723 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq),
|
|
724 thisindex));
|
|
725 else
|
|
726 elt = Felt (seq, make_int (thisindex));
|
|
727 thisindex++;
|
|
728 }
|
|
729
|
|
730 /* Store into result */
|
|
731 if (toindex < 0)
|
|
732 {
|
|
733 /* toindex negative means we are making a list */
|
|
734 XCAR (tail) = elt;
|
|
735 prev = tail;
|
|
736 tail = XCDR (tail);
|
|
737 }
|
|
738 else if (VECTORP (val))
|
173
|
739 XVECTOR_DATA (val)[toindex++] = elt;
|
0
|
740 else if (BIT_VECTORP (val))
|
|
741 {
|
|
742 CHECK_BIT (elt);
|
|
743 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt));
|
|
744 }
|
|
745 else
|
|
746 {
|
|
747 CHECK_CHAR_COERCE_INT (elt);
|
|
748 string_result_ptr += set_charptr_emchar (string_result_ptr,
|
|
749 XCHAR (elt));
|
|
750 }
|
|
751 }
|
|
752 if (args_mse)
|
|
753 {
|
|
754 args_mse[argnum].entry_offset =
|
|
755 string_prev_result_ptr - string_result;
|
|
756 args_mse[argnum].entry_length =
|
|
757 string_result_ptr - string_prev_result_ptr;
|
|
758 }
|
|
759 }
|
|
760
|
|
761 /* Now we finally make the string. */
|
|
762 if (target_type == c_string)
|
|
763 {
|
|
764 val = make_string (string_result, string_result_ptr - string_result);
|
|
765 for (argnum = 0; argnum < nargs; argnum++)
|
|
766 {
|
|
767 if (STRINGP (args_mse[argnum].string))
|
|
768 copy_string_extents (val, args_mse[argnum].string,
|
|
769 args_mse[argnum].entry_offset, 0,
|
|
770 args_mse[argnum].entry_length);
|
|
771 }
|
|
772 }
|
|
773
|
|
774 if (!NILP (prev))
|
|
775 XCDR (prev) = last_tail;
|
|
776
|
173
|
777 RETURN_UNGCPRO (val);
|
0
|
778 }
|
|
779
|
20
|
780 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /*
|
0
|
781 Return a copy of ALIST.
|
|
782 This is an alist which represents the same mapping from objects to objects,
|
|
783 but does not share the alist structure with ALIST.
|
|
784 The objects mapped (cars and cdrs of elements of the alist)
|
|
785 are shared, however.
|
|
786 Elements of ALIST that are not conses are also shared.
|
20
|
787 */
|
|
788 (alist))
|
0
|
789 {
|
|
790 Lisp_Object tem;
|
|
791
|
|
792 CHECK_LIST (alist);
|
|
793 if (NILP (alist))
|
|
794 return alist;
|
|
795 alist = concat (1, &alist, c_cons, 0);
|
|
796 for (tem = alist; CONSP (tem); tem = XCDR (tem))
|
|
797 {
|
|
798 Lisp_Object car;
|
|
799 car = XCAR (tem);
|
|
800
|
|
801 if (CONSP (car))
|
|
802 XCAR (tem) = Fcons (XCAR (car), XCDR (car));
|
|
803 }
|
|
804 return alist;
|
|
805 }
|
|
806
|
20
|
807 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /*
|
0
|
808 Return a copy of a list and substructures.
|
|
809 The argument is copied, and any lists contained within it are copied
|
|
810 recursively. Circularities and shared substructures are not preserved.
|
|
811 Second arg VECP causes vectors to be copied, too. Strings and bit vectors
|
|
812 are not copied.
|
20
|
813 */
|
|
814 (arg, vecp))
|
0
|
815 {
|
|
816 if (CONSP (arg))
|
|
817 {
|
|
818 Lisp_Object rest;
|
|
819 rest = arg = Fcopy_sequence (arg);
|
|
820 while (CONSP (rest))
|
|
821 {
|
|
822 Lisp_Object elt = XCAR (rest);
|
|
823 QUIT;
|
|
824 if (CONSP (elt) || VECTORP (elt))
|
|
825 XCAR (rest) = Fcopy_tree (elt, vecp);
|
|
826 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */
|
|
827 XCDR (rest) = Fcopy_tree (XCDR (rest), vecp);
|
|
828 rest = XCDR (rest);
|
|
829 }
|
|
830 }
|
|
831 else if (VECTORP (arg) && ! NILP (vecp))
|
|
832 {
|
173
|
833 int i = XVECTOR_LENGTH (arg);
|
0
|
834 int j;
|
|
835 arg = Fcopy_sequence (arg);
|
|
836 for (j = 0; j < i; j++)
|
|
837 {
|
173
|
838 Lisp_Object elt = XVECTOR_DATA (arg) [j];
|
0
|
839 QUIT;
|
|
840 if (CONSP (elt) || VECTORP (elt))
|
173
|
841 XVECTOR_DATA (arg) [j] = Fcopy_tree (elt, vecp);
|
0
|
842 }
|
|
843 }
|
|
844 return arg;
|
|
845 }
|
|
846
|
20
|
847 DEFUN ("substring", Fsubstring, 2, 3, 0, /*
|
0
|
848 Return a substring of STRING, starting at index FROM and ending before TO.
|
|
849 TO may be nil or omitted; then the substring runs to the end of STRING.
|
|
850 If FROM or TO is negative, it counts from the end.
|
|
851 Relevant parts of the string-extent-data are copied in the new string.
|
20
|
852 */
|
|
853 (string, from, to))
|
0
|
854 {
|
|
855 Charcount ccfr, ccto;
|
|
856 Bytecount bfr, bto;
|
|
857 Lisp_Object val;
|
|
858
|
|
859 CHECK_STRING (string);
|
|
860 /* Historically, FROM could not be omitted. Whatever ... */
|
|
861 CHECK_INT (from);
|
|
862 get_string_range_char (string, from, to, &ccfr, &ccto,
|
|
863 GB_HISTORICAL_STRING_BEHAVIOR);
|
14
|
864 bfr = charcount_to_bytecount (XSTRING_DATA (string), ccfr);
|
|
865 bto = charcount_to_bytecount (XSTRING_DATA (string), ccto);
|
|
866 val = make_string (XSTRING_DATA (string) + bfr, bto - bfr);
|
0
|
867 /* Copy any applicable extent information into the new string: */
|
|
868 copy_string_extents (val, string, 0, bfr, bto - bfr);
|
173
|
869 return val;
|
0
|
870 }
|
|
871
|
20
|
872 DEFUN ("subseq", Fsubseq, 2, 3, 0, /*
|
0
|
873 Return a subsequence of SEQ, starting at index FROM and ending before TO.
|
|
874 TO may be nil or omitted; then the subsequence runs to the end of SEQ.
|
|
875 If FROM or TO is negative, it counts from the end.
|
|
876 The resulting subsequence is always the same type as the original
|
|
877 sequence.
|
|
878 If SEQ is a string, relevant parts of the string-extent-data are copied
|
|
879 in the new string.
|
20
|
880 */
|
|
881 (seq, from, to))
|
0
|
882 {
|
|
883 int len, f, t;
|
|
884
|
|
885 if (STRINGP (seq))
|
|
886 return Fsubstring (seq, from, to);
|
|
887
|
|
888 if (CONSP (seq) || NILP (seq))
|
|
889 ;
|
|
890 else if (VECTORP (seq) || BIT_VECTORP (seq))
|
|
891 ;
|
|
892 else
|
|
893 {
|
|
894 check_losing_bytecode ("subseq", seq);
|
|
895 seq = wrong_type_argument (Qsequencep, seq);
|
|
896 }
|
173
|
897
|
0
|
898 len = XINT (Flength (seq));
|
|
899 CHECK_INT (from);
|
|
900 f = XINT (from);
|
|
901 if (f < 0)
|
|
902 f = len + f;
|
|
903 if (NILP (to))
|
|
904 t = len;
|
|
905 else
|
|
906 {
|
|
907 CHECK_INT (to);
|
|
908 t = XINT (to);
|
|
909 if (t < 0)
|
|
910 t = len + t;
|
|
911 }
|
173
|
912
|
0
|
913 if (!(0 <= f && f <= t && t <= len))
|
|
914 args_out_of_range_3 (seq, make_int (f), make_int (t));
|
|
915
|
|
916 if (VECTORP (seq))
|
|
917 {
|
|
918 Lisp_Object result = make_vector (t - f, Qnil);
|
|
919 int i;
|
173
|
920 Lisp_Object *in_elts = XVECTOR_DATA (seq);
|
|
921 Lisp_Object *out_elts = XVECTOR_DATA (result);
|
0
|
922
|
|
923 for (i = f; i < t; i++)
|
|
924 out_elts[i - f] = in_elts[i];
|
|
925 return result;
|
|
926 }
|
|
927
|
|
928 if (CONSP (seq))
|
|
929 {
|
|
930 Lisp_Object result = Qnil;
|
|
931 int i;
|
|
932
|
|
933 seq = Fnthcdr (make_int (f), seq);
|
|
934
|
|
935 for (i = f; i < t; i++)
|
|
936 {
|
|
937 result = Fcons (Fcar (seq), result);
|
|
938 seq = Fcdr (seq);
|
|
939 }
|
|
940
|
|
941 return Fnreverse (result);
|
|
942 }
|
|
943
|
|
944 /* bit vector */
|
|
945 {
|
|
946 Lisp_Object result = make_bit_vector (t - f, Qzero);
|
|
947 int i;
|
|
948
|
|
949 for (i = f; i < t; i++)
|
|
950 set_bit_vector_bit (XBIT_VECTOR (result), i - f,
|
|
951 bit_vector_bit (XBIT_VECTOR (seq), i));
|
|
952 return result;
|
|
953 }
|
|
954 }
|
|
955
|
|
956
|
20
|
957 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /*
|
0
|
958 Take cdr N times on LIST, returns the result.
|
20
|
959 */
|
|
960 (n, list))
|
0
|
961 {
|
|
962 REGISTER int i, num;
|
|
963 CHECK_INT (n);
|
|
964 num = XINT (n);
|
|
965 for (i = 0; i < num && !NILP (list); i++)
|
|
966 {
|
|
967 QUIT;
|
|
968 list = Fcdr (list);
|
|
969 }
|
|
970 return list;
|
|
971 }
|
|
972
|
20
|
973 DEFUN ("nth", Fnth, 2, 2, 0, /*
|
0
|
974 Return the Nth element of LIST.
|
|
975 N counts from zero. If LIST is not that long, nil is returned.
|
20
|
976 */
|
|
977 (n, list))
|
0
|
978 {
|
|
979 return Fcar (Fnthcdr (n, list));
|
|
980 }
|
|
981
|
20
|
982 DEFUN ("elt", Felt, 2, 2, 0, /*
|
0
|
983 Return element of SEQUENCE at index N.
|
20
|
984 */
|
|
985 (seq, n))
|
0
|
986 {
|
|
987 retry:
|
|
988 CHECK_INT_COERCE_CHAR (n); /* yuck! */
|
|
989 if (CONSP (seq) || NILP (seq))
|
|
990 {
|
|
991 Lisp_Object tem = Fnthcdr (n, seq);
|
|
992 /* #### Utterly, completely, fucking disgusting.
|
|
993 * #### The whole point of "elt" is that it operates on
|
|
994 * #### sequences, and does error- (bounds-) checking.
|
|
995 */
|
|
996 if (CONSP (tem))
|
173
|
997 return XCAR (tem);
|
0
|
998 else
|
|
999 #if 1
|
|
1000 /* This is The Way It Has Always Been. */
|
|
1001 return Qnil;
|
|
1002 #else
|
|
1003 /* This is The Way Mly Says It Should Be. */
|
|
1004 args_out_of_range (seq, n);
|
|
1005 #endif
|
|
1006 }
|
|
1007 else if (STRINGP (seq)
|
|
1008 || VECTORP (seq)
|
|
1009 || BIT_VECTORP (seq))
|
173
|
1010 return Faref (seq, n);
|
0
|
1011 #ifdef LOSING_BYTECODE
|
|
1012 else if (COMPILED_FUNCTIONP (seq))
|
|
1013 {
|
|
1014 int idx = XINT (n);
|
|
1015 if (idx < 0)
|
|
1016 {
|
|
1017 lose:
|
|
1018 args_out_of_range (seq, n);
|
|
1019 }
|
|
1020 /* Utter perversity */
|
|
1021 {
|
|
1022 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (seq);
|
|
1023 switch (idx)
|
|
1024 {
|
|
1025 case COMPILED_ARGLIST:
|
173
|
1026 return b->arglist;
|
0
|
1027 case COMPILED_BYTECODE:
|
173
|
1028 return b->bytecodes;
|
0
|
1029 case COMPILED_CONSTANTS:
|
173
|
1030 return b->constants;
|
0
|
1031 case COMPILED_STACK_DEPTH:
|
173
|
1032 return make_int (b->maxdepth);
|
0
|
1033 case COMPILED_DOC_STRING:
|
173
|
1034 return compiled_function_documentation (b);
|
0
|
1035 case COMPILED_DOMAIN:
|
173
|
1036 return compiled_function_domain (b);
|
0
|
1037 case COMPILED_INTERACTIVE:
|
|
1038 if (b->flags.interactivep)
|
173
|
1039 return compiled_function_interactive (b);
|
0
|
1040 /* if we return nil, can't tell interactive with no args
|
|
1041 from noninteractive. */
|
|
1042 goto lose;
|
|
1043 default:
|
|
1044 goto lose;
|
|
1045 }
|
|
1046 }
|
|
1047 }
|
|
1048 #endif /* LOSING_BYTECODE */
|
|
1049 else
|
|
1050 {
|
|
1051 check_losing_bytecode ("elt", seq);
|
|
1052 seq = wrong_type_argument (Qsequencep, seq);
|
|
1053 goto retry;
|
|
1054 }
|
|
1055 }
|
|
1056
|
20
|
1057 DEFUN ("member", Fmember, 2, 2, 0, /*
|
0
|
1058 Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
|
|
1059 The value is actually the tail of LIST whose car is ELT.
|
20
|
1060 */
|
|
1061 (elt, list))
|
0
|
1062 {
|
|
1063 REGISTER Lisp_Object tail, tem;
|
|
1064 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1065 {
|
|
1066 tem = Fcar (tail);
|
|
1067 if (! NILP (Fequal (elt, tem)))
|
|
1068 return tail;
|
|
1069 QUIT;
|
|
1070 }
|
|
1071 return Qnil;
|
|
1072 }
|
|
1073
|
70
|
1074 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
|
|
1075 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
|
|
1076 The value is actually the tail of LIST whose car is ELT.
|
|
1077 This function is provided only for byte-code compatibility with v19.
|
|
1078 Do not use it.
|
|
1079 */
|
|
1080 (elt, list))
|
|
1081 {
|
|
1082 REGISTER Lisp_Object tail, tem;
|
|
1083 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1084 {
|
|
1085 tem = Fcar (tail);
|
|
1086 if (! NILP (Fold_equal (elt, tem)))
|
|
1087 return tail;
|
|
1088 QUIT;
|
|
1089 }
|
|
1090 return Qnil;
|
|
1091 }
|
|
1092
|
20
|
1093 DEFUN ("memq", Fmemq, 2, 2, 0, /*
|
0
|
1094 Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
|
|
1095 The value is actually the tail of LIST whose car is ELT.
|
20
|
1096 */
|
|
1097 (elt, list))
|
0
|
1098 {
|
|
1099 REGISTER Lisp_Object tail, tem;
|
|
1100 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1101 {
|
|
1102 tem = Fcar (tail);
|
70
|
1103 if (EQ_WITH_EBOLA_NOTICE (elt, tem)) return tail;
|
|
1104 QUIT;
|
|
1105 }
|
|
1106 return Qnil;
|
|
1107 }
|
|
1108
|
|
1109 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
|
|
1110 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
|
|
1111 The value is actually the tail of LIST whose car is ELT.
|
|
1112 This function is provided only for byte-code compatibility with v19.
|
|
1113 Do not use it.
|
|
1114 */
|
|
1115 (elt, list))
|
|
1116 {
|
|
1117 REGISTER Lisp_Object tail, tem;
|
|
1118 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1119 {
|
|
1120 tem = Fcar (tail);
|
0
|
1121 if (HACKEQ_UNSAFE (elt, tem)) return tail;
|
|
1122 QUIT;
|
|
1123 }
|
|
1124 return Qnil;
|
|
1125 }
|
|
1126
|
|
1127 Lisp_Object
|
|
1128 memq_no_quit (Lisp_Object elt, Lisp_Object list)
|
|
1129 {
|
|
1130 REGISTER Lisp_Object tail, tem;
|
|
1131 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1132 {
|
|
1133 tem = XCAR (tail);
|
70
|
1134 if (EQ_WITH_EBOLA_NOTICE (elt, tem)) return tail;
|
0
|
1135 }
|
|
1136 return Qnil;
|
|
1137 }
|
|
1138
|
20
|
1139 DEFUN ("assoc", Fassoc, 2, 2, 0, /*
|
0
|
1140 Return non-nil if KEY is `equal' to the car of an element of LIST.
|
|
1141 The value is actually the element of LIST whose car equals KEY.
|
20
|
1142 */
|
|
1143 (key, list))
|
0
|
1144 {
|
|
1145 /* This function can GC. */
|
|
1146 REGISTER Lisp_Object tail, elt, tem;
|
|
1147 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1148 {
|
|
1149 elt = Fcar (tail);
|
|
1150 if (!CONSP (elt)) continue;
|
|
1151 tem = Fequal (Fcar (elt), key);
|
|
1152 if (!NILP (tem)) return elt;
|
|
1153 QUIT;
|
|
1154 }
|
|
1155 return Qnil;
|
|
1156 }
|
|
1157
|
70
|
1158 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
|
|
1159 Return non-nil if KEY is `old-equal' to the car of an element of LIST.
|
|
1160 The value is actually the element of LIST whose car equals KEY.
|
|
1161 */
|
|
1162 (key, list))
|
|
1163 {
|
|
1164 /* This function can GC. */
|
|
1165 REGISTER Lisp_Object tail, elt, tem;
|
|
1166 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1167 {
|
|
1168 elt = Fcar (tail);
|
|
1169 if (!CONSP (elt)) continue;
|
|
1170 tem = Fold_equal (Fcar (elt), key);
|
|
1171 if (!NILP (tem)) return elt;
|
|
1172 QUIT;
|
|
1173 }
|
|
1174 return Qnil;
|
|
1175 }
|
|
1176
|
0
|
1177 Lisp_Object
|
|
1178 assoc_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1179 {
|
|
1180 int speccount = specpdl_depth ();
|
|
1181 specbind (Qinhibit_quit, Qt);
|
149
|
1182 return unbind_to (speccount, Fassoc (key, list));
|
0
|
1183 }
|
|
1184
|
20
|
1185 DEFUN ("assq", Fassq, 2, 2, 0, /*
|
0
|
1186 Return non-nil if KEY is `eq' to the car of an element of LIST.
|
|
1187 The value is actually the element of LIST whose car is KEY.
|
|
1188 Elements of LIST that are not conses are ignored.
|
20
|
1189 */
|
|
1190 (key, list))
|
0
|
1191 {
|
|
1192 REGISTER Lisp_Object tail, elt, tem;
|
|
1193 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1194 {
|
|
1195 elt = Fcar (tail);
|
|
1196 if (!CONSP (elt)) continue;
|
|
1197 tem = Fcar (elt);
|
70
|
1198 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
|
1199 QUIT;
|
|
1200 }
|
|
1201 return Qnil;
|
|
1202 }
|
|
1203
|
|
1204 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
|
|
1205 Return non-nil if KEY is `old-eq' to the car of an element of LIST.
|
|
1206 The value is actually the element of LIST whose car is KEY.
|
|
1207 Elements of LIST that are not conses are ignored.
|
|
1208 This function is provided only for byte-code compatibility with v19.
|
|
1209 Do not use it.
|
|
1210 */
|
|
1211 (key, list))
|
|
1212 {
|
|
1213 REGISTER Lisp_Object tail, elt, tem;
|
|
1214 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1215 {
|
|
1216 elt = Fcar (tail);
|
|
1217 if (!CONSP (elt)) continue;
|
|
1218 tem = Fcar (elt);
|
0
|
1219 if (HACKEQ_UNSAFE (key, tem)) return elt;
|
|
1220 QUIT;
|
|
1221 }
|
|
1222 return Qnil;
|
|
1223 }
|
|
1224
|
|
1225 /* Like Fassq but never report an error and do not allow quits.
|
|
1226 Use only on lists known never to be circular. */
|
|
1227
|
|
1228 Lisp_Object
|
|
1229 assq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1230 {
|
|
1231 /* This cannot GC. */
|
|
1232 REGISTER Lisp_Object tail, elt, tem;
|
|
1233 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1234 {
|
|
1235 elt = XCAR (tail);
|
|
1236 if (!CONSP (elt)) continue;
|
|
1237 tem = XCAR (elt);
|
70
|
1238 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
0
|
1239 }
|
|
1240 return Qnil;
|
|
1241 }
|
|
1242
|
20
|
1243 DEFUN ("rassoc", Frassoc, 2, 2, 0, /*
|
0
|
1244 Return non-nil if KEY is `equal' to the cdr of an element of LIST.
|
|
1245 The value is actually the element of LIST whose cdr equals KEY.
|
20
|
1246 */
|
|
1247 (key, list))
|
0
|
1248 {
|
|
1249 REGISTER Lisp_Object tail;
|
|
1250 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1251 {
|
|
1252 REGISTER Lisp_Object elt, tem;
|
|
1253 elt = Fcar (tail);
|
|
1254 if (!CONSP (elt)) continue;
|
|
1255 tem = Fequal (Fcdr (elt), key);
|
|
1256 if (!NILP (tem)) return elt;
|
|
1257 QUIT;
|
|
1258 }
|
|
1259 return Qnil;
|
|
1260 }
|
|
1261
|
70
|
1262 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
|
|
1263 Return non-nil if KEY is `old-equal' to the cdr of an element of LIST.
|
|
1264 The value is actually the element of LIST whose cdr equals KEY.
|
|
1265 */
|
|
1266 (key, list))
|
|
1267 {
|
|
1268 REGISTER Lisp_Object tail;
|
|
1269 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1270 {
|
|
1271 REGISTER Lisp_Object elt, tem;
|
|
1272 elt = Fcar (tail);
|
|
1273 if (!CONSP (elt)) continue;
|
|
1274 tem = Fold_equal (Fcdr (elt), key);
|
|
1275 if (!NILP (tem)) return elt;
|
|
1276 QUIT;
|
|
1277 }
|
|
1278 return Qnil;
|
|
1279 }
|
|
1280
|
20
|
1281 DEFUN ("rassq", Frassq, 2, 2, 0, /*
|
0
|
1282 Return non-nil if KEY is `eq' to the cdr of an element of LIST.
|
|
1283 The value is actually the element of LIST whose cdr is KEY.
|
20
|
1284 */
|
|
1285 (key, list))
|
0
|
1286 {
|
|
1287 REGISTER Lisp_Object tail, elt, tem;
|
|
1288 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1289 {
|
|
1290 elt = Fcar (tail);
|
|
1291 if (!CONSP (elt)) continue;
|
|
1292 tem = Fcdr (elt);
|
70
|
1293 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
|
1294 QUIT;
|
|
1295 }
|
|
1296 return Qnil;
|
|
1297 }
|
|
1298
|
|
1299 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /*
|
|
1300 Return non-nil if KEY is `old-eq' to the cdr of an element of LIST.
|
|
1301 The value is actually the element of LIST whose cdr is KEY.
|
|
1302 */
|
|
1303 (key, list))
|
|
1304 {
|
|
1305 REGISTER Lisp_Object tail, elt, tem;
|
|
1306 for (tail = list; !NILP (tail); tail = Fcdr (tail))
|
|
1307 {
|
|
1308 elt = Fcar (tail);
|
|
1309 if (!CONSP (elt)) continue;
|
|
1310 tem = Fcdr (elt);
|
0
|
1311 if (HACKEQ_UNSAFE (key, tem)) return elt;
|
|
1312 QUIT;
|
|
1313 }
|
|
1314 return Qnil;
|
|
1315 }
|
|
1316
|
|
1317 Lisp_Object
|
|
1318 rassq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1319 {
|
|
1320 REGISTER Lisp_Object tail, elt, tem;
|
|
1321 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1322 {
|
|
1323 elt = XCAR (tail);
|
|
1324 if (!CONSP (elt)) continue;
|
|
1325 tem = XCDR (elt);
|
70
|
1326 if (EQ_WITH_EBOLA_NOTICE (key, tem)) return elt;
|
0
|
1327 }
|
|
1328 return Qnil;
|
|
1329 }
|
|
1330
|
|
1331
|
20
|
1332 DEFUN ("delete", Fdelete, 2, 2, 0, /*
|
0
|
1333 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1334 The modified LIST is returned. Comparison is done with `equal'.
|
|
1335 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1336 effect; therefore, write `(setq foo (delete element foo))' to be sure
|
|
1337 of changing the value of `foo'.
|
20
|
1338 */
|
|
1339 (elt, list))
|
0
|
1340 {
|
|
1341 REGISTER Lisp_Object tail, prev;
|
|
1342
|
|
1343 tail = list;
|
|
1344 prev = Qnil;
|
|
1345 while (!NILP (tail))
|
|
1346 {
|
|
1347 if (!NILP (Fequal (elt, Fcar (tail))))
|
|
1348 {
|
|
1349 if (NILP (prev))
|
|
1350 list = Fcdr (tail);
|
|
1351 else
|
|
1352 Fsetcdr (prev, Fcdr (tail));
|
|
1353 }
|
|
1354 else
|
|
1355 prev = tail;
|
|
1356 tail = Fcdr (tail);
|
|
1357 QUIT;
|
|
1358 }
|
|
1359 return list;
|
|
1360 }
|
|
1361
|
70
|
1362 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
|
|
1363 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1364 The modified LIST is returned. Comparison is done with `old-equal'.
|
|
1365 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1366 effect; therefore, write `(setq foo (delete element foo))' to be sure
|
|
1367 of changing the value of `foo'.
|
|
1368 */
|
|
1369 (elt, list))
|
|
1370 {
|
|
1371 REGISTER Lisp_Object tail, prev;
|
|
1372
|
|
1373 tail = list;
|
|
1374 prev = Qnil;
|
|
1375 while (!NILP (tail))
|
|
1376 {
|
|
1377 if (!NILP (Fold_equal (elt, Fcar (tail))))
|
|
1378 {
|
|
1379 if (NILP (prev))
|
|
1380 list = Fcdr (tail);
|
|
1381 else
|
|
1382 Fsetcdr (prev, Fcdr (tail));
|
|
1383 }
|
|
1384 else
|
|
1385 prev = tail;
|
|
1386 tail = Fcdr (tail);
|
|
1387 QUIT;
|
|
1388 }
|
|
1389 return list;
|
|
1390 }
|
|
1391
|
20
|
1392 DEFUN ("delq", Fdelq, 2, 2, 0, /*
|
0
|
1393 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1394 The modified LIST is returned. Comparison is done with `eq'.
|
|
1395 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1396 effect; therefore, write `(setq foo (delq element foo))' to be sure of
|
|
1397 changing the value of `foo'.
|
20
|
1398 */
|
|
1399 (elt, list))
|
0
|
1400 {
|
|
1401 REGISTER Lisp_Object tail, prev;
|
|
1402 REGISTER Lisp_Object tem;
|
|
1403
|
|
1404 tail = list;
|
|
1405 prev = Qnil;
|
|
1406 while (!NILP (tail))
|
|
1407 {
|
|
1408 tem = Fcar (tail);
|
70
|
1409 if (EQ_WITH_EBOLA_NOTICE (elt, tem))
|
|
1410 {
|
|
1411 if (NILP (prev))
|
|
1412 list = Fcdr (tail);
|
|
1413 else
|
|
1414 Fsetcdr (prev, Fcdr (tail));
|
|
1415 }
|
|
1416 else
|
|
1417 prev = tail;
|
|
1418 tail = Fcdr (tail);
|
|
1419 QUIT;
|
|
1420 }
|
|
1421 return list;
|
|
1422 }
|
|
1423
|
|
1424 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
|
|
1425 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1426 The modified LIST is returned. Comparison is done with `old-eq'.
|
|
1427 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1428 effect; therefore, write `(setq foo (delq element foo))' to be sure of
|
|
1429 changing the value of `foo'.
|
|
1430 */
|
|
1431 (elt, list))
|
|
1432 {
|
|
1433 REGISTER Lisp_Object tail, prev;
|
|
1434 REGISTER Lisp_Object tem;
|
|
1435
|
|
1436 tail = list;
|
|
1437 prev = Qnil;
|
|
1438 while (!NILP (tail))
|
|
1439 {
|
|
1440 tem = Fcar (tail);
|
0
|
1441 if (HACKEQ_UNSAFE (elt, tem))
|
|
1442 {
|
|
1443 if (NILP (prev))
|
|
1444 list = Fcdr (tail);
|
|
1445 else
|
|
1446 Fsetcdr (prev, Fcdr (tail));
|
|
1447 }
|
|
1448 else
|
|
1449 prev = tail;
|
|
1450 tail = Fcdr (tail);
|
|
1451 QUIT;
|
|
1452 }
|
|
1453 return list;
|
|
1454 }
|
|
1455
|
|
1456 /* no quit, no errors; be careful */
|
|
1457
|
|
1458 Lisp_Object
|
|
1459 delq_no_quit (Lisp_Object elt, Lisp_Object list)
|
|
1460 {
|
|
1461 REGISTER Lisp_Object tail, prev;
|
|
1462 REGISTER Lisp_Object tem;
|
|
1463
|
|
1464 tail = list;
|
|
1465 prev = Qnil;
|
|
1466 while (CONSP (tail))
|
|
1467 {
|
|
1468 tem = XCAR (tail);
|
70
|
1469 if (EQ_WITH_EBOLA_NOTICE (elt, tem))
|
0
|
1470 {
|
|
1471 if (NILP (prev))
|
|
1472 list = XCDR (tail);
|
|
1473 else
|
|
1474 XCDR (prev) = XCDR (tail);
|
|
1475 }
|
|
1476 else
|
|
1477 prev = tail;
|
|
1478 tail = XCDR (tail);
|
|
1479 }
|
|
1480 return list;
|
|
1481 }
|
|
1482
|
|
1483 /* Be VERY careful with this. This is like delq_no_quit() but
|
|
1484 also calls free_cons() on the removed conses. You must be SURE
|
|
1485 that no pointers to the freed conses remain around (e.g.
|
|
1486 someone else is pointing to part of the list). This function
|
|
1487 is useful on internal lists that are used frequently and where
|
|
1488 the actual list doesn't escape beyond known code bounds. */
|
|
1489
|
|
1490 Lisp_Object
|
|
1491 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list)
|
|
1492 {
|
|
1493 REGISTER Lisp_Object tail, prev;
|
|
1494 REGISTER Lisp_Object tem;
|
|
1495
|
|
1496 tail = list;
|
|
1497 prev = Qnil;
|
|
1498 while (CONSP (tail))
|
|
1499 {
|
|
1500 Lisp_Object cons_to_free = Qnil;
|
|
1501 tem = XCAR (tail);
|
70
|
1502 if (EQ_WITH_EBOLA_NOTICE (elt, tem))
|
0
|
1503 {
|
|
1504 if (NILP (prev))
|
|
1505 list = XCDR (tail);
|
|
1506 else
|
|
1507 XCDR (prev) = XCDR (tail);
|
|
1508 cons_to_free = tail;
|
|
1509 }
|
|
1510 else
|
|
1511 prev = tail;
|
|
1512 tail = XCDR (tail);
|
|
1513 if (!NILP (cons_to_free))
|
|
1514 free_cons (XCONS (cons_to_free));
|
|
1515 }
|
|
1516 return list;
|
|
1517 }
|
|
1518
|
20
|
1519 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /*
|
0
|
1520 Delete by side effect any elements of LIST whose car is `equal' to KEY.
|
|
1521 The modified LIST is returned. If the first member of LIST has a car
|
|
1522 that is `equal' to KEY, there is no way to remove it by side effect;
|
|
1523 therefore, write `(setq foo (remassoc key foo))' to be sure of changing
|
|
1524 the value of `foo'.
|
20
|
1525 */
|
|
1526 (key, list))
|
0
|
1527 {
|
|
1528 REGISTER Lisp_Object tail, prev;
|
|
1529
|
|
1530 tail = list;
|
|
1531 prev = Qnil;
|
|
1532 while (!NILP (tail))
|
|
1533 {
|
|
1534 Lisp_Object elt = Fcar (tail);
|
|
1535 if (CONSP (elt) && ! NILP (Fequal (key, Fcar (elt))))
|
|
1536 {
|
|
1537 if (NILP (prev))
|
|
1538 list = Fcdr (tail);
|
|
1539 else
|
|
1540 Fsetcdr (prev, Fcdr (tail));
|
|
1541 }
|
|
1542 else
|
|
1543 prev = tail;
|
|
1544 tail = Fcdr (tail);
|
|
1545 QUIT;
|
|
1546 }
|
|
1547 return list;
|
|
1548 }
|
|
1549
|
|
1550 Lisp_Object
|
|
1551 remassoc_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1552 {
|
|
1553 int speccount = specpdl_depth ();
|
|
1554 specbind (Qinhibit_quit, Qt);
|
149
|
1555 return unbind_to (speccount, Fremassoc (key, list));
|
0
|
1556 }
|
|
1557
|
20
|
1558 DEFUN ("remassq", Fremassq, 2, 2, 0, /*
|
0
|
1559 Delete by side effect any elements of LIST whose car is `eq' to KEY.
|
|
1560 The modified LIST is returned. If the first member of LIST has a car
|
|
1561 that is `eq' to KEY, there is no way to remove it by side effect;
|
|
1562 therefore, write `(setq foo (remassq key foo))' to be sure of changing
|
|
1563 the value of `foo'.
|
20
|
1564 */
|
|
1565 (key, list))
|
0
|
1566 {
|
|
1567 REGISTER Lisp_Object tail, prev;
|
|
1568
|
|
1569 tail = list;
|
|
1570 prev = Qnil;
|
|
1571 while (!NILP (tail))
|
|
1572 {
|
|
1573 Lisp_Object elt = Fcar (tail);
|
70
|
1574 if (CONSP (elt) && EQ_WITH_EBOLA_NOTICE (key, Fcar (elt)))
|
0
|
1575 {
|
|
1576 if (NILP (prev))
|
|
1577 list = Fcdr (tail);
|
|
1578 else
|
|
1579 Fsetcdr (prev, Fcdr (tail));
|
|
1580 }
|
|
1581 else
|
|
1582 prev = tail;
|
|
1583 tail = Fcdr (tail);
|
|
1584 QUIT;
|
|
1585 }
|
|
1586 return list;
|
|
1587 }
|
|
1588
|
|
1589 /* no quit, no errors; be careful */
|
|
1590
|
|
1591 Lisp_Object
|
|
1592 remassq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1593 {
|
|
1594 REGISTER Lisp_Object tail, prev;
|
|
1595 REGISTER Lisp_Object tem;
|
|
1596
|
|
1597 tail = list;
|
|
1598 prev = Qnil;
|
|
1599 while (CONSP (tail))
|
|
1600 {
|
|
1601 tem = XCAR (tail);
|
70
|
1602 if (CONSP (tem) && EQ_WITH_EBOLA_NOTICE (key, XCAR (tem)))
|
0
|
1603 {
|
|
1604 if (NILP (prev))
|
|
1605 list = XCDR (tail);
|
|
1606 else
|
|
1607 XCDR (prev) = XCDR (tail);
|
|
1608 }
|
|
1609 else
|
|
1610 prev = tail;
|
|
1611 tail = XCDR (tail);
|
|
1612 }
|
|
1613 return list;
|
|
1614 }
|
|
1615
|
20
|
1616 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /*
|
0
|
1617 Delete by side effect any elements of LIST whose cdr is `equal' to VALUE.
|
|
1618 The modified LIST is returned. If the first member of LIST has a car
|
|
1619 that is `equal' to VALUE, there is no way to remove it by side effect;
|
|
1620 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing
|
|
1621 the value of `foo'.
|
20
|
1622 */
|
|
1623 (value, list))
|
0
|
1624 {
|
|
1625 REGISTER Lisp_Object tail, prev;
|
|
1626
|
|
1627 tail = list;
|
|
1628 prev = Qnil;
|
|
1629 while (!NILP (tail))
|
|
1630 {
|
|
1631 Lisp_Object elt = Fcar (tail);
|
|
1632 if (CONSP (elt) && ! NILP (Fequal (value, Fcdr (elt))))
|
|
1633 {
|
|
1634 if (NILP (prev))
|
|
1635 list = Fcdr (tail);
|
|
1636 else
|
|
1637 Fsetcdr (prev, Fcdr (tail));
|
|
1638 }
|
|
1639 else
|
|
1640 prev = tail;
|
|
1641 tail = Fcdr (tail);
|
|
1642 QUIT;
|
|
1643 }
|
|
1644 return list;
|
|
1645 }
|
|
1646
|
20
|
1647 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /*
|
0
|
1648 Delete by side effect any elements of LIST whose cdr is `eq' to VALUE.
|
|
1649 The modified LIST is returned. If the first member of LIST has a car
|
|
1650 that is `eq' to VALUE, there is no way to remove it by side effect;
|
|
1651 therefore, write `(setq foo (remrassq value foo))' to be sure of changing
|
|
1652 the value of `foo'.
|
20
|
1653 */
|
|
1654 (value, list))
|
0
|
1655 {
|
|
1656 REGISTER Lisp_Object tail, prev;
|
|
1657
|
|
1658 tail = list;
|
|
1659 prev = Qnil;
|
|
1660 while (!NILP (tail))
|
|
1661 {
|
|
1662 Lisp_Object elt = Fcar (tail);
|
70
|
1663 if (CONSP (elt) && EQ_WITH_EBOLA_NOTICE (value, Fcdr (elt)))
|
0
|
1664 {
|
|
1665 if (NILP (prev))
|
|
1666 list = Fcdr (tail);
|
|
1667 else
|
|
1668 Fsetcdr (prev, Fcdr (tail));
|
|
1669 }
|
|
1670 else
|
|
1671 prev = tail;
|
|
1672 tail = Fcdr (tail);
|
|
1673 QUIT;
|
|
1674 }
|
|
1675 return list;
|
|
1676 }
|
|
1677
|
|
1678 /* no quit, no errors; be careful */
|
|
1679
|
|
1680 Lisp_Object
|
|
1681 remrassq_no_quit (Lisp_Object value, Lisp_Object list)
|
|
1682 {
|
|
1683 REGISTER Lisp_Object tail, prev;
|
|
1684 REGISTER Lisp_Object tem;
|
|
1685
|
|
1686 tail = list;
|
|
1687 prev = Qnil;
|
|
1688 while (CONSP (tail))
|
|
1689 {
|
|
1690 tem = XCAR (tail);
|
70
|
1691 if (CONSP (tem) && EQ_WITH_EBOLA_NOTICE (value, XCDR (tem)))
|
0
|
1692 {
|
|
1693 if (NILP (prev))
|
|
1694 list = XCDR (tail);
|
|
1695 else
|
|
1696 XCDR (prev) = XCDR (tail);
|
|
1697 }
|
|
1698 else
|
|
1699 prev = tail;
|
|
1700 tail = XCDR (tail);
|
|
1701 }
|
|
1702 return list;
|
|
1703 }
|
|
1704
|
20
|
1705 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /*
|
0
|
1706 Reverse LIST by modifying cdr pointers.
|
|
1707 Returns the beginning of the reversed list.
|
20
|
1708 */
|
|
1709 (list))
|
0
|
1710 {
|
|
1711 Lisp_Object prev, tail, next;
|
|
1712 struct gcpro gcpro1, gcpro2;
|
|
1713
|
|
1714 /* We gcpro our args; see `nconc' */
|
|
1715 prev = Qnil;
|
|
1716 tail = list;
|
|
1717 GCPRO2 (prev, tail);
|
|
1718 while (!NILP (tail))
|
|
1719 {
|
|
1720 QUIT;
|
165
|
1721 CHECK_CONS (tail);
|
|
1722 next = XCDR (tail);
|
|
1723 XCDR (tail) = prev;
|
0
|
1724 prev = tail;
|
|
1725 tail = next;
|
|
1726 }
|
|
1727 UNGCPRO;
|
|
1728 return prev;
|
|
1729 }
|
|
1730
|
20
|
1731 DEFUN ("reverse", Freverse, 1, 1, 0, /*
|
0
|
1732 Reverse LIST, copying. Returns the beginning of the reversed list.
|
|
1733 See also the function `nreverse', which is used more often.
|
20
|
1734 */
|
|
1735 (list))
|
0
|
1736 {
|
165
|
1737 Lisp_Object new;
|
|
1738
|
|
1739 for (new = Qnil; CONSP (list); list = XCDR (list))
|
|
1740 new = Fcons (XCAR (list), new);
|
|
1741 if (!NILP (list))
|
|
1742 list = wrong_type_argument (Qconsp, list);
|
|
1743 return new;
|
0
|
1744 }
|
|
1745
|
173
|
1746 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1747 Lisp_Object lisp_arg,
|
0
|
1748 int (*pred_fn) (Lisp_Object, Lisp_Object,
|
|
1749 Lisp_Object lisp_arg));
|
|
1750
|
|
1751 Lisp_Object
|
|
1752 list_sort (Lisp_Object list,
|
173
|
1753 Lisp_Object lisp_arg,
|
0
|
1754 int (*pred_fn) (Lisp_Object, Lisp_Object,
|
|
1755 Lisp_Object lisp_arg))
|
|
1756 {
|
|
1757 Lisp_Object front, back;
|
|
1758 Lisp_Object len, tem;
|
|
1759 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1760 int length;
|
|
1761
|
|
1762 front = list;
|
|
1763 len = Flength (list);
|
|
1764 length = XINT (len);
|
|
1765 if (length < 2)
|
|
1766 return list;
|
|
1767
|
|
1768 XSETINT (len, (length / 2) - 1);
|
|
1769 tem = Fnthcdr (len, list);
|
|
1770 back = Fcdr (tem);
|
|
1771 Fsetcdr (tem, Qnil);
|
|
1772
|
|
1773 GCPRO3 (front, back, lisp_arg);
|
|
1774 front = list_sort (front, lisp_arg, pred_fn);
|
|
1775 back = list_sort (back, lisp_arg, pred_fn);
|
|
1776 UNGCPRO;
|
|
1777 return list_merge (front, back, lisp_arg, pred_fn);
|
|
1778 }
|
|
1779
|
|
1780
|
|
1781 static int
|
173
|
1782 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2,
|
0
|
1783 Lisp_Object pred)
|
|
1784 {
|
|
1785 Lisp_Object tmp;
|
|
1786
|
|
1787 /* prevents the GC from happening in call2 */
|
|
1788 int speccount = specpdl_depth ();
|
|
1789 /* Emacs' GC doesn't actually relocate pointers, so this probably
|
|
1790 isn't strictly necessary */
|
|
1791 record_unwind_protect (restore_gc_inhibit,
|
|
1792 make_int (gc_currently_forbidden));
|
|
1793 gc_currently_forbidden = 1;
|
|
1794 tmp = call2 (pred, obj1, obj2);
|
|
1795 unbind_to (speccount, Qnil);
|
|
1796
|
173
|
1797 if (NILP (tmp))
|
0
|
1798 return -1;
|
|
1799 else
|
|
1800 return 1;
|
|
1801 }
|
|
1802
|
20
|
1803 DEFUN ("sort", Fsort, 2, 2, 0, /*
|
0
|
1804 Sort LIST, stably, comparing elements using PREDICATE.
|
|
1805 Returns the sorted list. LIST is modified by side effects.
|
|
1806 PREDICATE is called with two elements of LIST, and should return T
|
185
|
1807 if the first element is "less" than the second.
|
20
|
1808 */
|
|
1809 (list, pred))
|
0
|
1810 {
|
|
1811 return list_sort (list, pred, merge_pred_function);
|
|
1812 }
|
|
1813
|
|
1814 Lisp_Object
|
173
|
1815 merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
0
|
1816 Lisp_Object pred)
|
|
1817 {
|
|
1818 return list_merge (org_l1, org_l2, pred, merge_pred_function);
|
|
1819 }
|
|
1820
|
|
1821
|
|
1822 static Lisp_Object
|
173
|
1823 list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1824 Lisp_Object lisp_arg,
|
0
|
1825 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg))
|
|
1826 {
|
|
1827 Lisp_Object value;
|
|
1828 Lisp_Object tail;
|
|
1829 Lisp_Object tem;
|
|
1830 Lisp_Object l1, l2;
|
|
1831 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1832
|
|
1833 l1 = org_l1;
|
|
1834 l2 = org_l2;
|
|
1835 tail = Qnil;
|
|
1836 value = Qnil;
|
|
1837
|
|
1838 /* It is sufficient to protect org_l1 and org_l2.
|
|
1839 When l1 and l2 are updated, we copy the new values
|
|
1840 back into the org_ vars. */
|
173
|
1841
|
0
|
1842 GCPRO4 (org_l1, org_l2, lisp_arg, value);
|
|
1843
|
|
1844 while (1)
|
|
1845 {
|
|
1846 if (NILP (l1))
|
|
1847 {
|
|
1848 UNGCPRO;
|
|
1849 if (NILP (tail))
|
|
1850 return l2;
|
|
1851 Fsetcdr (tail, l2);
|
|
1852 return value;
|
|
1853 }
|
|
1854 if (NILP (l2))
|
|
1855 {
|
|
1856 UNGCPRO;
|
|
1857 if (NILP (tail))
|
|
1858 return l1;
|
|
1859 Fsetcdr (tail, l1);
|
|
1860 return value;
|
|
1861 }
|
|
1862
|
|
1863 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0)
|
|
1864 {
|
|
1865 tem = l1;
|
|
1866 l1 = Fcdr (l1);
|
|
1867 org_l1 = l1;
|
|
1868 }
|
|
1869 else
|
|
1870 {
|
|
1871 tem = l2;
|
|
1872 l2 = Fcdr (l2);
|
|
1873 org_l2 = l2;
|
|
1874 }
|
|
1875 if (NILP (tail))
|
|
1876 value = tem;
|
|
1877 else
|
|
1878 Fsetcdr (tail, tem);
|
|
1879 tail = tem;
|
|
1880 }
|
|
1881 }
|
|
1882
|
|
1883
|
|
1884 /************************************************************************/
|
|
1885 /* property-list functions */
|
|
1886 /************************************************************************/
|
|
1887
|
|
1888 /* For properties of text, we need to do order-insensitive comparison of
|
|
1889 plists. That is, we need to compare two plists such that they are the
|
|
1890 same if they have the same set of keys, and equivalent values.
|
|
1891 So (a 1 b 2) would be equal to (b 2 a 1).
|
|
1892
|
|
1893 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc.
|
|
1894 LAXP means use `equal' for comparisons.
|
|
1895 */
|
173
|
1896 int
|
0
|
1897 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present,
|
|
1898 int laxp, int depth)
|
|
1899 {
|
|
1900 int eqp = (depth == -1); /* -1 as depth means us eq, not equal. */
|
|
1901 int la, lb, m, i, fill;
|
|
1902 Lisp_Object *keys, *vals;
|
|
1903 char *flags;
|
|
1904 Lisp_Object rest;
|
|
1905
|
|
1906 if (NILP (a) && NILP (b))
|
|
1907 return 0;
|
|
1908
|
|
1909 Fcheck_valid_plist (a);
|
|
1910 Fcheck_valid_plist (b);
|
|
1911
|
|
1912 la = XINT (Flength (a));
|
|
1913 lb = XINT (Flength (b));
|
|
1914 m = (la > lb ? la : lb);
|
|
1915 fill = 0;
|
185
|
1916 keys = alloca_array (Lisp_Object, m);
|
|
1917 vals = alloca_array (Lisp_Object, m);
|
|
1918 flags = alloca_array (char, m);
|
0
|
1919
|
|
1920 /* First extract the pairs from A. */
|
|
1921 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest)))
|
|
1922 {
|
|
1923 Lisp_Object k = XCAR (rest);
|
|
1924 Lisp_Object v = XCAR (XCDR (rest));
|
|
1925 /* Maybe be Ebolified. */
|
|
1926 if (nil_means_not_present && NILP (v)) continue;
|
|
1927 keys [fill] = k;
|
|
1928 vals [fill] = v;
|
|
1929 flags[fill] = 0;
|
|
1930 fill++;
|
|
1931 }
|
|
1932 /* Now iterate over B, and stop if we find something that's not in A,
|
|
1933 or that doesn't match. As we match, mark them. */
|
|
1934 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest)))
|
|
1935 {
|
|
1936 Lisp_Object k = XCAR (rest);
|
|
1937 Lisp_Object v = XCAR (XCDR (rest));
|
|
1938 /* Maybe be Ebolified. */
|
|
1939 if (nil_means_not_present && NILP (v)) continue;
|
|
1940 for (i = 0; i < fill; i++)
|
|
1941 {
|
|
1942 if (!laxp ? EQ (k, keys [i]) : internal_equal (k, keys [i], depth))
|
|
1943 {
|
|
1944 if ((eqp
|
70
|
1945 /* We narrowly escaped being Ebolified here. */
|
|
1946 ? !EQ_WITH_EBOLA_NOTICE (v, vals [i])
|
0
|
1947 : !internal_equal (v, vals [i], depth)))
|
|
1948 /* a property in B has a different value than in A */
|
|
1949 goto MISMATCH;
|
|
1950 flags [i] = 1;
|
|
1951 break;
|
|
1952 }
|
|
1953 }
|
|
1954 if (i == fill)
|
|
1955 /* there are some properties in B that are not in A */
|
|
1956 goto MISMATCH;
|
|
1957 }
|
|
1958 /* Now check to see that all the properties in A were also in B */
|
|
1959 for (i = 0; i < fill; i++)
|
|
1960 if (flags [i] == 0)
|
|
1961 goto MISMATCH;
|
|
1962
|
|
1963 /* Ok. */
|
|
1964 return 0;
|
|
1965
|
|
1966 MISMATCH:
|
|
1967 return 1;
|
|
1968 }
|
|
1969
|
20
|
1970 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /*
|
0
|
1971 Return non-nil if property lists A and B are `eq'.
|
|
1972 A property list is an alternating list of keywords and values.
|
|
1973 This function does order-insensitive comparisons of the property lists:
|
|
1974 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
1975 Comparison between values is done using `eq'. See also `plists-equal'.
|
|
1976 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
1977 a nil value is ignored. This feature is a virus that has infected
|
16
|
1978 old Lisp implementations, but should not be used except for backward
|
|
1979 compatibility.
|
20
|
1980 */
|
|
1981 (a, b, nil_means_not_present))
|
0
|
1982 {
|
|
1983 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1)
|
|
1984 ? Qnil : Qt);
|
|
1985 }
|
|
1986
|
20
|
1987 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /*
|
0
|
1988 Return non-nil if property lists A and B are `equal'.
|
|
1989 A property list is an alternating list of keywords and values. This
|
|
1990 function does order-insensitive comparisons of the property lists: For
|
|
1991 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
1992 Comparison between values is done using `equal'. See also `plists-eq'.
|
|
1993 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
1994 a nil value is ignored. This feature is a virus that has infected
|
16
|
1995 old Lisp implementations, but should not be used except for backward
|
|
1996 compatibility.
|
20
|
1997 */
|
|
1998 (a, b, nil_means_not_present))
|
0
|
1999 {
|
|
2000 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1)
|
|
2001 ? Qnil : Qt);
|
|
2002 }
|
|
2003
|
|
2004
|
20
|
2005 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /*
|
0
|
2006 Return non-nil if lax property lists A and B are `eq'.
|
|
2007 A property list is an alternating list of keywords and values.
|
|
2008 This function does order-insensitive comparisons of the property lists:
|
|
2009 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2010 Comparison between values is done using `eq'. See also `plists-equal'.
|
|
2011 A lax property list is like a regular one except that comparisons between
|
|
2012 keywords is done using `equal' instead of `eq'.
|
|
2013 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2014 a nil value is ignored. This feature is a virus that has infected
|
16
|
2015 old Lisp implementations, but should not be used except for backward
|
|
2016 compatibility.
|
20
|
2017 */
|
|
2018 (a, b, nil_means_not_present))
|
0
|
2019 {
|
|
2020 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1)
|
|
2021 ? Qnil : Qt);
|
|
2022 }
|
|
2023
|
20
|
2024 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /*
|
0
|
2025 Return non-nil if lax property lists A and B are `equal'.
|
|
2026 A property list is an alternating list of keywords and values. This
|
|
2027 function does order-insensitive comparisons of the property lists: For
|
|
2028 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2029 Comparison between values is done using `equal'. See also `plists-eq'.
|
|
2030 A lax property list is like a regular one except that comparisons between
|
|
2031 keywords is done using `equal' instead of `eq'.
|
|
2032 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2033 a nil value is ignored. This feature is a virus that has infected
|
16
|
2034 old Lisp implementations, but should not be used except for backward
|
|
2035 compatibility.
|
20
|
2036 */
|
|
2037 (a, b, nil_means_not_present))
|
0
|
2038 {
|
|
2039 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1)
|
|
2040 ? Qnil : Qt);
|
|
2041 }
|
|
2042
|
|
2043 /* Return the value associated with key PROPERTY in property list PLIST.
|
|
2044 Return nil if key not found. This function is used for internal
|
|
2045 property lists that cannot be directly manipulated by the user.
|
|
2046 */
|
|
2047
|
|
2048 Lisp_Object
|
|
2049 internal_plist_get (Lisp_Object plist, Lisp_Object property)
|
|
2050 {
|
|
2051 Lisp_Object tail = plist;
|
|
2052
|
|
2053 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
|
|
2054 {
|
|
2055 struct Lisp_Cons *c = XCONS (tail);
|
|
2056 if (EQ (c->car, property))
|
|
2057 return XCAR (c->cdr);
|
|
2058 }
|
|
2059
|
|
2060 return Qunbound;
|
|
2061 }
|
|
2062
|
|
2063 /* Set PLIST's value for PROPERTY to VALUE. Analogous to
|
|
2064 internal_plist_get(). */
|
|
2065
|
|
2066 void
|
|
2067 internal_plist_put (Lisp_Object *plist, Lisp_Object property,
|
|
2068 Lisp_Object value)
|
|
2069 {
|
|
2070 Lisp_Object tail = *plist;
|
173
|
2071
|
0
|
2072 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
|
|
2073 {
|
|
2074 struct Lisp_Cons *c = XCONS (tail);
|
|
2075 if (EQ (c->car, property))
|
|
2076 {
|
|
2077 XCAR (c->cdr) = value;
|
|
2078 return;
|
|
2079 }
|
|
2080 }
|
|
2081
|
|
2082 *plist = Fcons (property, Fcons (value, *plist));
|
|
2083 }
|
|
2084
|
|
2085 int
|
|
2086 internal_remprop (Lisp_Object *plist, Lisp_Object property)
|
|
2087 {
|
|
2088 Lisp_Object tail = *plist;
|
|
2089
|
|
2090 if (NILP (tail))
|
|
2091 return 0;
|
|
2092
|
|
2093 if (EQ (XCAR (tail), property))
|
|
2094 {
|
|
2095 *plist = XCDR (XCDR (tail));
|
|
2096 return 1;
|
|
2097 }
|
|
2098
|
|
2099 for (tail = XCDR (tail); !NILP (XCDR (tail));
|
|
2100 tail = XCDR (XCDR (tail)))
|
|
2101 {
|
|
2102 struct Lisp_Cons *c = XCONS (tail);
|
|
2103 if (EQ (XCAR (c->cdr), property))
|
|
2104 {
|
|
2105 c->cdr = XCDR (XCDR (c->cdr));
|
|
2106 return 1;
|
|
2107 }
|
|
2108 }
|
|
2109
|
|
2110 return 0;
|
|
2111 }
|
|
2112
|
|
2113 /* Called on a malformed property list. BADPLACE should be some
|
|
2114 place where truncating will form a good list -- i.e. we shouldn't
|
|
2115 result in a list with an odd length. */
|
|
2116
|
|
2117 static Lisp_Object
|
|
2118 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
|
|
2119 {
|
|
2120 if (ERRB_EQ (errb, ERROR_ME))
|
|
2121 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace));
|
|
2122 else
|
|
2123 {
|
|
2124 if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2125 {
|
|
2126 warn_when_safe_lispobj
|
|
2127 (Qlist, Qwarning,
|
|
2128 list2 (build_string
|
|
2129 ("Malformed property list -- list has been truncated"),
|
|
2130 *plist));
|
|
2131 *badplace = Qnil;
|
|
2132 }
|
|
2133 return Qunbound;
|
|
2134 }
|
|
2135 }
|
|
2136
|
|
2137 /* Called on a circular property list. BADPLACE should be some place
|
|
2138 where truncating will result in an even-length list, as above.
|
|
2139 If doesn't particularly matter where we truncate -- anywhere we
|
|
2140 truncate along the entire list will break the circularity, because
|
|
2141 it will create a terminus and the list currently doesn't have one.
|
|
2142 */
|
|
2143
|
|
2144 static Lisp_Object
|
|
2145 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
|
|
2146 {
|
|
2147 if (ERRB_EQ (errb, ERROR_ME))
|
|
2148 /* #### Eek, this will probably result in another error
|
|
2149 when PLIST is printed out */
|
|
2150 return Fsignal (Qcircular_property_list, list1 (*plist));
|
|
2151 else
|
|
2152 {
|
|
2153 if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2154 {
|
|
2155 warn_when_safe_lispobj
|
|
2156 (Qlist, Qwarning,
|
|
2157 list2 (build_string
|
|
2158 ("Circular property list -- list has been truncated"),
|
|
2159 *plist));
|
|
2160 *badplace = Qnil;
|
|
2161 }
|
|
2162 return Qunbound;
|
|
2163 }
|
|
2164 }
|
|
2165
|
|
2166 /* Advance the tortoise pointer by two (one iteration of a property-list
|
|
2167 loop) and the hare pointer by four and verify that no malformations
|
|
2168 or circularities exist. If so, return zero and store a value into
|
|
2169 RETVAL that should be returned by the calling function. Otherwise,
|
|
2170 return 1. See external_plist_get().
|
|
2171 */
|
|
2172
|
|
2173 static int
|
|
2174 advance_plist_pointers (Lisp_Object *plist,
|
|
2175 Lisp_Object **tortoise, Lisp_Object **hare,
|
|
2176 Error_behavior errb, Lisp_Object *retval)
|
|
2177 {
|
|
2178 int i;
|
|
2179 Lisp_Object *tortsave = *tortoise;
|
|
2180
|
|
2181 /* Note that our "fixing" may be more brutal than necessary,
|
|
2182 but it's the user's own problem, not ours. if they went in and
|
|
2183 manually fucked up a plist. */
|
173
|
2184
|
0
|
2185 for (i = 0; i < 2; i++)
|
|
2186 {
|
|
2187 /* This is a standard iteration of a defensive-loop-checking
|
|
2188 loop. We just do it twice because we want to advance past
|
|
2189 both the property and its value.
|
|
2190
|
|
2191 If the pointer indirection is confusing you, remember that
|
|
2192 one level of indirection on the hare and tortoise pointers
|
|
2193 is only due to pass-by-reference for this function. The other
|
|
2194 level is so that the plist can be fixed in place. */
|
|
2195
|
|
2196 /* When we reach the end of a well-formed plist, **HARE is
|
|
2197 nil. In that case, we don't do anything at all except
|
|
2198 advance TORTOISE by one. Otherwise, we advance HARE
|
|
2199 by two (making sure it's OK to do so), then advance
|
|
2200 TORTOISE by one (it will always be OK to do so because
|
|
2201 the HARE is always ahead of the TORTOISE and will have
|
|
2202 already verified the path), then make sure TORTOISE and
|
|
2203 HARE don't contain the same non-nil object -- if the
|
|
2204 TORTOISE and the HARE ever meet, then obviously we're
|
|
2205 in a circularity, and if we're in a circularity, then
|
|
2206 the TORTOISE and the HARE can't cross paths without
|
|
2207 meeting, since the HARE only gains one step over the
|
|
2208 TORTOISE per iteration. */
|
|
2209
|
|
2210 if (!NILP (**hare))
|
|
2211 {
|
|
2212 Lisp_Object *haresave = *hare;
|
|
2213 if (!CONSP (**hare))
|
|
2214 {
|
|
2215 *retval = bad_bad_bunny (plist, haresave, errb);
|
|
2216 return 0;
|
|
2217 }
|
|
2218 *hare = &XCDR (**hare);
|
|
2219 /* In a non-plist, we'd check here for a nil value for
|
|
2220 **HARE, which is OK (it just means the list has an
|
|
2221 odd number of elements). In a plist, it's not OK
|
|
2222 for the list to have an odd number of elements. */
|
|
2223 if (!CONSP (**hare))
|
|
2224 {
|
|
2225 *retval = bad_bad_bunny (plist, haresave, errb);
|
|
2226 return 0;
|
|
2227 }
|
|
2228 *hare = &XCDR (**hare);
|
|
2229 }
|
|
2230
|
|
2231 *tortoise = &XCDR (**tortoise);
|
|
2232 if (!NILP (**hare) && EQ (**tortoise, **hare))
|
|
2233 {
|
|
2234 *retval = bad_bad_turtle (plist, tortsave, errb);
|
|
2235 return 0;
|
|
2236 }
|
|
2237 }
|
|
2238
|
|
2239 return 1;
|
|
2240 }
|
|
2241
|
|
2242 /* Return the value of PROPERTY from PLIST, or Qunbound if
|
|
2243 property is not on the list.
|
|
2244
|
|
2245 PLIST is a Lisp-accessible property list, meaning that it
|
|
2246 has to be checked for malformations and circularities.
|
|
2247
|
|
2248 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the
|
|
2249 function will never signal an error; and if ERRB is ERROR_ME_WARN,
|
|
2250 on finding a malformation or a circularity, it issues a warning and
|
|
2251 attempts to silently fix the problem.
|
|
2252
|
|
2253 A pointer to PLIST is passed in so that PLIST can be successfully
|
|
2254 "fixed" even if the error is at the beginning of the plist. */
|
|
2255
|
|
2256 Lisp_Object
|
|
2257 external_plist_get (Lisp_Object *plist, Lisp_Object property,
|
|
2258 int laxp, Error_behavior errb)
|
|
2259 {
|
|
2260 Lisp_Object *tortoise = plist;
|
|
2261 Lisp_Object *hare = plist;
|
|
2262
|
|
2263 while (!NILP (*tortoise))
|
|
2264 {
|
|
2265 Lisp_Object *tortsave = tortoise;
|
|
2266 Lisp_Object retval;
|
|
2267
|
|
2268 /* We do the standard tortoise/hare march. We isolate the
|
|
2269 grungy stuff to do this in advance_plist_pointers(), though.
|
|
2270 To us, all this function does is advance the tortoise
|
|
2271 pointer by two and the hare pointer by four and make sure
|
|
2272 everything's OK. We first advance the pointers and then
|
|
2273 check if a property matched; this ensures that our
|
|
2274 check for a matching property is safe. */
|
|
2275
|
|
2276 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2277 return retval;
|
|
2278
|
|
2279 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2280 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2281 return XCAR (XCDR (*tortsave));
|
|
2282 }
|
|
2283
|
|
2284 return Qunbound;
|
|
2285 }
|
|
2286
|
|
2287 /* Set PLIST's value for PROPERTY to VALUE, given a possibly
|
|
2288 malformed or circular plist. Analogous to external_plist_get(). */
|
|
2289
|
|
2290 void
|
|
2291 external_plist_put (Lisp_Object *plist, Lisp_Object property,
|
|
2292 Lisp_Object value, int laxp, Error_behavior errb)
|
|
2293 {
|
|
2294 Lisp_Object *tortoise = plist;
|
|
2295 Lisp_Object *hare = plist;
|
|
2296
|
|
2297 while (!NILP (*tortoise))
|
|
2298 {
|
|
2299 Lisp_Object *tortsave = tortoise;
|
|
2300 Lisp_Object retval;
|
|
2301
|
|
2302 /* See above */
|
|
2303 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2304 return;
|
|
2305
|
|
2306 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2307 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2308 {
|
|
2309 XCAR (XCDR (*tortsave)) = value;
|
|
2310 return;
|
|
2311 }
|
|
2312 }
|
|
2313
|
|
2314 *plist = Fcons (property, Fcons (value, *plist));
|
|
2315 }
|
|
2316
|
|
2317 int
|
|
2318 external_remprop (Lisp_Object *plist, Lisp_Object property,
|
|
2319 int laxp, Error_behavior errb)
|
|
2320 {
|
|
2321 Lisp_Object *tortoise = plist;
|
|
2322 Lisp_Object *hare = plist;
|
|
2323
|
|
2324 while (!NILP (*tortoise))
|
|
2325 {
|
|
2326 Lisp_Object *tortsave = tortoise;
|
|
2327 Lisp_Object retval;
|
|
2328
|
|
2329 /* See above */
|
|
2330 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2331 return 0;
|
|
2332
|
|
2333 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2334 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2335 {
|
|
2336 /* Now you see why it's so convenient to have that level
|
|
2337 of indirection. */
|
|
2338 *tortsave = XCDR (XCDR (*tortsave));
|
|
2339 return 1;
|
|
2340 }
|
|
2341 }
|
|
2342
|
|
2343 return 0;
|
|
2344 }
|
|
2345
|
20
|
2346 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /*
|
0
|
2347 Extract a value from a property list.
|
|
2348 PLIST is a property list, which is a list of the form
|
|
2349 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
|
|
2350 corresponding to the given PROP, or DEFAULT if PROP is not
|
|
2351 one of the properties on the list.
|
20
|
2352 */
|
173
|
2353 (plist, prop, default_))
|
0
|
2354 {
|
|
2355 Lisp_Object val = external_plist_get (&plist, prop, 0, ERROR_ME);
|
|
2356 if (UNBOUNDP (val))
|
173
|
2357 return default_;
|
0
|
2358 return val;
|
|
2359 }
|
|
2360
|
20
|
2361 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /*
|
0
|
2362 Change value in PLIST of PROP to VAL.
|
|
2363 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
|
|
2364 PROP2 VALUE2 ...). PROP is usually a symbol and VAL is any object.
|
|
2365 If PROP is already a property on the list, its value is set to VAL,
|
|
2366 otherwise the new PROP VAL pair is added. The new plist is returned;
|
|
2367 use `(setq x (plist-put x prop val))' to be sure to use the new value.
|
|
2368 The PLIST is modified by side effects.
|
20
|
2369 */
|
|
2370 (plist, prop, val))
|
0
|
2371 {
|
|
2372 external_plist_put (&plist, prop, val, 0, ERROR_ME);
|
|
2373 return plist;
|
|
2374 }
|
|
2375
|
20
|
2376 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /*
|
0
|
2377 Remove from PLIST the property PROP and its value.
|
|
2378 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
|
|
2379 PROP2 VALUE2 ...). PROP is usually a symbol. The new plist is
|
|
2380 returned; use `(setq x (plist-remprop x prop val))' to be sure to use
|
|
2381 the new value. The PLIST is modified by side effects.
|
20
|
2382 */
|
|
2383 (plist, prop))
|
0
|
2384 {
|
|
2385 external_remprop (&plist, prop, 0, ERROR_ME);
|
|
2386 return plist;
|
|
2387 }
|
|
2388
|
20
|
2389 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /*
|
0
|
2390 Return t if PROP has a value specified in PLIST.
|
20
|
2391 */
|
|
2392 (plist, prop))
|
0
|
2393 {
|
|
2394 return UNBOUNDP (Fplist_get (plist, prop, Qunbound)) ? Qnil : Qt;
|
|
2395 }
|
|
2396
|
20
|
2397 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /*
|
0
|
2398 Given a plist, signal an error if there is anything wrong with it.
|
|
2399 This means that it's a malformed or circular plist.
|
20
|
2400 */
|
|
2401 (plist))
|
0
|
2402 {
|
|
2403 Lisp_Object *tortoise;
|
|
2404 Lisp_Object *hare;
|
|
2405
|
|
2406 start_over:
|
|
2407 tortoise = &plist;
|
|
2408 hare = &plist;
|
|
2409 while (!NILP (*tortoise))
|
|
2410 {
|
|
2411 Lisp_Object retval;
|
|
2412
|
|
2413 /* See above */
|
|
2414 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME,
|
|
2415 &retval))
|
|
2416 goto start_over;
|
|
2417 }
|
|
2418
|
|
2419 return Qnil;
|
|
2420 }
|
173
|
2421
|
20
|
2422 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /*
|
0
|
2423 Given a plist, return non-nil if its format is correct.
|
|
2424 If it returns nil, `check-valid-plist' will signal an error when given
|
|
2425 the plist; that means it's a malformed or circular plist or has non-symbols
|
|
2426 as keywords.
|
20
|
2427 */
|
|
2428 (plist))
|
0
|
2429 {
|
|
2430 Lisp_Object *tortoise;
|
|
2431 Lisp_Object *hare;
|
|
2432
|
|
2433 tortoise = &plist;
|
|
2434 hare = &plist;
|
|
2435 while (!NILP (*tortoise))
|
|
2436 {
|
|
2437 Lisp_Object retval;
|
|
2438
|
|
2439 /* See above */
|
|
2440 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT,
|
|
2441 &retval))
|
|
2442 return Qnil;
|
|
2443 }
|
|
2444
|
|
2445 return Qt;
|
|
2446 }
|
|
2447
|
20
|
2448 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /*
|
0
|
2449 Destructively remove any duplicate entries from a plist.
|
|
2450 In such cases, the first entry applies.
|
|
2451
|
|
2452 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2453 a nil value is removed. This feature is a virus that has infected
|
16
|
2454 old Lisp implementations, but should not be used except for backward
|
|
2455 compatibility.
|
0
|
2456
|
|
2457 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
|
|
2458 return value may not be EQ to the passed-in value, so make sure to
|
|
2459 `setq' the value back into where it came from.
|
20
|
2460 */
|
|
2461 (plist, nil_means_not_present))
|
0
|
2462 {
|
|
2463 Lisp_Object head = plist;
|
|
2464
|
|
2465 Fcheck_valid_plist (plist);
|
|
2466
|
|
2467 while (!NILP (plist))
|
|
2468 {
|
|
2469 Lisp_Object prop = Fcar (plist);
|
|
2470 Lisp_Object next = Fcdr (plist);
|
|
2471
|
|
2472 CHECK_CONS (next); /* just make doubly sure we catch any errors */
|
|
2473 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
|
|
2474 {
|
|
2475 if (EQ (head, plist))
|
|
2476 head = Fcdr (next);
|
|
2477 plist = Fcdr (next);
|
|
2478 continue;
|
|
2479 }
|
|
2480 /* external_remprop returns 1 if it removed any property.
|
|
2481 We have to loop till it didn't remove anything, in case
|
|
2482 the property occurs many times. */
|
|
2483 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME));
|
|
2484 plist = Fcdr (next);
|
|
2485 }
|
|
2486
|
|
2487 return head;
|
|
2488 }
|
|
2489
|
20
|
2490 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /*
|
0
|
2491 Extract a value from a lax property list.
|
|
2492
|
|
2493 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2494 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2495 using `equal' instead of `eq'. This function returns the value
|
|
2496 corresponding to the given PROP, or DEFAULT if PROP is not one of the
|
|
2497 properties on the list.
|
20
|
2498 */
|
173
|
2499 (lax_plist, prop, default_))
|
0
|
2500 {
|
|
2501 Lisp_Object val = external_plist_get (&lax_plist, prop, 1, ERROR_ME);
|
|
2502 if (UNBOUNDP (val))
|
173
|
2503 return default_;
|
0
|
2504 return val;
|
|
2505 }
|
|
2506
|
20
|
2507 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /*
|
0
|
2508 Change value in LAX-PLIST of PROP to VAL.
|
|
2509 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2510 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2511 using `equal' instead of `eq'. PROP is usually a symbol and VAL is
|
|
2512 any object. If PROP is already a property on the list, its value is
|
|
2513 set to VAL, otherwise the new PROP VAL pair is added. The new plist
|
|
2514 is returned; use `(setq x (lax-plist-put x prop val))' to be sure to
|
|
2515 use the new value. The LAX-PLIST is modified by side effects.
|
20
|
2516 */
|
|
2517 (lax_plist, prop, val))
|
0
|
2518 {
|
|
2519 external_plist_put (&lax_plist, prop, val, 1, ERROR_ME);
|
|
2520 return lax_plist;
|
|
2521 }
|
|
2522
|
20
|
2523 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /*
|
0
|
2524 Remove from LAX-PLIST the property PROP and its value.
|
|
2525 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2526 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2527 using `equal' instead of `eq'. PROP is usually a symbol. The new
|
|
2528 plist is returned; use `(setq x (lax-plist-remprop x prop val))' to be
|
|
2529 sure to use the new value. The LAX-PLIST is modified by side effects.
|
20
|
2530 */
|
|
2531 (lax_plist, prop))
|
0
|
2532 {
|
|
2533 external_remprop (&lax_plist, prop, 1, ERROR_ME);
|
|
2534 return lax_plist;
|
|
2535 }
|
|
2536
|
20
|
2537 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /*
|
0
|
2538 Return t if PROP has a value specified in LAX-PLIST.
|
|
2539 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2540 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2541 using `equal' instead of `eq'.
|
20
|
2542 */
|
|
2543 (lax_plist, prop))
|
0
|
2544 {
|
|
2545 return UNBOUNDP (Flax_plist_get (lax_plist, prop, Qunbound)) ? Qnil : Qt;
|
|
2546 }
|
|
2547
|
20
|
2548 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /*
|
0
|
2549 Destructively remove any duplicate entries from a lax plist.
|
|
2550 In such cases, the first entry applies.
|
|
2551
|
|
2552 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2553 a nil value is removed. This feature is a virus that has infected
|
16
|
2554 old Lisp implementations, but should not be used except for backward
|
|
2555 compatibility.
|
0
|
2556
|
|
2557 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
|
|
2558 return value may not be EQ to the passed-in value, so make sure to
|
|
2559 `setq' the value back into where it came from.
|
20
|
2560 */
|
|
2561 (lax_plist, nil_means_not_present))
|
0
|
2562 {
|
|
2563 Lisp_Object head = lax_plist;
|
|
2564
|
|
2565 Fcheck_valid_plist (lax_plist);
|
|
2566
|
|
2567 while (!NILP (lax_plist))
|
|
2568 {
|
|
2569 Lisp_Object prop = Fcar (lax_plist);
|
|
2570 Lisp_Object next = Fcdr (lax_plist);
|
|
2571
|
|
2572 CHECK_CONS (next); /* just make doubly sure we catch any errors */
|
|
2573 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
|
|
2574 {
|
|
2575 if (EQ (head, lax_plist))
|
|
2576 head = Fcdr (next);
|
|
2577 lax_plist = Fcdr (next);
|
|
2578 continue;
|
|
2579 }
|
|
2580 /* external_remprop returns 1 if it removed any property.
|
|
2581 We have to loop till it didn't remove anything, in case
|
|
2582 the property occurs many times. */
|
|
2583 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME));
|
|
2584 lax_plist = Fcdr (next);
|
|
2585 }
|
|
2586
|
|
2587 return head;
|
|
2588 }
|
|
2589
|
|
2590 /* In C because the frame props stuff uses it */
|
|
2591
|
20
|
2592 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /*
|
0
|
2593 Convert association list ALIST into the equivalent property-list form.
|
|
2594 The plist is returned. This converts from
|
|
2595
|
|
2596 \((a . 1) (b . 2) (c . 3))
|
|
2597
|
|
2598 into
|
|
2599
|
|
2600 \(a 1 b 2 c 3)
|
|
2601
|
|
2602 The original alist is destroyed in the process of constructing the plist.
|
|
2603 See also `alist-to-plist'.
|
20
|
2604 */
|
|
2605 (alist))
|
0
|
2606 {
|
|
2607 Lisp_Object head = alist;
|
|
2608 while (!NILP (alist))
|
|
2609 {
|
|
2610 /* remember the alist element. */
|
|
2611 Lisp_Object el = Fcar (alist);
|
|
2612
|
|
2613 Fsetcar (alist, Fcar (el));
|
|
2614 Fsetcar (el, Fcdr (el));
|
|
2615 Fsetcdr (el, Fcdr (alist));
|
|
2616 Fsetcdr (alist, el);
|
|
2617 alist = Fcdr (Fcdr (alist));
|
|
2618 }
|
|
2619
|
|
2620 return head;
|
|
2621 }
|
|
2622
|
|
2623 /* Symbol plists are directly accessible, so we need to protect against
|
|
2624 invalid property list structure */
|
|
2625
|
|
2626 static Lisp_Object
|
173
|
2627 symbol_getprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object default_)
|
0
|
2628 {
|
|
2629 Lisp_Object val = external_plist_get (&XSYMBOL (sym)->plist, propname,
|
|
2630 0, ERROR_ME);
|
|
2631 if (UNBOUNDP (val))
|
173
|
2632 return default_;
|
0
|
2633 return val;
|
|
2634 }
|
|
2635
|
|
2636 static void
|
|
2637 symbol_putprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object value)
|
|
2638 {
|
|
2639 external_plist_put (&XSYMBOL (sym)->plist, propname, value, 0, ERROR_ME);
|
|
2640 }
|
|
2641
|
|
2642 static int
|
|
2643 symbol_remprop (Lisp_Object symbol, Lisp_Object propname)
|
|
2644 {
|
|
2645 return external_remprop (&XSYMBOL (symbol)->plist, propname, 0, ERROR_ME);
|
|
2646 }
|
|
2647
|
|
2648 /* We store the string's extent info as the first element of the string's
|
|
2649 property list; and the string's MODIFF as the first or second element
|
|
2650 of the string's property list (depending on whether the extent info
|
|
2651 is present), but only if the string has been modified. This is ugly
|
|
2652 but it reduces the memory allocated for the string in the vast
|
|
2653 majority of cases, where the string is never modified and has no
|
|
2654 extent info. */
|
|
2655
|
|
2656
|
|
2657 static Lisp_Object *
|
|
2658 string_plist_ptr (struct Lisp_String *s)
|
|
2659 {
|
|
2660 Lisp_Object *ptr = &s->plist;
|
|
2661
|
|
2662 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
|
|
2663 ptr = &XCDR (*ptr);
|
|
2664 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
|
|
2665 ptr = &XCDR (*ptr);
|
|
2666 return ptr;
|
|
2667 }
|
|
2668
|
|
2669 Lisp_Object
|
|
2670 string_getprop (struct Lisp_String *s, Lisp_Object property,
|
173
|
2671 Lisp_Object default_)
|
0
|
2672 {
|
|
2673 Lisp_Object val = external_plist_get (string_plist_ptr (s), property, 0,
|
|
2674 ERROR_ME);
|
|
2675 if (UNBOUNDP (val))
|
173
|
2676 return default_;
|
0
|
2677 return val;
|
|
2678 }
|
|
2679
|
|
2680 void
|
|
2681 string_putprop (struct Lisp_String *s, Lisp_Object property,
|
|
2682 Lisp_Object value)
|
|
2683 {
|
|
2684 external_plist_put (string_plist_ptr (s), property, value, 0, ERROR_ME);
|
|
2685 }
|
|
2686
|
|
2687 static int
|
|
2688 string_remprop (struct Lisp_String *s, Lisp_Object property)
|
|
2689 {
|
|
2690 return external_remprop (string_plist_ptr (s), property, 0, ERROR_ME);
|
|
2691 }
|
|
2692
|
|
2693 static Lisp_Object
|
|
2694 string_plist (struct Lisp_String *s)
|
|
2695 {
|
|
2696 return *string_plist_ptr (s);
|
|
2697 }
|
|
2698
|
20
|
2699 DEFUN ("get", Fget, 2, 3, 0, /*
|
0
|
2700 Return the value of OBJECT's PROPNAME property.
|
|
2701 This is the last VALUE stored with `(put OBJECT PROPNAME VALUE)'.
|
|
2702 If there is no such property, return optional third arg DEFAULT
|
173
|
2703 \(which defaults to `nil'). OBJECT can be a symbol, face, extent,
|
0
|
2704 or string. See also `put', `remprop', and `object-plist'.
|
20
|
2705 */
|
173
|
2706 (object, propname, default_))
|
0
|
2707 {
|
|
2708 Lisp_Object val;
|
|
2709
|
|
2710 /* Various places in emacs call Fget() and expect it not to quit,
|
|
2711 so don't quit. */
|
173
|
2712
|
0
|
2713 /* It's easiest to treat symbols specially because they may not
|
|
2714 be an lrecord */
|
|
2715 if (SYMBOLP (object))
|
173
|
2716 val = symbol_getprop (object, propname, default_);
|
0
|
2717 else if (STRINGP (object))
|
173
|
2718 val = string_getprop (XSTRING (object), propname, default_);
|
0
|
2719 else if (LRECORDP (object))
|
|
2720 {
|
|
2721 CONST struct lrecord_implementation
|
|
2722 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2723 if (imp->getprop)
|
|
2724 {
|
|
2725 val = (imp->getprop) (object, propname);
|
|
2726 if (UNBOUNDP (val))
|
173
|
2727 val = default_;
|
0
|
2728 }
|
|
2729 else
|
|
2730 goto noprops;
|
|
2731 }
|
|
2732 else
|
|
2733 {
|
|
2734 noprops:
|
|
2735 signal_simple_error ("Object type has no properties", object);
|
|
2736 }
|
|
2737
|
|
2738 return val;
|
|
2739 }
|
|
2740
|
20
|
2741 DEFUN ("put", Fput, 3, 3, 0, /*
|
0
|
2742 Store OBJECT's PROPNAME property with value VALUE.
|
|
2743 It can be retrieved with `(get OBJECT PROPNAME)'. OBJECT can be a
|
|
2744 symbol, face, extent, or string.
|
|
2745
|
|
2746 For a string, no properties currently have predefined meanings.
|
|
2747 For the predefined properties for extents, see `set-extent-property'.
|
|
2748 For the predefined properties for faces, see `set-face-property'.
|
|
2749
|
|
2750 See also `get', `remprop', and `object-plist'.
|
20
|
2751 */
|
|
2752 (object, propname, value))
|
0
|
2753 {
|
|
2754 CHECK_SYMBOL (propname);
|
|
2755 CHECK_IMPURE (object);
|
|
2756
|
|
2757 if (SYMBOLP (object))
|
|
2758 symbol_putprop (object, propname, value);
|
|
2759 else if (STRINGP (object))
|
|
2760 string_putprop (XSTRING (object), propname, value);
|
|
2761 else if (LRECORDP (object))
|
|
2762 {
|
|
2763 CONST struct lrecord_implementation
|
|
2764 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2765 if (imp->putprop)
|
|
2766 {
|
|
2767 if (! (imp->putprop) (object, propname, value))
|
|
2768 signal_simple_error ("Can't set property on object", propname);
|
|
2769 }
|
|
2770 else
|
|
2771 goto noprops;
|
|
2772 }
|
|
2773 else
|
|
2774 {
|
|
2775 noprops:
|
|
2776 signal_simple_error ("Object type has no settable properties", object);
|
|
2777 }
|
|
2778
|
|
2779 return value;
|
|
2780 }
|
|
2781
|
|
2782 void
|
|
2783 pure_put (Lisp_Object sym, Lisp_Object prop, Lisp_Object val)
|
|
2784 {
|
|
2785 Fput (sym, prop, Fpurecopy (val));
|
|
2786 }
|
|
2787
|
20
|
2788 DEFUN ("remprop", Fremprop, 2, 2, 0, /*
|
0
|
2789 Remove from OBJECT's property list the property PROPNAME and its
|
|
2790 value. OBJECT can be a symbol, face, extent, or string. Returns
|
|
2791 non-nil if the property list was actually changed (i.e. if PROPNAME
|
|
2792 was present in the property list). See also `get', `put', and
|
|
2793 `object-plist'.
|
20
|
2794 */
|
|
2795 (object, propname))
|
0
|
2796 {
|
|
2797 int retval = 0;
|
|
2798
|
|
2799 CHECK_SYMBOL (propname);
|
|
2800 CHECK_IMPURE (object);
|
|
2801
|
|
2802 if (SYMBOLP (object))
|
|
2803 retval = symbol_remprop (object, propname);
|
|
2804 else if (STRINGP (object))
|
|
2805 retval = string_remprop (XSTRING (object), propname);
|
|
2806 else if (LRECORDP (object))
|
|
2807 {
|
|
2808 CONST struct lrecord_implementation
|
|
2809 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2810 if (imp->remprop)
|
|
2811 {
|
|
2812 retval = (imp->remprop) (object, propname);
|
|
2813 if (retval == -1)
|
|
2814 signal_simple_error ("Can't remove property from object",
|
|
2815 propname);
|
|
2816 }
|
|
2817 else
|
|
2818 goto noprops;
|
|
2819 }
|
|
2820 else
|
|
2821 {
|
|
2822 noprops:
|
|
2823 signal_simple_error ("Object type has no removable properties", object);
|
|
2824 }
|
|
2825
|
|
2826 return retval ? Qt : Qnil;
|
|
2827 }
|
|
2828
|
20
|
2829 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /*
|
0
|
2830 Return a property list of OBJECT's props.
|
|
2831 For a symbol this is equivalent to `symbol-plist'.
|
|
2832 Do not modify the property list directly; this may or may not have
|
|
2833 the desired effects. (In particular, for a property with a special
|
|
2834 interpretation, this will probably have no effect at all.)
|
20
|
2835 */
|
|
2836 (object))
|
0
|
2837 {
|
|
2838 if (SYMBOLP (object))
|
|
2839 return Fsymbol_plist (object);
|
|
2840 else if (STRINGP (object))
|
|
2841 return string_plist (XSTRING (object));
|
|
2842 else if (LRECORDP (object))
|
|
2843 {
|
|
2844 CONST struct lrecord_implementation
|
|
2845 *imp = XRECORD_LHEADER (object)->implementation;
|
|
2846 if (imp->plist)
|
|
2847 return (imp->plist) (object);
|
|
2848 else
|
|
2849 signal_simple_error ("Object type has no properties", object);
|
|
2850 }
|
|
2851 else
|
|
2852 signal_simple_error ("Object type has no properties", object);
|
|
2853
|
|
2854 return Qnil;
|
|
2855 }
|
|
2856
|
|
2857
|
|
2858 int
|
|
2859 internal_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2860 {
|
|
2861 if (depth > 200)
|
|
2862 error ("Stack overflow in equal");
|
|
2863 do_cdr:
|
|
2864 QUIT;
|
70
|
2865 if (EQ_WITH_EBOLA_NOTICE (o1, o2))
|
149
|
2866 return 1;
|
0
|
2867 /* Note that (equal 20 20.0) should be nil */
|
173
|
2868 else if (XTYPE (o1) != XTYPE (o2))
|
149
|
2869 return 0;
|
0
|
2870 else if (CONSP (o1))
|
|
2871 {
|
165
|
2872 if (!internal_equal (XCAR (o1), XCAR (o2), depth + 1))
|
149
|
2873 return 0;
|
165
|
2874 o1 = XCDR (o1);
|
|
2875 o2 = XCDR (o2);
|
0
|
2876 goto do_cdr;
|
|
2877 }
|
|
2878
|
|
2879 #ifndef LRECORD_VECTOR
|
|
2880 else if (VECTORP (o1))
|
|
2881 {
|
173
|
2882 int indice;
|
|
2883 int len = XVECTOR_LENGTH (o1);
|
|
2884 if (len != XVECTOR_LENGTH (o2))
|
149
|
2885 return 0;
|
173
|
2886 for (indice = 0; indice < len; indice++)
|
0
|
2887 {
|
|
2888 Lisp_Object v1, v2;
|
173
|
2889 v1 = XVECTOR_DATA (o1) [indice];
|
|
2890 v2 = XVECTOR_DATA (o2) [indice];
|
0
|
2891 if (!internal_equal (v1, v2, depth + 1))
|
149
|
2892 return 0;
|
0
|
2893 }
|
149
|
2894 return 1;
|
0
|
2895 }
|
|
2896 #endif /* !LRECORD_VECTOR */
|
|
2897 else if (STRINGP (o1))
|
|
2898 {
|
14
|
2899 Bytecount len = XSTRING_LENGTH (o1);
|
|
2900 if (len != XSTRING_LENGTH (o2))
|
149
|
2901 return 0;
|
14
|
2902 if (memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len))
|
149
|
2903 return 0;
|
|
2904 return 1;
|
0
|
2905 }
|
|
2906 else if (LRECORDP (o1))
|
|
2907 {
|
|
2908 CONST struct lrecord_implementation
|
|
2909 *imp1 = XRECORD_LHEADER (o1)->implementation,
|
|
2910 *imp2 = XRECORD_LHEADER (o2)->implementation;
|
|
2911 if (imp1 != imp2)
|
149
|
2912 return 0;
|
0
|
2913 else if (imp1->equal == 0)
|
|
2914 /* EQ-ness of the objects was noticed above */
|
149
|
2915 return 0;
|
0
|
2916 else
|
149
|
2917 return (imp1->equal) (o1, o2, depth);
|
0
|
2918 }
|
|
2919
|
149
|
2920 return 0;
|
0
|
2921 }
|
|
2922
|
70
|
2923 /* Note that we may be calling sub-objects that will use
|
|
2924 internal_equal() (instead of internal_old_equal()). Oh well.
|
|
2925 We will get an Ebola note if there's any possibility of confusion,
|
|
2926 but that seems unlikely. */
|
|
2927
|
|
2928 static int
|
|
2929 internal_old_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2930 {
|
|
2931 if (depth > 200)
|
|
2932 error ("Stack overflow in equal");
|
|
2933 do_cdr:
|
|
2934 QUIT;
|
|
2935 if (HACKEQ_UNSAFE (o1, o2))
|
149
|
2936 return 1;
|
70
|
2937 /* Note that (equal 20 20.0) should be nil */
|
173
|
2938 else if (XTYPE (o1) != XTYPE (o2))
|
149
|
2939 return 0;
|
70
|
2940 else if (CONSP (o1))
|
|
2941 {
|
165
|
2942 if (!internal_old_equal (XCAR (o1), XCAR (o2), depth + 1))
|
149
|
2943 return 0;
|
165
|
2944 o1 = XCDR (o1);
|
|
2945 o2 = XCDR (o2);
|
70
|
2946 goto do_cdr;
|
|
2947 }
|
|
2948
|
|
2949 #ifndef LRECORD_VECTOR
|
|
2950 else if (VECTORP (o1))
|
|
2951 {
|
173
|
2952 int indice;
|
|
2953 int len = XVECTOR_LENGTH (o1);
|
|
2954 if (len != XVECTOR_LENGTH (o2))
|
149
|
2955 return 0;
|
173
|
2956 for (indice = 0; indice < len; indice++)
|
70
|
2957 {
|
173
|
2958 if (!internal_old_equal (XVECTOR_DATA (o1) [indice],
|
|
2959 XVECTOR_DATA (o2) [indice],
|
|
2960 depth + 1))
|
149
|
2961 return 0;
|
70
|
2962 }
|
149
|
2963 return 1;
|
70
|
2964 }
|
|
2965 #endif /* !LRECORD_VECTOR */
|
|
2966 else if (STRINGP (o1))
|
|
2967 {
|
|
2968 Bytecount len = XSTRING_LENGTH (o1);
|
|
2969 if (len != XSTRING_LENGTH (o2))
|
149
|
2970 return 0;
|
70
|
2971 if (memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len))
|
149
|
2972 return 0;
|
|
2973 return 1;
|
70
|
2974 }
|
|
2975 else if (LRECORDP (o1))
|
|
2976 {
|
|
2977 CONST struct lrecord_implementation
|
|
2978 *imp1 = XRECORD_LHEADER (o1)->implementation,
|
|
2979 *imp2 = XRECORD_LHEADER (o2)->implementation;
|
|
2980 if (imp1 != imp2)
|
149
|
2981 return 0;
|
70
|
2982 else if (imp1->equal == 0)
|
|
2983 /* EQ-ness of the objects was noticed above */
|
149
|
2984 return 0;
|
70
|
2985 else
|
173
|
2986 return (imp1->equal) (o1, o2, depth);
|
70
|
2987 }
|
|
2988
|
149
|
2989 return 0;
|
70
|
2990 }
|
|
2991
|
20
|
2992 DEFUN ("equal", Fequal, 2, 2, 0, /*
|
0
|
2993 T if two Lisp objects have similar structure and contents.
|
|
2994 They must have the same data type.
|
|
2995 Conses are compared by comparing the cars and the cdrs.
|
|
2996 Vectors and strings are compared element by element.
|
|
2997 Numbers are compared by value. Symbols must match exactly.
|
20
|
2998 */
|
|
2999 (o1, o2))
|
0
|
3000 {
|
149
|
3001 return internal_equal (o1, o2, 0) ? Qt : Qnil;
|
0
|
3002 }
|
|
3003
|
70
|
3004 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /*
|
|
3005 T if two Lisp objects have similar structure and contents.
|
|
3006 They must have the same data type.
|
|
3007 \(Note, however, that an exception is made for characters and integers;
|
185
|
3008 this is known as the "char-int confoundance disease." See `eq' and
|
70
|
3009 `old-eq'.)
|
|
3010 This function is provided only for byte-code compatibility with v19.
|
|
3011 Do not use it.
|
|
3012 */
|
|
3013 (o1, o2))
|
|
3014 {
|
149
|
3015 return internal_old_equal (o1, o2, 0) ? Qt : Qnil;
|
70
|
3016 }
|
|
3017
|
0
|
3018
|
20
|
3019 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /*
|
0
|
3020 Store each element of ARRAY with ITEM.
|
|
3021 ARRAY is a vector, bit vector, or string.
|
20
|
3022 */
|
|
3023 (array, item))
|
0
|
3024 {
|
|
3025 retry:
|
76
|
3026 if (STRINGP (array))
|
|
3027 {
|
173
|
3028 Charcount len;
|
76
|
3029 Charcount i;
|
|
3030 Emchar charval;
|
|
3031 struct Lisp_String *s;
|
|
3032 CHECK_CHAR_COERCE_INT (item);
|
|
3033 CHECK_IMPURE (array);
|
|
3034 charval = XCHAR (item);
|
|
3035 s = XSTRING (array);
|
173
|
3036 len = string_char_length (s);
|
|
3037 for (i = 0; i < len; i++)
|
76
|
3038 set_string_char (s, i, charval);
|
|
3039 bump_string_modiff (array);
|
|
3040 }
|
|
3041 else if (VECTORP (array))
|
10
|
3042 {
|
70
|
3043 Lisp_Object *p;
|
173
|
3044 int len;
|
76
|
3045 int i;
|
10
|
3046 CHECK_IMPURE (array);
|
173
|
3047 len = XVECTOR_LENGTH (array);
|
|
3048 p = XVECTOR_DATA (array);
|
|
3049 for (i = 0; i < len; i++)
|
76
|
3050 p[i] = item;
|
10
|
3051 }
|
76
|
3052 else if (BIT_VECTORP (array))
|
0
|
3053 {
|
|
3054 struct Lisp_Bit_Vector *v;
|
173
|
3055 int len;
|
76
|
3056 int i;
|
0
|
3057 CHECK_BIT (item);
|
|
3058 CHECK_IMPURE (array);
|
|
3059 v = XBIT_VECTOR (array);
|
173
|
3060 len = bit_vector_length (v);
|
|
3061 for (i = 0; i < len; i++)
|
76
|
3062 set_bit_vector_bit (v, i, XINT (item));
|
0
|
3063 }
|
|
3064 else
|
|
3065 {
|
|
3066 array = wrong_type_argument (Qarrayp, array);
|
|
3067 goto retry;
|
|
3068 }
|
|
3069 return array;
|
|
3070 }
|
|
3071
|
|
3072 Lisp_Object
|
|
3073 nconc2 (Lisp_Object s1, Lisp_Object s2)
|
|
3074 {
|
|
3075 Lisp_Object args[2];
|
|
3076 args[0] = s1;
|
|
3077 args[1] = s2;
|
|
3078 return Fnconc (2, args);
|
|
3079 }
|
|
3080
|
20
|
3081 DEFUN ("nconc", Fnconc, 0, MANY, 0, /*
|
0
|
3082 Concatenate any number of lists by altering them.
|
|
3083 Only the last argument is not altered, and need not be a list.
|
20
|
3084 */
|
|
3085 (int nargs, Lisp_Object *args))
|
0
|
3086 {
|
|
3087 int argnum;
|
|
3088 Lisp_Object tail, tem, val;
|
|
3089 struct gcpro gcpro1;
|
|
3090
|
|
3091 /* The modus operandi in Emacs is "caller gc-protects args".
|
|
3092 However, nconc (particularly nconc2 ()) is called many times
|
|
3093 in Emacs on freshly created stuff (e.g. you see the idiom
|
|
3094 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those
|
|
3095 callers out by protecting the args ourselves to save them
|
|
3096 a lot of temporary-variable grief. */
|
|
3097
|
173
|
3098 again:
|
|
3099
|
0
|
3100 GCPRO1 (args[0]);
|
|
3101 gcpro1.nvars = nargs;
|
173
|
3102
|
0
|
3103 val = Qnil;
|
|
3104
|
|
3105 for (argnum = 0; argnum < nargs; argnum++)
|
|
3106 {
|
|
3107 tem = args[argnum];
|
|
3108 if (NILP (tem)) continue;
|
|
3109
|
|
3110 if (NILP (val))
|
|
3111 val = tem;
|
|
3112
|
|
3113 if (argnum + 1 == nargs) break;
|
|
3114
|
|
3115 if (!CONSP (tem))
|
173
|
3116 {
|
|
3117 tem = wrong_type_argument (Qlistp, tem);
|
|
3118 goto again;
|
|
3119 }
|
0
|
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 {
|
173
|
3173 dummy = XVECTOR_DATA (seq)[i];
|
0
|
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.
|
185
|
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
|
185
|
3230 args = alloca_array (Lisp_Object, nargs);
|
0
|
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];
|
173
|
3238
|
0
|
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));
|
185
|
3253 Lisp_Object *args = alloca_array (Lisp_Object, len);
|
16
|
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));
|
185
|
3268 Lisp_Object *args = alloca_array (Lisp_Object, len);
|
163
|
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 }
|
173
|
3361 return featurep_emacs_version >= d ? Qt : Qnil;
|
163
|
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,
|
177
|
3451 Qnil, Qt, Qnil);
|
0
|
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 }
|