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