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