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