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