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;
|
|
967 CHECK_NATNUM (n);
|
|
968 for (i = XINT (n); i; i--)
|
0
|
969 {
|
272
|
970 if (NILP (list))
|
|
971 return list;
|
|
972 CHECK_CONS (list);
|
|
973 list = XCDR (list);
|
0
|
974 QUIT;
|
|
975 }
|
|
976 return list;
|
|
977 }
|
|
978
|
20
|
979 DEFUN ("nth", Fnth, 2, 2, 0, /*
|
0
|
980 Return the Nth element of LIST.
|
|
981 N counts from zero. If LIST is not that long, nil is returned.
|
20
|
982 */
|
|
983 (n, list))
|
0
|
984 {
|
|
985 return Fcar (Fnthcdr (n, list));
|
|
986 }
|
|
987
|
20
|
988 DEFUN ("elt", Felt, 2, 2, 0, /*
|
0
|
989 Return element of SEQUENCE at index N.
|
20
|
990 */
|
272
|
991 (sequence, n))
|
0
|
992 {
|
|
993 retry:
|
|
994 CHECK_INT_COERCE_CHAR (n); /* yuck! */
|
272
|
995 if (LISTP (sequence))
|
0
|
996 {
|
272
|
997 Lisp_Object tem = Fnthcdr (n, sequence);
|
0
|
998 /* #### Utterly, completely, fucking disgusting.
|
|
999 * #### The whole point of "elt" is that it operates on
|
|
1000 * #### sequences, and does error- (bounds-) checking.
|
|
1001 */
|
|
1002 if (CONSP (tem))
|
173
|
1003 return XCAR (tem);
|
0
|
1004 else
|
|
1005 #if 1
|
|
1006 /* This is The Way It Has Always Been. */
|
|
1007 return Qnil;
|
|
1008 #else
|
|
1009 /* This is The Way Mly Says It Should Be. */
|
272
|
1010 args_out_of_range (sequence, n);
|
0
|
1011 #endif
|
|
1012 }
|
272
|
1013 else if (STRINGP (sequence)
|
|
1014 || VECTORP (sequence)
|
|
1015 || BIT_VECTORP (sequence))
|
|
1016 return Faref (sequence, n);
|
0
|
1017 #ifdef LOSING_BYTECODE
|
272
|
1018 else if (COMPILED_FUNCTIONP (sequence))
|
0
|
1019 {
|
|
1020 int idx = XINT (n);
|
|
1021 if (idx < 0)
|
|
1022 {
|
|
1023 lose:
|
272
|
1024 args_out_of_range (sequence, n);
|
0
|
1025 }
|
|
1026 /* Utter perversity */
|
|
1027 {
|
272
|
1028 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (sequence);
|
0
|
1029 switch (idx)
|
|
1030 {
|
|
1031 case COMPILED_ARGLIST:
|
173
|
1032 return b->arglist;
|
0
|
1033 case COMPILED_BYTECODE:
|
173
|
1034 return b->bytecodes;
|
0
|
1035 case COMPILED_CONSTANTS:
|
173
|
1036 return b->constants;
|
0
|
1037 case COMPILED_STACK_DEPTH:
|
173
|
1038 return make_int (b->maxdepth);
|
0
|
1039 case COMPILED_DOC_STRING:
|
173
|
1040 return compiled_function_documentation (b);
|
0
|
1041 case COMPILED_DOMAIN:
|
173
|
1042 return compiled_function_domain (b);
|
0
|
1043 case COMPILED_INTERACTIVE:
|
|
1044 if (b->flags.interactivep)
|
173
|
1045 return compiled_function_interactive (b);
|
0
|
1046 /* if we return nil, can't tell interactive with no args
|
|
1047 from noninteractive. */
|
|
1048 goto lose;
|
|
1049 default:
|
|
1050 goto lose;
|
|
1051 }
|
|
1052 }
|
|
1053 }
|
|
1054 #endif /* LOSING_BYTECODE */
|
|
1055 else
|
|
1056 {
|
272
|
1057 check_losing_bytecode ("elt", sequence);
|
|
1058 sequence = wrong_type_argument (Qsequencep, sequence);
|
0
|
1059 goto retry;
|
|
1060 }
|
|
1061 }
|
|
1062
|
20
|
1063 DEFUN ("member", Fmember, 2, 2, 0, /*
|
0
|
1064 Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
|
|
1065 The value is actually the tail of LIST whose car is ELT.
|
20
|
1066 */
|
|
1067 (elt, list))
|
0
|
1068 {
|
272
|
1069 REGISTER Lisp_Object tail;
|
|
1070 LIST_LOOP (tail, list)
|
0
|
1071 {
|
272
|
1072 CONCHECK_CONS (tail);
|
|
1073 if (internal_equal (elt, XCAR (tail), 0))
|
|
1074 return tail;
|
0
|
1075 QUIT;
|
|
1076 }
|
|
1077 return Qnil;
|
|
1078 }
|
|
1079
|
70
|
1080 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
|
|
1081 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
|
|
1082 The value is actually the tail of LIST whose car is ELT.
|
|
1083 This function is provided only for byte-code compatibility with v19.
|
|
1084 Do not use it.
|
|
1085 */
|
|
1086 (elt, list))
|
|
1087 {
|
272
|
1088 REGISTER Lisp_Object tail;
|
|
1089 LIST_LOOP (tail, list)
|
70
|
1090 {
|
272
|
1091 CONCHECK_CONS (tail);
|
|
1092 if (internal_old_equal (elt, XCAR (tail), 0))
|
|
1093 return tail;
|
70
|
1094 QUIT;
|
|
1095 }
|
|
1096 return Qnil;
|
|
1097 }
|
|
1098
|
20
|
1099 DEFUN ("memq", Fmemq, 2, 2, 0, /*
|
0
|
1100 Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
|
|
1101 The value is actually the tail of LIST whose car is ELT.
|
20
|
1102 */
|
|
1103 (elt, list))
|
0
|
1104 {
|
272
|
1105 REGISTER Lisp_Object tail;
|
|
1106 LIST_LOOP (tail, list)
|
0
|
1107 {
|
272
|
1108 REGISTER Lisp_Object tem;
|
|
1109 CONCHECK_CONS (tail);
|
|
1110 if (tem = XCAR (tail), EQ_WITH_EBOLA_NOTICE (elt, tem))
|
|
1111 return tail;
|
70
|
1112 QUIT;
|
|
1113 }
|
|
1114 return Qnil;
|
|
1115 }
|
|
1116
|
|
1117 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
|
|
1118 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
|
|
1119 The value is actually the tail of LIST whose car is ELT.
|
|
1120 This function is provided only for byte-code compatibility with v19.
|
|
1121 Do not use it.
|
|
1122 */
|
|
1123 (elt, list))
|
|
1124 {
|
272
|
1125 REGISTER Lisp_Object tail;
|
|
1126 LIST_LOOP (tail, list)
|
70
|
1127 {
|
272
|
1128 REGISTER Lisp_Object tem;
|
|
1129 CONCHECK_CONS (tail);
|
|
1130 if (tem = XCAR (tail), HACKEQ_UNSAFE (elt, tem))
|
|
1131 return tail;
|
0
|
1132 QUIT;
|
|
1133 }
|
|
1134 return Qnil;
|
|
1135 }
|
|
1136
|
|
1137 Lisp_Object
|
|
1138 memq_no_quit (Lisp_Object elt, Lisp_Object list)
|
|
1139 {
|
272
|
1140 REGISTER Lisp_Object tail;
|
0
|
1141 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1142 {
|
272
|
1143 REGISTER Lisp_Object tem;
|
|
1144 if (tem = XCAR (tail), EQ_WITH_EBOLA_NOTICE (elt, tem))
|
|
1145 return tail;
|
0
|
1146 }
|
|
1147 return Qnil;
|
|
1148 }
|
|
1149
|
20
|
1150 DEFUN ("assoc", Fassoc, 2, 2, 0, /*
|
0
|
1151 Return non-nil if KEY is `equal' to the car of an element of LIST.
|
|
1152 The value is actually the element of LIST whose car equals KEY.
|
20
|
1153 */
|
|
1154 (key, list))
|
0
|
1155 {
|
|
1156 /* This function can GC. */
|
272
|
1157 REGISTER Lisp_Object tail;
|
|
1158 LIST_LOOP (tail, list)
|
0
|
1159 {
|
272
|
1160 REGISTER Lisp_Object elt;
|
|
1161 CONCHECK_CONS (tail);
|
|
1162 elt = XCAR (tail);
|
|
1163 if (CONSP (elt) && internal_equal (XCAR (elt), key, 0))
|
195
|
1164 return elt;
|
0
|
1165 QUIT;
|
|
1166 }
|
|
1167 return Qnil;
|
|
1168 }
|
|
1169
|
70
|
1170 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
|
|
1171 Return non-nil if KEY is `old-equal' to the car of an element of LIST.
|
|
1172 The value is actually the element of LIST whose car equals KEY.
|
|
1173 */
|
|
1174 (key, list))
|
|
1175 {
|
|
1176 /* This function can GC. */
|
272
|
1177 REGISTER Lisp_Object tail;
|
|
1178 LIST_LOOP (tail, list)
|
70
|
1179 {
|
272
|
1180 REGISTER Lisp_Object elt;
|
|
1181 CONCHECK_CONS (tail);
|
|
1182 elt = XCAR (tail);
|
|
1183 if (CONSP (elt) && internal_old_equal (XCAR (elt), key, 0))
|
195
|
1184 return elt;
|
70
|
1185 QUIT;
|
|
1186 }
|
|
1187 return Qnil;
|
|
1188 }
|
|
1189
|
0
|
1190 Lisp_Object
|
|
1191 assoc_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1192 {
|
|
1193 int speccount = specpdl_depth ();
|
|
1194 specbind (Qinhibit_quit, Qt);
|
149
|
1195 return unbind_to (speccount, Fassoc (key, list));
|
0
|
1196 }
|
|
1197
|
20
|
1198 DEFUN ("assq", Fassq, 2, 2, 0, /*
|
0
|
1199 Return non-nil if KEY is `eq' to the car of an element of LIST.
|
|
1200 The value is actually the element of LIST whose car is KEY.
|
|
1201 Elements of LIST that are not conses are ignored.
|
20
|
1202 */
|
|
1203 (key, list))
|
0
|
1204 {
|
272
|
1205 REGISTER Lisp_Object tail;
|
|
1206 LIST_LOOP (tail, list)
|
0
|
1207 {
|
272
|
1208 REGISTER Lisp_Object elt, tem;
|
|
1209 CONCHECK_CONS (tail);
|
|
1210 elt = XCAR (tail);
|
|
1211 if (CONSP (elt) && (tem = XCAR (elt), EQ_WITH_EBOLA_NOTICE (key, tem)))
|
195
|
1212 return elt;
|
70
|
1213 QUIT;
|
|
1214 }
|
|
1215 return Qnil;
|
|
1216 }
|
|
1217
|
|
1218 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
|
|
1219 Return non-nil if KEY is `old-eq' to the car of an element of LIST.
|
|
1220 The value is actually the element of LIST whose car is KEY.
|
|
1221 Elements of LIST that are not conses are ignored.
|
|
1222 This function is provided only for byte-code compatibility with v19.
|
|
1223 Do not use it.
|
|
1224 */
|
|
1225 (key, list))
|
|
1226 {
|
272
|
1227 REGISTER Lisp_Object tail;
|
|
1228 LIST_LOOP (tail, list)
|
70
|
1229 {
|
272
|
1230 REGISTER Lisp_Object elt, tem;
|
|
1231 CONCHECK_CONS (tail);
|
|
1232 elt = XCAR (tail);
|
|
1233 if (CONSP (elt) && (tem = XCAR (elt), HACKEQ_UNSAFE (key, tem)))
|
195
|
1234 return elt;
|
0
|
1235 QUIT;
|
|
1236 }
|
|
1237 return Qnil;
|
|
1238 }
|
|
1239
|
|
1240 /* Like Fassq but never report an error and do not allow quits.
|
|
1241 Use only on lists known never to be circular. */
|
|
1242
|
|
1243 Lisp_Object
|
|
1244 assq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1245 {
|
|
1246 /* This cannot GC. */
|
272
|
1247 REGISTER Lisp_Object tail;
|
0
|
1248 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1249 {
|
272
|
1250 REGISTER Lisp_Object tem, elt;
|
0
|
1251 elt = XCAR (tail);
|
272
|
1252 if (CONSP (elt) && (tem = XCAR (elt), EQ_WITH_EBOLA_NOTICE (key, tem)))
|
|
1253 return elt;
|
0
|
1254 }
|
|
1255 return Qnil;
|
|
1256 }
|
|
1257
|
20
|
1258 DEFUN ("rassoc", Frassoc, 2, 2, 0, /*
|
0
|
1259 Return non-nil if KEY is `equal' to the cdr of an element of LIST.
|
|
1260 The value is actually the element of LIST whose cdr equals KEY.
|
20
|
1261 */
|
|
1262 (key, list))
|
0
|
1263 {
|
|
1264 REGISTER Lisp_Object tail;
|
272
|
1265 LIST_LOOP (tail, list)
|
0
|
1266 {
|
195
|
1267 REGISTER Lisp_Object elt;
|
272
|
1268 CONCHECK_CONS (tail);
|
|
1269 elt = XCAR (tail);
|
|
1270 if (CONSP (elt) && internal_equal (XCDR (elt), key, 0))
|
195
|
1271 return elt;
|
0
|
1272 QUIT;
|
|
1273 }
|
|
1274 return Qnil;
|
|
1275 }
|
|
1276
|
70
|
1277 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
|
|
1278 Return non-nil if KEY is `old-equal' to the cdr of an element of LIST.
|
|
1279 The value is actually the element of LIST whose cdr equals KEY.
|
|
1280 */
|
|
1281 (key, list))
|
|
1282 {
|
|
1283 REGISTER Lisp_Object tail;
|
272
|
1284 LIST_LOOP (tail, list)
|
70
|
1285 {
|
195
|
1286 REGISTER Lisp_Object elt;
|
272
|
1287 CONCHECK_CONS (tail);
|
|
1288 elt = XCAR (tail);
|
|
1289 if (CONSP (elt) && internal_old_equal (XCDR (elt), key, 0))
|
195
|
1290 return elt;
|
70
|
1291 QUIT;
|
|
1292 }
|
|
1293 return Qnil;
|
|
1294 }
|
|
1295
|
20
|
1296 DEFUN ("rassq", Frassq, 2, 2, 0, /*
|
0
|
1297 Return non-nil if KEY is `eq' to the cdr of an element of LIST.
|
|
1298 The value is actually the element of LIST whose cdr is KEY.
|
20
|
1299 */
|
|
1300 (key, list))
|
0
|
1301 {
|
272
|
1302 REGISTER Lisp_Object tail;
|
|
1303 LIST_LOOP (tail, list)
|
0
|
1304 {
|
272
|
1305 REGISTER Lisp_Object elt, tem;
|
|
1306 CONCHECK_CONS (tail);
|
|
1307 elt = XCAR (tail);
|
|
1308 if (CONSP (elt) && (tem = XCDR (elt), EQ_WITH_EBOLA_NOTICE (key, tem)))
|
195
|
1309 return elt;
|
70
|
1310 QUIT;
|
|
1311 }
|
|
1312 return Qnil;
|
|
1313 }
|
|
1314
|
|
1315 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /*
|
|
1316 Return non-nil if KEY is `old-eq' to the cdr of an element of LIST.
|
|
1317 The value is actually the element of LIST whose cdr is KEY.
|
|
1318 */
|
|
1319 (key, list))
|
|
1320 {
|
272
|
1321 REGISTER Lisp_Object tail;
|
|
1322 LIST_LOOP (tail, list)
|
70
|
1323 {
|
272
|
1324 REGISTER Lisp_Object elt, tem;
|
|
1325 CONCHECK_CONS (tail);
|
|
1326 elt = XCAR (tail);
|
|
1327 if (CONSP (elt) && (tem = XCDR (elt), HACKEQ_UNSAFE (key, tem)))
|
195
|
1328 return elt;
|
0
|
1329 QUIT;
|
|
1330 }
|
|
1331 return Qnil;
|
|
1332 }
|
|
1333
|
|
1334 Lisp_Object
|
|
1335 rassq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1336 {
|
272
|
1337 REGISTER Lisp_Object tail;
|
0
|
1338 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1339 {
|
272
|
1340 REGISTER Lisp_Object elt, tem;
|
0
|
1341 elt = XCAR (tail);
|
272
|
1342 if (CONSP (elt) && (tem = XCDR (elt), EQ_WITH_EBOLA_NOTICE (key, tem)))
|
|
1343 return elt;
|
0
|
1344 }
|
|
1345 return Qnil;
|
|
1346 }
|
|
1347
|
|
1348
|
20
|
1349 DEFUN ("delete", Fdelete, 2, 2, 0, /*
|
0
|
1350 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1351 The modified LIST is returned. Comparison is done with `equal'.
|
|
1352 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1353 effect; therefore, write `(setq foo (delete element foo))' to be sure
|
|
1354 of changing the value of `foo'.
|
201
|
1355 Also see: `remove'.
|
20
|
1356 */
|
|
1357 (elt, list))
|
0
|
1358 {
|
272
|
1359 REGISTER Lisp_Object tail = list;
|
|
1360 REGISTER Lisp_Object prev = Qnil;
|
|
1361
|
0
|
1362 while (!NILP (tail))
|
|
1363 {
|
272
|
1364 CONCHECK_CONS (tail);
|
|
1365 if (internal_equal (elt, XCAR (tail), 0))
|
0
|
1366 {
|
|
1367 if (NILP (prev))
|
272
|
1368 list = XCDR (tail);
|
0
|
1369 else
|
272
|
1370 XCDR (prev) = XCDR (tail);
|
0
|
1371 }
|
|
1372 else
|
|
1373 prev = tail;
|
272
|
1374 tail = XCDR (tail);
|
0
|
1375 QUIT;
|
|
1376 }
|
|
1377 return list;
|
|
1378 }
|
|
1379
|
70
|
1380 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
|
|
1381 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1382 The modified LIST is returned. Comparison is done with `old-equal'.
|
|
1383 If the first member of LIST is ELT, there is no way to remove it by side
|
272
|
1384 effect; therefore, write `(setq foo (old-delete element foo))' to be sure
|
70
|
1385 of changing the value of `foo'.
|
|
1386 */
|
|
1387 (elt, list))
|
|
1388 {
|
272
|
1389 REGISTER Lisp_Object tail = list;
|
|
1390 REGISTER Lisp_Object prev = Qnil;
|
|
1391
|
70
|
1392 while (!NILP (tail))
|
|
1393 {
|
272
|
1394 CONCHECK_CONS (tail);
|
|
1395 if (internal_old_equal (elt, XCAR (tail), 0))
|
70
|
1396 {
|
|
1397 if (NILP (prev))
|
272
|
1398 list = XCDR (tail);
|
70
|
1399 else
|
272
|
1400 XCDR (prev) = XCDR (tail);
|
70
|
1401 }
|
|
1402 else
|
|
1403 prev = tail;
|
272
|
1404 tail = XCDR (tail);
|
70
|
1405 QUIT;
|
|
1406 }
|
|
1407 return list;
|
|
1408 }
|
|
1409
|
20
|
1410 DEFUN ("delq", Fdelq, 2, 2, 0, /*
|
0
|
1411 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1412 The modified LIST is returned. Comparison is done with `eq'.
|
|
1413 If the first member of LIST is ELT, there is no way to remove it by side
|
|
1414 effect; therefore, write `(setq foo (delq element foo))' to be sure of
|
|
1415 changing the value of `foo'.
|
20
|
1416 */
|
|
1417 (elt, list))
|
0
|
1418 {
|
272
|
1419 REGISTER Lisp_Object tail = list;
|
|
1420 REGISTER Lisp_Object prev = Qnil;
|
|
1421
|
0
|
1422 while (!NILP (tail))
|
|
1423 {
|
272
|
1424 REGISTER Lisp_Object tem;
|
|
1425 CONCHECK_CONS (tail);
|
|
1426 if (tem = XCAR (tail), EQ_WITH_EBOLA_NOTICE (elt, tem))
|
70
|
1427 {
|
|
1428 if (NILP (prev))
|
272
|
1429 list = XCDR (tail);
|
70
|
1430 else
|
272
|
1431 XCDR (prev) = XCDR (tail);
|
70
|
1432 }
|
|
1433 else
|
|
1434 prev = tail;
|
272
|
1435 tail = XCDR (tail);
|
70
|
1436 QUIT;
|
|
1437 }
|
|
1438 return list;
|
|
1439 }
|
|
1440
|
|
1441 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
|
|
1442 Delete by side effect any occurrences of ELT as a member of LIST.
|
|
1443 The modified LIST is returned. Comparison is done with `old-eq'.
|
|
1444 If the first member of LIST is ELT, there is no way to remove it by side
|
272
|
1445 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of
|
70
|
1446 changing the value of `foo'.
|
|
1447 */
|
|
1448 (elt, list))
|
|
1449 {
|
272
|
1450 REGISTER Lisp_Object tail = list;
|
|
1451 REGISTER Lisp_Object prev = Qnil;
|
|
1452
|
70
|
1453 while (!NILP (tail))
|
|
1454 {
|
272
|
1455 REGISTER Lisp_Object tem;
|
|
1456 CONCHECK_CONS (tail);
|
|
1457 if (tem = XCAR (tail), HACKEQ_UNSAFE (elt, tem))
|
0
|
1458 {
|
|
1459 if (NILP (prev))
|
272
|
1460 list = XCDR (tail);
|
0
|
1461 else
|
272
|
1462 XCDR (prev) = XCDR (tail);
|
0
|
1463 }
|
|
1464 else
|
|
1465 prev = tail;
|
272
|
1466 tail = XCDR (tail);
|
0
|
1467 QUIT;
|
|
1468 }
|
|
1469 return list;
|
|
1470 }
|
|
1471
|
|
1472 /* no quit, no errors; be careful */
|
|
1473
|
|
1474 Lisp_Object
|
|
1475 delq_no_quit (Lisp_Object elt, Lisp_Object list)
|
|
1476 {
|
272
|
1477 REGISTER Lisp_Object tail = list;
|
|
1478 REGISTER Lisp_Object prev = Qnil;
|
|
1479
|
0
|
1480 while (CONSP (tail))
|
|
1481 {
|
272
|
1482 REGISTER Lisp_Object tem;
|
|
1483 if (tem = XCAR (tail), EQ_WITH_EBOLA_NOTICE (elt, tem))
|
0
|
1484 {
|
|
1485 if (NILP (prev))
|
|
1486 list = XCDR (tail);
|
|
1487 else
|
|
1488 XCDR (prev) = XCDR (tail);
|
|
1489 }
|
|
1490 else
|
|
1491 prev = tail;
|
|
1492 tail = XCDR (tail);
|
|
1493 }
|
|
1494 return list;
|
|
1495 }
|
|
1496
|
|
1497 /* Be VERY careful with this. This is like delq_no_quit() but
|
|
1498 also calls free_cons() on the removed conses. You must be SURE
|
|
1499 that no pointers to the freed conses remain around (e.g.
|
|
1500 someone else is pointing to part of the list). This function
|
|
1501 is useful on internal lists that are used frequently and where
|
|
1502 the actual list doesn't escape beyond known code bounds. */
|
|
1503
|
|
1504 Lisp_Object
|
|
1505 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list)
|
|
1506 {
|
272
|
1507 REGISTER Lisp_Object tail = list;
|
|
1508 REGISTER Lisp_Object prev = Qnil;
|
|
1509 struct Lisp_Cons *cons_to_free = NULL;
|
|
1510
|
0
|
1511 while (CONSP (tail))
|
|
1512 {
|
272
|
1513 REGISTER Lisp_Object tem;
|
|
1514 if (tem = XCAR (tail), EQ_WITH_EBOLA_NOTICE (elt, tem))
|
0
|
1515 {
|
|
1516 if (NILP (prev))
|
|
1517 list = XCDR (tail);
|
|
1518 else
|
|
1519 XCDR (prev) = XCDR (tail);
|
272
|
1520 cons_to_free = XCONS (tail);
|
0
|
1521 }
|
|
1522 else
|
|
1523 prev = tail;
|
|
1524 tail = XCDR (tail);
|
272
|
1525 if (cons_to_free)
|
|
1526 {
|
|
1527 free_cons (cons_to_free);
|
|
1528 cons_to_free = NULL;
|
|
1529 }
|
0
|
1530 }
|
|
1531 return list;
|
|
1532 }
|
|
1533
|
20
|
1534 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /*
|
0
|
1535 Delete by side effect any elements of LIST whose car is `equal' to KEY.
|
|
1536 The modified LIST is returned. If the first member of LIST has a car
|
|
1537 that is `equal' to KEY, there is no way to remove it by side effect;
|
|
1538 therefore, write `(setq foo (remassoc key foo))' to be sure of changing
|
|
1539 the value of `foo'.
|
20
|
1540 */
|
|
1541 (key, list))
|
0
|
1542 {
|
272
|
1543 REGISTER Lisp_Object tail = list;
|
|
1544 REGISTER Lisp_Object prev = Qnil;
|
|
1545
|
0
|
1546 while (!NILP (tail))
|
|
1547 {
|
272
|
1548 REGISTER Lisp_Object elt;
|
|
1549 CONCHECK_CONS (tail);
|
|
1550 elt = XCAR (tail);
|
195
|
1551 if (CONSP (elt) && internal_equal (key, XCAR (elt), 0))
|
0
|
1552 {
|
|
1553 if (NILP (prev))
|
272
|
1554 list = XCDR (tail);
|
0
|
1555 else
|
272
|
1556 XCDR (prev) = XCDR (tail);
|
0
|
1557 }
|
|
1558 else
|
|
1559 prev = tail;
|
272
|
1560 tail = XCDR (tail);
|
0
|
1561 QUIT;
|
|
1562 }
|
|
1563 return list;
|
|
1564 }
|
|
1565
|
|
1566 Lisp_Object
|
|
1567 remassoc_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1568 {
|
|
1569 int speccount = specpdl_depth ();
|
|
1570 specbind (Qinhibit_quit, Qt);
|
149
|
1571 return unbind_to (speccount, Fremassoc (key, list));
|
0
|
1572 }
|
|
1573
|
20
|
1574 DEFUN ("remassq", Fremassq, 2, 2, 0, /*
|
0
|
1575 Delete by side effect any elements of LIST whose car is `eq' to KEY.
|
|
1576 The modified LIST is returned. If the first member of LIST has a car
|
|
1577 that is `eq' to KEY, there is no way to remove it by side effect;
|
|
1578 therefore, write `(setq foo (remassq key foo))' to be sure of changing
|
|
1579 the value of `foo'.
|
20
|
1580 */
|
|
1581 (key, list))
|
0
|
1582 {
|
272
|
1583 REGISTER Lisp_Object tail = list;
|
|
1584 REGISTER Lisp_Object prev = Qnil;
|
|
1585
|
0
|
1586 while (!NILP (tail))
|
|
1587 {
|
272
|
1588 REGISTER Lisp_Object elt, tem;
|
|
1589 CONCHECK_CONS (tail);
|
|
1590 elt = XCAR (tail);
|
|
1591 if (CONSP (elt) && (tem = XCAR (elt), EQ_WITH_EBOLA_NOTICE (key, tem)))
|
0
|
1592 {
|
|
1593 if (NILP (prev))
|
272
|
1594 list = XCDR (tail);
|
0
|
1595 else
|
272
|
1596 XCDR (prev) = XCDR (tail);
|
0
|
1597 }
|
|
1598 else
|
|
1599 prev = tail;
|
272
|
1600 tail = XCDR (tail);
|
0
|
1601 QUIT;
|
|
1602 }
|
|
1603 return list;
|
|
1604 }
|
|
1605
|
|
1606 /* no quit, no errors; be careful */
|
|
1607
|
|
1608 Lisp_Object
|
|
1609 remassq_no_quit (Lisp_Object key, Lisp_Object list)
|
|
1610 {
|
272
|
1611 REGISTER Lisp_Object tail = list;
|
|
1612 REGISTER Lisp_Object prev = Qnil;
|
|
1613
|
0
|
1614 while (CONSP (tail))
|
|
1615 {
|
272
|
1616 REGISTER Lisp_Object elt, tem;
|
|
1617 elt = XCAR (tail);
|
|
1618 if (CONSP (elt) && (tem = XCAR (elt), EQ_WITH_EBOLA_NOTICE (key, tem)))
|
0
|
1619 {
|
|
1620 if (NILP (prev))
|
|
1621 list = XCDR (tail);
|
|
1622 else
|
|
1623 XCDR (prev) = XCDR (tail);
|
|
1624 }
|
|
1625 else
|
|
1626 prev = tail;
|
|
1627 tail = XCDR (tail);
|
|
1628 }
|
|
1629 return list;
|
|
1630 }
|
|
1631
|
20
|
1632 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /*
|
0
|
1633 Delete by side effect any elements of LIST whose cdr is `equal' to VALUE.
|
|
1634 The modified LIST is returned. If the first member of LIST has a car
|
|
1635 that is `equal' to VALUE, there is no way to remove it by side effect;
|
|
1636 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing
|
|
1637 the value of `foo'.
|
20
|
1638 */
|
|
1639 (value, list))
|
0
|
1640 {
|
272
|
1641 REGISTER Lisp_Object tail = list;
|
|
1642 REGISTER Lisp_Object prev = Qnil;
|
|
1643
|
0
|
1644 while (!NILP (tail))
|
|
1645 {
|
272
|
1646 REGISTER Lisp_Object elt;
|
|
1647 CONCHECK_CONS (tail);
|
|
1648 elt = XCAR (tail);
|
195
|
1649 if (CONSP (elt) && internal_equal (value, XCDR (elt), 0))
|
0
|
1650 {
|
|
1651 if (NILP (prev))
|
272
|
1652 list = XCDR (tail);
|
0
|
1653 else
|
272
|
1654 XCDR (prev) = XCDR (tail);
|
0
|
1655 }
|
|
1656 else
|
|
1657 prev = tail;
|
272
|
1658 tail = XCDR (tail);
|
0
|
1659 QUIT;
|
|
1660 }
|
|
1661 return list;
|
|
1662 }
|
|
1663
|
20
|
1664 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /*
|
0
|
1665 Delete by side effect any elements of LIST whose cdr is `eq' to VALUE.
|
|
1666 The modified LIST is returned. If the first member of LIST has a car
|
|
1667 that is `eq' to VALUE, there is no way to remove it by side effect;
|
|
1668 therefore, write `(setq foo (remrassq value foo))' to be sure of changing
|
|
1669 the value of `foo'.
|
20
|
1670 */
|
|
1671 (value, list))
|
0
|
1672 {
|
272
|
1673 REGISTER Lisp_Object tail = list;
|
|
1674 REGISTER Lisp_Object prev = Qnil;
|
|
1675
|
0
|
1676 while (!NILP (tail))
|
|
1677 {
|
272
|
1678 REGISTER Lisp_Object elt, tem;
|
|
1679 CONCHECK_CONS (tail);
|
|
1680 elt = XCAR (tail);
|
|
1681 if (CONSP (elt) && (tem = XCAR (elt), EQ_WITH_EBOLA_NOTICE (value, tem)))
|
0
|
1682 {
|
|
1683 if (NILP (prev))
|
272
|
1684 list = XCDR (tail);
|
0
|
1685 else
|
272
|
1686 XCDR (prev) = XCDR (tail);
|
0
|
1687 }
|
|
1688 else
|
|
1689 prev = tail;
|
272
|
1690 tail = XCDR (tail);
|
0
|
1691 QUIT;
|
|
1692 }
|
|
1693 return list;
|
|
1694 }
|
|
1695
|
|
1696 /* no quit, no errors; be careful */
|
|
1697
|
|
1698 Lisp_Object
|
|
1699 remrassq_no_quit (Lisp_Object value, Lisp_Object list)
|
|
1700 {
|
272
|
1701 REGISTER Lisp_Object tail = list;
|
|
1702 REGISTER Lisp_Object prev = Qnil;
|
|
1703
|
0
|
1704 while (CONSP (tail))
|
|
1705 {
|
272
|
1706 REGISTER Lisp_Object elt, tem;
|
|
1707 elt = XCAR (tail);
|
|
1708 if (CONSP (elt) && (tem = XCAR (elt), EQ_WITH_EBOLA_NOTICE (value, tem)))
|
0
|
1709 {
|
|
1710 if (NILP (prev))
|
|
1711 list = XCDR (tail);
|
|
1712 else
|
|
1713 XCDR (prev) = XCDR (tail);
|
|
1714 }
|
|
1715 else
|
|
1716 prev = tail;
|
|
1717 tail = XCDR (tail);
|
|
1718 }
|
|
1719 return list;
|
|
1720 }
|
|
1721
|
20
|
1722 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /*
|
272
|
1723 Reverse LIST by destructively modifying cdr pointers.
|
|
1724 Return the beginning of the reversed list.
|
201
|
1725 Also see: `reverse'.
|
20
|
1726 */
|
|
1727 (list))
|
0
|
1728 {
|
|
1729 struct gcpro gcpro1, gcpro2;
|
272
|
1730 REGISTER Lisp_Object prev = Qnil;
|
|
1731 REGISTER Lisp_Object tail = list;
|
0
|
1732
|
|
1733 /* We gcpro our args; see `nconc' */
|
|
1734 GCPRO2 (prev, tail);
|
|
1735 while (!NILP (tail))
|
|
1736 {
|
272
|
1737 REGISTER Lisp_Object next;
|
0
|
1738 QUIT;
|
272
|
1739 CONCHECK_CONS (tail);
|
165
|
1740 next = XCDR (tail);
|
|
1741 XCDR (tail) = prev;
|
0
|
1742 prev = tail;
|
|
1743 tail = next;
|
|
1744 }
|
|
1745 UNGCPRO;
|
|
1746 return prev;
|
|
1747 }
|
|
1748
|
20
|
1749 DEFUN ("reverse", Freverse, 1, 1, 0, /*
|
272
|
1750 Reverse LIST, copying. Return the beginning of the reversed list.
|
0
|
1751 See also the function `nreverse', which is used more often.
|
20
|
1752 */
|
|
1753 (list))
|
0
|
1754 {
|
272
|
1755 REGISTER Lisp_Object tail;
|
|
1756 Lisp_Object new = Qnil;
|
|
1757
|
|
1758 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
1759 {
|
|
1760 new = Fcons (XCAR (tail), new);
|
|
1761 QUIT;
|
|
1762 }
|
|
1763 if (!NILP (tail))
|
|
1764 dead_wrong_type_argument (Qlistp, tail);
|
165
|
1765 return new;
|
0
|
1766 }
|
|
1767
|
173
|
1768 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1769 Lisp_Object lisp_arg,
|
0
|
1770 int (*pred_fn) (Lisp_Object, Lisp_Object,
|
|
1771 Lisp_Object lisp_arg));
|
|
1772
|
|
1773 Lisp_Object
|
|
1774 list_sort (Lisp_Object list,
|
173
|
1775 Lisp_Object lisp_arg,
|
0
|
1776 int (*pred_fn) (Lisp_Object, Lisp_Object,
|
|
1777 Lisp_Object lisp_arg))
|
|
1778 {
|
|
1779 struct gcpro gcpro1, gcpro2, gcpro3;
|
272
|
1780 Lisp_Object back, tem;
|
|
1781 Lisp_Object front = list;
|
|
1782 Lisp_Object len = Flength (list);
|
|
1783 int length = XINT (len);
|
|
1784
|
0
|
1785 if (length < 2)
|
|
1786 return list;
|
|
1787
|
|
1788 XSETINT (len, (length / 2) - 1);
|
|
1789 tem = Fnthcdr (len, list);
|
|
1790 back = Fcdr (tem);
|
|
1791 Fsetcdr (tem, Qnil);
|
|
1792
|
|
1793 GCPRO3 (front, back, lisp_arg);
|
|
1794 front = list_sort (front, lisp_arg, pred_fn);
|
|
1795 back = list_sort (back, lisp_arg, pred_fn);
|
|
1796 UNGCPRO;
|
|
1797 return list_merge (front, back, lisp_arg, pred_fn);
|
|
1798 }
|
|
1799
|
|
1800
|
|
1801 static int
|
173
|
1802 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2,
|
0
|
1803 Lisp_Object pred)
|
|
1804 {
|
|
1805 Lisp_Object tmp;
|
|
1806
|
|
1807 /* prevents the GC from happening in call2 */
|
|
1808 int speccount = specpdl_depth ();
|
|
1809 /* Emacs' GC doesn't actually relocate pointers, so this probably
|
|
1810 isn't strictly necessary */
|
|
1811 record_unwind_protect (restore_gc_inhibit,
|
|
1812 make_int (gc_currently_forbidden));
|
|
1813 gc_currently_forbidden = 1;
|
|
1814 tmp = call2 (pred, obj1, obj2);
|
|
1815 unbind_to (speccount, Qnil);
|
|
1816
|
173
|
1817 if (NILP (tmp))
|
0
|
1818 return -1;
|
|
1819 else
|
|
1820 return 1;
|
|
1821 }
|
|
1822
|
20
|
1823 DEFUN ("sort", Fsort, 2, 2, 0, /*
|
0
|
1824 Sort LIST, stably, comparing elements using PREDICATE.
|
|
1825 Returns the sorted list. LIST is modified by side effects.
|
|
1826 PREDICATE is called with two elements of LIST, and should return T
|
185
|
1827 if the first element is "less" than the second.
|
20
|
1828 */
|
|
1829 (list, pred))
|
0
|
1830 {
|
|
1831 return list_sort (list, pred, merge_pred_function);
|
|
1832 }
|
|
1833
|
|
1834 Lisp_Object
|
173
|
1835 merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
0
|
1836 Lisp_Object pred)
|
|
1837 {
|
|
1838 return list_merge (org_l1, org_l2, pred, merge_pred_function);
|
|
1839 }
|
|
1840
|
|
1841
|
|
1842 static Lisp_Object
|
173
|
1843 list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
|
|
1844 Lisp_Object lisp_arg,
|
0
|
1845 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg))
|
|
1846 {
|
|
1847 Lisp_Object value;
|
|
1848 Lisp_Object tail;
|
|
1849 Lisp_Object tem;
|
|
1850 Lisp_Object l1, l2;
|
|
1851 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1852
|
|
1853 l1 = org_l1;
|
|
1854 l2 = org_l2;
|
|
1855 tail = Qnil;
|
|
1856 value = Qnil;
|
|
1857
|
|
1858 /* It is sufficient to protect org_l1 and org_l2.
|
|
1859 When l1 and l2 are updated, we copy the new values
|
|
1860 back into the org_ vars. */
|
173
|
1861
|
0
|
1862 GCPRO4 (org_l1, org_l2, lisp_arg, value);
|
|
1863
|
|
1864 while (1)
|
|
1865 {
|
|
1866 if (NILP (l1))
|
|
1867 {
|
|
1868 UNGCPRO;
|
|
1869 if (NILP (tail))
|
|
1870 return l2;
|
|
1871 Fsetcdr (tail, l2);
|
|
1872 return value;
|
|
1873 }
|
|
1874 if (NILP (l2))
|
|
1875 {
|
|
1876 UNGCPRO;
|
|
1877 if (NILP (tail))
|
|
1878 return l1;
|
|
1879 Fsetcdr (tail, l1);
|
|
1880 return value;
|
|
1881 }
|
|
1882
|
|
1883 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0)
|
|
1884 {
|
|
1885 tem = l1;
|
|
1886 l1 = Fcdr (l1);
|
|
1887 org_l1 = l1;
|
|
1888 }
|
|
1889 else
|
|
1890 {
|
|
1891 tem = l2;
|
|
1892 l2 = Fcdr (l2);
|
|
1893 org_l2 = l2;
|
|
1894 }
|
|
1895 if (NILP (tail))
|
|
1896 value = tem;
|
|
1897 else
|
|
1898 Fsetcdr (tail, tem);
|
|
1899 tail = tem;
|
|
1900 }
|
|
1901 }
|
|
1902
|
|
1903
|
|
1904 /************************************************************************/
|
|
1905 /* property-list functions */
|
|
1906 /************************************************************************/
|
|
1907
|
|
1908 /* For properties of text, we need to do order-insensitive comparison of
|
|
1909 plists. That is, we need to compare two plists such that they are the
|
|
1910 same if they have the same set of keys, and equivalent values.
|
|
1911 So (a 1 b 2) would be equal to (b 2 a 1).
|
|
1912
|
|
1913 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc.
|
|
1914 LAXP means use `equal' for comparisons.
|
|
1915 */
|
173
|
1916 int
|
0
|
1917 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present,
|
|
1918 int laxp, int depth)
|
|
1919 {
|
|
1920 int eqp = (depth == -1); /* -1 as depth means us eq, not equal. */
|
|
1921 int la, lb, m, i, fill;
|
|
1922 Lisp_Object *keys, *vals;
|
|
1923 char *flags;
|
|
1924 Lisp_Object rest;
|
|
1925
|
|
1926 if (NILP (a) && NILP (b))
|
|
1927 return 0;
|
|
1928
|
|
1929 Fcheck_valid_plist (a);
|
|
1930 Fcheck_valid_plist (b);
|
|
1931
|
|
1932 la = XINT (Flength (a));
|
|
1933 lb = XINT (Flength (b));
|
|
1934 m = (la > lb ? la : lb);
|
|
1935 fill = 0;
|
185
|
1936 keys = alloca_array (Lisp_Object, m);
|
|
1937 vals = alloca_array (Lisp_Object, m);
|
|
1938 flags = alloca_array (char, m);
|
0
|
1939
|
|
1940 /* First extract the pairs from A. */
|
|
1941 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest)))
|
|
1942 {
|
|
1943 Lisp_Object k = XCAR (rest);
|
|
1944 Lisp_Object v = XCAR (XCDR (rest));
|
|
1945 /* Maybe be Ebolified. */
|
|
1946 if (nil_means_not_present && NILP (v)) continue;
|
|
1947 keys [fill] = k;
|
|
1948 vals [fill] = v;
|
|
1949 flags[fill] = 0;
|
|
1950 fill++;
|
|
1951 }
|
|
1952 /* Now iterate over B, and stop if we find something that's not in A,
|
|
1953 or that doesn't match. As we match, mark them. */
|
|
1954 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest)))
|
|
1955 {
|
|
1956 Lisp_Object k = XCAR (rest);
|
|
1957 Lisp_Object v = XCAR (XCDR (rest));
|
|
1958 /* Maybe be Ebolified. */
|
|
1959 if (nil_means_not_present && NILP (v)) continue;
|
|
1960 for (i = 0; i < fill; i++)
|
|
1961 {
|
|
1962 if (!laxp ? EQ (k, keys [i]) : internal_equal (k, keys [i], depth))
|
|
1963 {
|
|
1964 if ((eqp
|
70
|
1965 /* We narrowly escaped being Ebolified here. */
|
|
1966 ? !EQ_WITH_EBOLA_NOTICE (v, vals [i])
|
0
|
1967 : !internal_equal (v, vals [i], depth)))
|
|
1968 /* a property in B has a different value than in A */
|
|
1969 goto MISMATCH;
|
|
1970 flags [i] = 1;
|
|
1971 break;
|
|
1972 }
|
|
1973 }
|
|
1974 if (i == fill)
|
|
1975 /* there are some properties in B that are not in A */
|
|
1976 goto MISMATCH;
|
|
1977 }
|
|
1978 /* Now check to see that all the properties in A were also in B */
|
|
1979 for (i = 0; i < fill; i++)
|
|
1980 if (flags [i] == 0)
|
|
1981 goto MISMATCH;
|
|
1982
|
|
1983 /* Ok. */
|
|
1984 return 0;
|
|
1985
|
|
1986 MISMATCH:
|
|
1987 return 1;
|
|
1988 }
|
|
1989
|
20
|
1990 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /*
|
0
|
1991 Return non-nil if property lists A and B are `eq'.
|
|
1992 A property list is an alternating list of keywords and values.
|
|
1993 This function does order-insensitive comparisons of the property lists:
|
|
1994 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
1995 Comparison between values is done using `eq'. See also `plists-equal'.
|
|
1996 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
1997 a nil value is ignored. This feature is a virus that has infected
|
16
|
1998 old Lisp implementations, but should not be used except for backward
|
|
1999 compatibility.
|
20
|
2000 */
|
|
2001 (a, b, nil_means_not_present))
|
0
|
2002 {
|
|
2003 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1)
|
|
2004 ? Qnil : Qt);
|
|
2005 }
|
|
2006
|
20
|
2007 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /*
|
0
|
2008 Return non-nil if property lists A and B are `equal'.
|
|
2009 A property list is an alternating list of keywords and values. This
|
|
2010 function does order-insensitive comparisons of the property lists: For
|
|
2011 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2012 Comparison between values is done using `equal'. See also `plists-eq'.
|
|
2013 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2014 a nil value is ignored. This feature is a virus that has infected
|
16
|
2015 old Lisp implementations, but should not be used except for backward
|
|
2016 compatibility.
|
20
|
2017 */
|
|
2018 (a, b, nil_means_not_present))
|
0
|
2019 {
|
|
2020 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1)
|
|
2021 ? Qnil : Qt);
|
|
2022 }
|
|
2023
|
|
2024
|
20
|
2025 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /*
|
0
|
2026 Return non-nil if lax property lists A and B are `eq'.
|
|
2027 A property list is an alternating list of keywords and values.
|
|
2028 This function does order-insensitive comparisons of the property lists:
|
|
2029 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2030 Comparison between values is done using `eq'. See also `plists-equal'.
|
|
2031 A lax property list is like a regular one except that comparisons between
|
|
2032 keywords is done using `equal' instead of `eq'.
|
|
2033 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2034 a nil value is ignored. This feature is a virus that has infected
|
16
|
2035 old Lisp implementations, but should not be used except for backward
|
|
2036 compatibility.
|
20
|
2037 */
|
|
2038 (a, b, nil_means_not_present))
|
0
|
2039 {
|
|
2040 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1)
|
|
2041 ? Qnil : Qt);
|
|
2042 }
|
|
2043
|
20
|
2044 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /*
|
0
|
2045 Return non-nil if lax property lists A and B are `equal'.
|
|
2046 A property list is an alternating list of keywords and values. This
|
|
2047 function does order-insensitive comparisons of the property lists: For
|
|
2048 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
|
|
2049 Comparison between values is done using `equal'. See also `plists-eq'.
|
|
2050 A lax property list is like a regular one except that comparisons between
|
|
2051 keywords is done using `equal' instead of `eq'.
|
|
2052 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2053 a nil value is ignored. This feature is a virus that has infected
|
16
|
2054 old Lisp implementations, but should not be used except for backward
|
|
2055 compatibility.
|
20
|
2056 */
|
|
2057 (a, b, nil_means_not_present))
|
0
|
2058 {
|
|
2059 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1)
|
|
2060 ? Qnil : Qt);
|
|
2061 }
|
|
2062
|
|
2063 /* Return the value associated with key PROPERTY in property list PLIST.
|
|
2064 Return nil if key not found. This function is used for internal
|
|
2065 property lists that cannot be directly manipulated by the user.
|
|
2066 */
|
|
2067
|
|
2068 Lisp_Object
|
|
2069 internal_plist_get (Lisp_Object plist, Lisp_Object property)
|
|
2070 {
|
|
2071 Lisp_Object tail = plist;
|
|
2072
|
|
2073 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
|
|
2074 {
|
|
2075 struct Lisp_Cons *c = XCONS (tail);
|
|
2076 if (EQ (c->car, property))
|
|
2077 return XCAR (c->cdr);
|
|
2078 }
|
|
2079
|
|
2080 return Qunbound;
|
|
2081 }
|
|
2082
|
|
2083 /* Set PLIST's value for PROPERTY to VALUE. Analogous to
|
|
2084 internal_plist_get(). */
|
|
2085
|
|
2086 void
|
|
2087 internal_plist_put (Lisp_Object *plist, Lisp_Object property,
|
|
2088 Lisp_Object value)
|
|
2089 {
|
272
|
2090 Lisp_Object tail;
|
|
2091
|
|
2092 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail)))
|
0
|
2093 {
|
272
|
2094 if (EQ (XCAR (tail), property))
|
0
|
2095 {
|
272
|
2096 XCAR (XCDR (tail)) = value;
|
0
|
2097 return;
|
|
2098 }
|
|
2099 }
|
|
2100
|
|
2101 *plist = Fcons (property, Fcons (value, *plist));
|
|
2102 }
|
|
2103
|
|
2104 int
|
|
2105 internal_remprop (Lisp_Object *plist, Lisp_Object property)
|
|
2106 {
|
|
2107 Lisp_Object tail = *plist;
|
|
2108
|
|
2109 if (NILP (tail))
|
|
2110 return 0;
|
|
2111
|
|
2112 if (EQ (XCAR (tail), property))
|
|
2113 {
|
|
2114 *plist = XCDR (XCDR (tail));
|
|
2115 return 1;
|
|
2116 }
|
|
2117
|
|
2118 for (tail = XCDR (tail); !NILP (XCDR (tail));
|
|
2119 tail = XCDR (XCDR (tail)))
|
|
2120 {
|
|
2121 struct Lisp_Cons *c = XCONS (tail);
|
|
2122 if (EQ (XCAR (c->cdr), property))
|
|
2123 {
|
|
2124 c->cdr = XCDR (XCDR (c->cdr));
|
|
2125 return 1;
|
|
2126 }
|
|
2127 }
|
|
2128
|
|
2129 return 0;
|
|
2130 }
|
|
2131
|
|
2132 /* Called on a malformed property list. BADPLACE should be some
|
|
2133 place where truncating will form a good list -- i.e. we shouldn't
|
|
2134 result in a list with an odd length. */
|
|
2135
|
|
2136 static Lisp_Object
|
|
2137 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
|
|
2138 {
|
|
2139 if (ERRB_EQ (errb, ERROR_ME))
|
|
2140 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace));
|
|
2141 else
|
|
2142 {
|
|
2143 if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2144 {
|
|
2145 warn_when_safe_lispobj
|
|
2146 (Qlist, Qwarning,
|
|
2147 list2 (build_string
|
|
2148 ("Malformed property list -- list has been truncated"),
|
|
2149 *plist));
|
|
2150 *badplace = Qnil;
|
|
2151 }
|
|
2152 return Qunbound;
|
|
2153 }
|
|
2154 }
|
|
2155
|
|
2156 /* Called on a circular property list. BADPLACE should be some place
|
|
2157 where truncating will result in an even-length list, as above.
|
|
2158 If doesn't particularly matter where we truncate -- anywhere we
|
|
2159 truncate along the entire list will break the circularity, because
|
|
2160 it will create a terminus and the list currently doesn't have one.
|
|
2161 */
|
|
2162
|
|
2163 static Lisp_Object
|
|
2164 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
|
|
2165 {
|
|
2166 if (ERRB_EQ (errb, ERROR_ME))
|
|
2167 /* #### Eek, this will probably result in another error
|
|
2168 when PLIST is printed out */
|
|
2169 return Fsignal (Qcircular_property_list, list1 (*plist));
|
|
2170 else
|
|
2171 {
|
|
2172 if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2173 {
|
|
2174 warn_when_safe_lispobj
|
|
2175 (Qlist, Qwarning,
|
|
2176 list2 (build_string
|
|
2177 ("Circular property list -- list has been truncated"),
|
|
2178 *plist));
|
|
2179 *badplace = Qnil;
|
|
2180 }
|
|
2181 return Qunbound;
|
|
2182 }
|
|
2183 }
|
|
2184
|
|
2185 /* Advance the tortoise pointer by two (one iteration of a property-list
|
|
2186 loop) and the hare pointer by four and verify that no malformations
|
|
2187 or circularities exist. If so, return zero and store a value into
|
|
2188 RETVAL that should be returned by the calling function. Otherwise,
|
|
2189 return 1. See external_plist_get().
|
|
2190 */
|
|
2191
|
|
2192 static int
|
|
2193 advance_plist_pointers (Lisp_Object *plist,
|
|
2194 Lisp_Object **tortoise, Lisp_Object **hare,
|
|
2195 Error_behavior errb, Lisp_Object *retval)
|
|
2196 {
|
|
2197 int i;
|
|
2198 Lisp_Object *tortsave = *tortoise;
|
|
2199
|
|
2200 /* Note that our "fixing" may be more brutal than necessary,
|
|
2201 but it's the user's own problem, not ours. if they went in and
|
|
2202 manually fucked up a plist. */
|
173
|
2203
|
0
|
2204 for (i = 0; i < 2; i++)
|
|
2205 {
|
|
2206 /* This is a standard iteration of a defensive-loop-checking
|
|
2207 loop. We just do it twice because we want to advance past
|
|
2208 both the property and its value.
|
|
2209
|
|
2210 If the pointer indirection is confusing you, remember that
|
|
2211 one level of indirection on the hare and tortoise pointers
|
|
2212 is only due to pass-by-reference for this function. The other
|
|
2213 level is so that the plist can be fixed in place. */
|
|
2214
|
|
2215 /* When we reach the end of a well-formed plist, **HARE is
|
|
2216 nil. In that case, we don't do anything at all except
|
|
2217 advance TORTOISE by one. Otherwise, we advance HARE
|
|
2218 by two (making sure it's OK to do so), then advance
|
|
2219 TORTOISE by one (it will always be OK to do so because
|
|
2220 the HARE is always ahead of the TORTOISE and will have
|
|
2221 already verified the path), then make sure TORTOISE and
|
|
2222 HARE don't contain the same non-nil object -- if the
|
|
2223 TORTOISE and the HARE ever meet, then obviously we're
|
|
2224 in a circularity, and if we're in a circularity, then
|
|
2225 the TORTOISE and the HARE can't cross paths without
|
|
2226 meeting, since the HARE only gains one step over the
|
|
2227 TORTOISE per iteration. */
|
|
2228
|
|
2229 if (!NILP (**hare))
|
|
2230 {
|
|
2231 Lisp_Object *haresave = *hare;
|
|
2232 if (!CONSP (**hare))
|
|
2233 {
|
|
2234 *retval = bad_bad_bunny (plist, haresave, errb);
|
|
2235 return 0;
|
|
2236 }
|
|
2237 *hare = &XCDR (**hare);
|
|
2238 /* In a non-plist, we'd check here for a nil value for
|
|
2239 **HARE, which is OK (it just means the list has an
|
|
2240 odd number of elements). In a plist, it's not OK
|
|
2241 for the list to have an odd number of elements. */
|
|
2242 if (!CONSP (**hare))
|
|
2243 {
|
|
2244 *retval = bad_bad_bunny (plist, haresave, errb);
|
|
2245 return 0;
|
|
2246 }
|
|
2247 *hare = &XCDR (**hare);
|
|
2248 }
|
|
2249
|
|
2250 *tortoise = &XCDR (**tortoise);
|
|
2251 if (!NILP (**hare) && EQ (**tortoise, **hare))
|
|
2252 {
|
|
2253 *retval = bad_bad_turtle (plist, tortsave, errb);
|
|
2254 return 0;
|
|
2255 }
|
|
2256 }
|
|
2257
|
|
2258 return 1;
|
|
2259 }
|
|
2260
|
|
2261 /* Return the value of PROPERTY from PLIST, or Qunbound if
|
|
2262 property is not on the list.
|
|
2263
|
|
2264 PLIST is a Lisp-accessible property list, meaning that it
|
|
2265 has to be checked for malformations and circularities.
|
|
2266
|
|
2267 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the
|
|
2268 function will never signal an error; and if ERRB is ERROR_ME_WARN,
|
|
2269 on finding a malformation or a circularity, it issues a warning and
|
|
2270 attempts to silently fix the problem.
|
|
2271
|
|
2272 A pointer to PLIST is passed in so that PLIST can be successfully
|
|
2273 "fixed" even if the error is at the beginning of the plist. */
|
|
2274
|
|
2275 Lisp_Object
|
|
2276 external_plist_get (Lisp_Object *plist, Lisp_Object property,
|
|
2277 int laxp, Error_behavior errb)
|
|
2278 {
|
|
2279 Lisp_Object *tortoise = plist;
|
|
2280 Lisp_Object *hare = plist;
|
|
2281
|
|
2282 while (!NILP (*tortoise))
|
|
2283 {
|
|
2284 Lisp_Object *tortsave = tortoise;
|
|
2285 Lisp_Object retval;
|
|
2286
|
|
2287 /* We do the standard tortoise/hare march. We isolate the
|
|
2288 grungy stuff to do this in advance_plist_pointers(), though.
|
|
2289 To us, all this function does is advance the tortoise
|
|
2290 pointer by two and the hare pointer by four and make sure
|
|
2291 everything's OK. We first advance the pointers and then
|
|
2292 check if a property matched; this ensures that our
|
|
2293 check for a matching property is safe. */
|
|
2294
|
|
2295 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2296 return retval;
|
|
2297
|
|
2298 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2299 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2300 return XCAR (XCDR (*tortsave));
|
|
2301 }
|
|
2302
|
|
2303 return Qunbound;
|
|
2304 }
|
|
2305
|
|
2306 /* Set PLIST's value for PROPERTY to VALUE, given a possibly
|
|
2307 malformed or circular plist. Analogous to external_plist_get(). */
|
|
2308
|
|
2309 void
|
|
2310 external_plist_put (Lisp_Object *plist, Lisp_Object property,
|
|
2311 Lisp_Object value, int laxp, Error_behavior errb)
|
|
2312 {
|
|
2313 Lisp_Object *tortoise = plist;
|
|
2314 Lisp_Object *hare = plist;
|
|
2315
|
|
2316 while (!NILP (*tortoise))
|
|
2317 {
|
|
2318 Lisp_Object *tortsave = tortoise;
|
|
2319 Lisp_Object retval;
|
|
2320
|
|
2321 /* See above */
|
|
2322 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2323 return;
|
|
2324
|
|
2325 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2326 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2327 {
|
|
2328 XCAR (XCDR (*tortsave)) = value;
|
|
2329 return;
|
|
2330 }
|
|
2331 }
|
|
2332
|
|
2333 *plist = Fcons (property, Fcons (value, *plist));
|
|
2334 }
|
|
2335
|
|
2336 int
|
|
2337 external_remprop (Lisp_Object *plist, Lisp_Object property,
|
|
2338 int laxp, Error_behavior errb)
|
|
2339 {
|
|
2340 Lisp_Object *tortoise = plist;
|
|
2341 Lisp_Object *hare = plist;
|
|
2342
|
|
2343 while (!NILP (*tortoise))
|
|
2344 {
|
|
2345 Lisp_Object *tortsave = tortoise;
|
|
2346 Lisp_Object retval;
|
|
2347
|
|
2348 /* See above */
|
|
2349 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
|
|
2350 return 0;
|
|
2351
|
|
2352 if (!laxp ? EQ (XCAR (*tortsave), property)
|
|
2353 : internal_equal (XCAR (*tortsave), property, 0))
|
|
2354 {
|
|
2355 /* Now you see why it's so convenient to have that level
|
|
2356 of indirection. */
|
|
2357 *tortsave = XCDR (XCDR (*tortsave));
|
|
2358 return 1;
|
|
2359 }
|
|
2360 }
|
|
2361
|
|
2362 return 0;
|
|
2363 }
|
|
2364
|
20
|
2365 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /*
|
0
|
2366 Extract a value from a property list.
|
|
2367 PLIST is a property list, which is a list of the form
|
|
2368 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
|
|
2369 corresponding to the given PROP, or DEFAULT if PROP is not
|
|
2370 one of the properties on the list.
|
20
|
2371 */
|
173
|
2372 (plist, prop, default_))
|
0
|
2373 {
|
|
2374 Lisp_Object val = external_plist_get (&plist, prop, 0, ERROR_ME);
|
|
2375 if (UNBOUNDP (val))
|
173
|
2376 return default_;
|
0
|
2377 return val;
|
|
2378 }
|
|
2379
|
20
|
2380 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /*
|
0
|
2381 Change value in PLIST of PROP to VAL.
|
|
2382 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
|
|
2383 PROP2 VALUE2 ...). PROP is usually a symbol and VAL is any object.
|
|
2384 If PROP is already a property on the list, its value is set to VAL,
|
|
2385 otherwise the new PROP VAL pair is added. The new plist is returned;
|
|
2386 use `(setq x (plist-put x prop val))' to be sure to use the new value.
|
|
2387 The PLIST is modified by side effects.
|
20
|
2388 */
|
|
2389 (plist, prop, val))
|
0
|
2390 {
|
|
2391 external_plist_put (&plist, prop, val, 0, ERROR_ME);
|
|
2392 return plist;
|
|
2393 }
|
|
2394
|
20
|
2395 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /*
|
0
|
2396 Remove from PLIST the property PROP and its value.
|
|
2397 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
|
|
2398 PROP2 VALUE2 ...). PROP is usually a symbol. The new plist is
|
|
2399 returned; use `(setq x (plist-remprop x prop val))' to be sure to use
|
|
2400 the new value. The PLIST is modified by side effects.
|
20
|
2401 */
|
|
2402 (plist, prop))
|
0
|
2403 {
|
|
2404 external_remprop (&plist, prop, 0, ERROR_ME);
|
|
2405 return plist;
|
|
2406 }
|
|
2407
|
20
|
2408 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /*
|
0
|
2409 Return t if PROP has a value specified in PLIST.
|
20
|
2410 */
|
|
2411 (plist, prop))
|
0
|
2412 {
|
|
2413 return UNBOUNDP (Fplist_get (plist, prop, Qunbound)) ? Qnil : Qt;
|
|
2414 }
|
|
2415
|
20
|
2416 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /*
|
0
|
2417 Given a plist, signal an error if there is anything wrong with it.
|
|
2418 This means that it's a malformed or circular plist.
|
20
|
2419 */
|
|
2420 (plist))
|
0
|
2421 {
|
|
2422 Lisp_Object *tortoise;
|
|
2423 Lisp_Object *hare;
|
|
2424
|
|
2425 start_over:
|
|
2426 tortoise = &plist;
|
|
2427 hare = &plist;
|
|
2428 while (!NILP (*tortoise))
|
|
2429 {
|
|
2430 Lisp_Object retval;
|
|
2431
|
|
2432 /* See above */
|
|
2433 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME,
|
|
2434 &retval))
|
|
2435 goto start_over;
|
|
2436 }
|
|
2437
|
|
2438 return Qnil;
|
|
2439 }
|
173
|
2440
|
20
|
2441 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /*
|
0
|
2442 Given a plist, return non-nil if its format is correct.
|
|
2443 If it returns nil, `check-valid-plist' will signal an error when given
|
|
2444 the plist; that means it's a malformed or circular plist or has non-symbols
|
|
2445 as keywords.
|
20
|
2446 */
|
|
2447 (plist))
|
0
|
2448 {
|
|
2449 Lisp_Object *tortoise;
|
|
2450 Lisp_Object *hare;
|
|
2451
|
|
2452 tortoise = &plist;
|
|
2453 hare = &plist;
|
|
2454 while (!NILP (*tortoise))
|
|
2455 {
|
|
2456 Lisp_Object retval;
|
|
2457
|
|
2458 /* See above */
|
|
2459 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT,
|
|
2460 &retval))
|
|
2461 return Qnil;
|
|
2462 }
|
|
2463
|
|
2464 return Qt;
|
|
2465 }
|
|
2466
|
20
|
2467 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /*
|
0
|
2468 Destructively remove any duplicate entries from a plist.
|
|
2469 In such cases, the first entry applies.
|
|
2470
|
|
2471 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2472 a nil value is removed. This feature is a virus that has infected
|
16
|
2473 old Lisp implementations, but should not be used except for backward
|
|
2474 compatibility.
|
0
|
2475
|
|
2476 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
|
|
2477 return value may not be EQ to the passed-in value, so make sure to
|
|
2478 `setq' the value back into where it came from.
|
20
|
2479 */
|
|
2480 (plist, nil_means_not_present))
|
0
|
2481 {
|
|
2482 Lisp_Object head = plist;
|
|
2483
|
|
2484 Fcheck_valid_plist (plist);
|
|
2485
|
|
2486 while (!NILP (plist))
|
|
2487 {
|
|
2488 Lisp_Object prop = Fcar (plist);
|
|
2489 Lisp_Object next = Fcdr (plist);
|
|
2490
|
|
2491 CHECK_CONS (next); /* just make doubly sure we catch any errors */
|
|
2492 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
|
|
2493 {
|
|
2494 if (EQ (head, plist))
|
|
2495 head = Fcdr (next);
|
|
2496 plist = Fcdr (next);
|
|
2497 continue;
|
|
2498 }
|
|
2499 /* external_remprop returns 1 if it removed any property.
|
|
2500 We have to loop till it didn't remove anything, in case
|
|
2501 the property occurs many times. */
|
|
2502 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME));
|
|
2503 plist = Fcdr (next);
|
|
2504 }
|
|
2505
|
|
2506 return head;
|
|
2507 }
|
|
2508
|
20
|
2509 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /*
|
0
|
2510 Extract a value from a lax property list.
|
|
2511
|
|
2512 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2513 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2514 using `equal' instead of `eq'. This function returns the value
|
|
2515 corresponding to the given PROP, or DEFAULT if PROP is not one of the
|
|
2516 properties on the list.
|
20
|
2517 */
|
173
|
2518 (lax_plist, prop, default_))
|
0
|
2519 {
|
|
2520 Lisp_Object val = external_plist_get (&lax_plist, prop, 1, ERROR_ME);
|
|
2521 if (UNBOUNDP (val))
|
173
|
2522 return default_;
|
0
|
2523 return val;
|
|
2524 }
|
|
2525
|
20
|
2526 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /*
|
0
|
2527 Change value in LAX-PLIST of PROP to VAL.
|
|
2528 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2529 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2530 using `equal' instead of `eq'. PROP is usually a symbol and VAL is
|
|
2531 any object. If PROP is already a property on the list, its value is
|
|
2532 set to VAL, otherwise the new PROP VAL pair is added. The new plist
|
|
2533 is returned; use `(setq x (lax-plist-put x prop val))' to be sure to
|
|
2534 use the new value. The LAX-PLIST is modified by side effects.
|
20
|
2535 */
|
|
2536 (lax_plist, prop, val))
|
0
|
2537 {
|
|
2538 external_plist_put (&lax_plist, prop, val, 1, ERROR_ME);
|
|
2539 return lax_plist;
|
|
2540 }
|
|
2541
|
20
|
2542 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /*
|
0
|
2543 Remove from LAX-PLIST the property PROP and its value.
|
|
2544 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2545 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2546 using `equal' instead of `eq'. PROP is usually a symbol. The new
|
|
2547 plist is returned; use `(setq x (lax-plist-remprop x prop val))' to be
|
|
2548 sure to use the new value. The LAX-PLIST is modified by side effects.
|
20
|
2549 */
|
|
2550 (lax_plist, prop))
|
0
|
2551 {
|
|
2552 external_remprop (&lax_plist, prop, 1, ERROR_ME);
|
|
2553 return lax_plist;
|
|
2554 }
|
|
2555
|
20
|
2556 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /*
|
0
|
2557 Return t if PROP has a value specified in LAX-PLIST.
|
|
2558 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
|
|
2559 VALUE1 PROP2 VALUE2...), where comparions between properties is done
|
|
2560 using `equal' instead of `eq'.
|
20
|
2561 */
|
|
2562 (lax_plist, prop))
|
0
|
2563 {
|
|
2564 return UNBOUNDP (Flax_plist_get (lax_plist, prop, Qunbound)) ? Qnil : Qt;
|
|
2565 }
|
|
2566
|
20
|
2567 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /*
|
0
|
2568 Destructively remove any duplicate entries from a lax plist.
|
|
2569 In such cases, the first entry applies.
|
|
2570
|
|
2571 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
|
|
2572 a nil value is removed. This feature is a virus that has infected
|
16
|
2573 old Lisp implementations, but should not be used except for backward
|
|
2574 compatibility.
|
0
|
2575
|
|
2576 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
|
|
2577 return value may not be EQ to the passed-in value, so make sure to
|
|
2578 `setq' the value back into where it came from.
|
20
|
2579 */
|
|
2580 (lax_plist, nil_means_not_present))
|
0
|
2581 {
|
|
2582 Lisp_Object head = lax_plist;
|
|
2583
|
|
2584 Fcheck_valid_plist (lax_plist);
|
|
2585
|
|
2586 while (!NILP (lax_plist))
|
|
2587 {
|
|
2588 Lisp_Object prop = Fcar (lax_plist);
|
|
2589 Lisp_Object next = Fcdr (lax_plist);
|
|
2590
|
|
2591 CHECK_CONS (next); /* just make doubly sure we catch any errors */
|
|
2592 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
|
|
2593 {
|
|
2594 if (EQ (head, lax_plist))
|
|
2595 head = Fcdr (next);
|
|
2596 lax_plist = Fcdr (next);
|
|
2597 continue;
|
|
2598 }
|
|
2599 /* external_remprop returns 1 if it removed any property.
|
|
2600 We have to loop till it didn't remove anything, in case
|
|
2601 the property occurs many times. */
|
|
2602 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME));
|
|
2603 lax_plist = Fcdr (next);
|
|
2604 }
|
|
2605
|
|
2606 return head;
|
|
2607 }
|
|
2608
|
|
2609 /* In C because the frame props stuff uses it */
|
|
2610
|
20
|
2611 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /*
|
0
|
2612 Convert association list ALIST into the equivalent property-list form.
|
|
2613 The plist is returned. This converts from
|
|
2614
|
|
2615 \((a . 1) (b . 2) (c . 3))
|
|
2616
|
|
2617 into
|
|
2618
|
|
2619 \(a 1 b 2 c 3)
|
|
2620
|
|
2621 The original alist is destroyed in the process of constructing the plist.
|
|
2622 See also `alist-to-plist'.
|
20
|
2623 */
|
|
2624 (alist))
|
0
|
2625 {
|
|
2626 Lisp_Object head = alist;
|
|
2627 while (!NILP (alist))
|
|
2628 {
|
|
2629 /* remember the alist element. */
|
|
2630 Lisp_Object el = Fcar (alist);
|
|
2631
|
|
2632 Fsetcar (alist, Fcar (el));
|
|
2633 Fsetcar (el, Fcdr (el));
|
|
2634 Fsetcdr (el, Fcdr (alist));
|
|
2635 Fsetcdr (alist, el);
|
|
2636 alist = Fcdr (Fcdr (alist));
|
|
2637 }
|
|
2638
|
|
2639 return head;
|
|
2640 }
|
|
2641
|
|
2642 /* Symbol plists are directly accessible, so we need to protect against
|
|
2643 invalid property list structure */
|
|
2644
|
|
2645 static Lisp_Object
|
173
|
2646 symbol_getprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object default_)
|
0
|
2647 {
|
|
2648 Lisp_Object val = external_plist_get (&XSYMBOL (sym)->plist, propname,
|
|
2649 0, ERROR_ME);
|
272
|
2650 return UNBOUNDP (val) ? default_ : val;
|
0
|
2651 }
|
|
2652
|
|
2653 static void
|
|
2654 symbol_putprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object value)
|
|
2655 {
|
|
2656 external_plist_put (&XSYMBOL (sym)->plist, propname, value, 0, ERROR_ME);
|
|
2657 }
|
|
2658
|
|
2659 static int
|
|
2660 symbol_remprop (Lisp_Object symbol, Lisp_Object propname)
|
|
2661 {
|
|
2662 return external_remprop (&XSYMBOL (symbol)->plist, propname, 0, ERROR_ME);
|
|
2663 }
|
|
2664
|
|
2665 /* We store the string's extent info as the first element of the string's
|
|
2666 property list; and the string's MODIFF as the first or second element
|
|
2667 of the string's property list (depending on whether the extent info
|
|
2668 is present), but only if the string has been modified. This is ugly
|
|
2669 but it reduces the memory allocated for the string in the vast
|
|
2670 majority of cases, where the string is never modified and has no
|
|
2671 extent info. */
|
|
2672
|
|
2673
|
|
2674 static Lisp_Object *
|
|
2675 string_plist_ptr (struct Lisp_String *s)
|
|
2676 {
|
|
2677 Lisp_Object *ptr = &s->plist;
|
|
2678
|
|
2679 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
|
|
2680 ptr = &XCDR (*ptr);
|
|
2681 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
|
|
2682 ptr = &XCDR (*ptr);
|
|
2683 return ptr;
|
|
2684 }
|
|
2685
|
272
|
2686 static Lisp_Object
|
0
|
2687 string_getprop (struct Lisp_String *s, Lisp_Object property,
|
173
|
2688 Lisp_Object default_)
|
0
|
2689 {
|
|
2690 Lisp_Object val = external_plist_get (string_plist_ptr (s), property, 0,
|
|
2691 ERROR_ME);
|
272
|
2692 return UNBOUNDP (val) ? default_ : val;
|
0
|
2693 }
|
|
2694
|
272
|
2695 static void
|
0
|
2696 string_putprop (struct Lisp_String *s, Lisp_Object property,
|
|
2697 Lisp_Object value)
|
|
2698 {
|
|
2699 external_plist_put (string_plist_ptr (s), property, value, 0, ERROR_ME);
|
|
2700 }
|
|
2701
|
|
2702 static int
|
|
2703 string_remprop (struct Lisp_String *s, Lisp_Object property)
|
|
2704 {
|
|
2705 return external_remprop (string_plist_ptr (s), property, 0, ERROR_ME);
|
|
2706 }
|
|
2707
|
|
2708 static Lisp_Object
|
|
2709 string_plist (struct Lisp_String *s)
|
|
2710 {
|
|
2711 return *string_plist_ptr (s);
|
|
2712 }
|
|
2713
|
20
|
2714 DEFUN ("get", Fget, 2, 3, 0, /*
|
0
|
2715 Return the value of OBJECT's PROPNAME property.
|
|
2716 This is the last VALUE stored with `(put OBJECT PROPNAME VALUE)'.
|
|
2717 If there is no such property, return optional third arg DEFAULT
|
173
|
2718 \(which defaults to `nil'). OBJECT can be a symbol, face, extent,
|
0
|
2719 or string. See also `put', `remprop', and `object-plist'.
|
20
|
2720 */
|
173
|
2721 (object, propname, default_))
|
0
|
2722 {
|
|
2723 Lisp_Object val;
|
|
2724
|
|
2725 /* Various places in emacs call Fget() and expect it not to quit,
|
|
2726 so don't quit. */
|
173
|
2727
|
0
|
2728 /* It's easiest to treat symbols specially because they may not
|
|
2729 be an lrecord */
|
|
2730 if (SYMBOLP (object))
|
173
|
2731 val = symbol_getprop (object, propname, default_);
|
0
|
2732 else if (STRINGP (object))
|
173
|
2733 val = string_getprop (XSTRING (object), propname, default_);
|
0
|
2734 else if (LRECORDP (object))
|
|
2735 {
|
|
2736 CONST struct lrecord_implementation
|
211
|
2737 *imp = XRECORD_LHEADER_IMPLEMENTATION (object);
|
0
|
2738 if (imp->getprop)
|
|
2739 {
|
|
2740 val = (imp->getprop) (object, propname);
|
|
2741 if (UNBOUNDP (val))
|
173
|
2742 val = default_;
|
0
|
2743 }
|
|
2744 else
|
|
2745 goto noprops;
|
|
2746 }
|
|
2747 else
|
|
2748 {
|
|
2749 noprops:
|
|
2750 signal_simple_error ("Object type has no properties", object);
|
|
2751 }
|
|
2752
|
|
2753 return val;
|
|
2754 }
|
|
2755
|
20
|
2756 DEFUN ("put", Fput, 3, 3, 0, /*
|
0
|
2757 Store OBJECT's PROPNAME property with value VALUE.
|
|
2758 It can be retrieved with `(get OBJECT PROPNAME)'. OBJECT can be a
|
|
2759 symbol, face, extent, or string.
|
|
2760
|
|
2761 For a string, no properties currently have predefined meanings.
|
|
2762 For the predefined properties for extents, see `set-extent-property'.
|
|
2763 For the predefined properties for faces, see `set-face-property'.
|
|
2764
|
|
2765 See also `get', `remprop', and `object-plist'.
|
20
|
2766 */
|
|
2767 (object, propname, value))
|
0
|
2768 {
|
|
2769 CHECK_SYMBOL (propname);
|
|
2770 CHECK_IMPURE (object);
|
|
2771
|
|
2772 if (SYMBOLP (object))
|
|
2773 symbol_putprop (object, propname, value);
|
|
2774 else if (STRINGP (object))
|
|
2775 string_putprop (XSTRING (object), propname, value);
|
|
2776 else if (LRECORDP (object))
|
|
2777 {
|
|
2778 CONST struct lrecord_implementation
|
211
|
2779 *imp = XRECORD_LHEADER_IMPLEMENTATION (object);
|
0
|
2780 if (imp->putprop)
|
|
2781 {
|
|
2782 if (! (imp->putprop) (object, propname, value))
|
|
2783 signal_simple_error ("Can't set property on object", propname);
|
|
2784 }
|
|
2785 else
|
|
2786 goto noprops;
|
|
2787 }
|
|
2788 else
|
|
2789 {
|
|
2790 noprops:
|
|
2791 signal_simple_error ("Object type has no settable properties", object);
|
|
2792 }
|
|
2793
|
|
2794 return value;
|
|
2795 }
|
|
2796
|
|
2797 void
|
|
2798 pure_put (Lisp_Object sym, Lisp_Object prop, Lisp_Object val)
|
|
2799 {
|
|
2800 Fput (sym, prop, Fpurecopy (val));
|
|
2801 }
|
|
2802
|
20
|
2803 DEFUN ("remprop", Fremprop, 2, 2, 0, /*
|
0
|
2804 Remove from OBJECT's property list the property PROPNAME and its
|
|
2805 value. OBJECT can be a symbol, face, extent, or string. Returns
|
|
2806 non-nil if the property list was actually changed (i.e. if PROPNAME
|
|
2807 was present in the property list). See also `get', `put', and
|
|
2808 `object-plist'.
|
20
|
2809 */
|
|
2810 (object, propname))
|
0
|
2811 {
|
|
2812 int retval = 0;
|
|
2813
|
|
2814 CHECK_SYMBOL (propname);
|
|
2815 CHECK_IMPURE (object);
|
|
2816
|
|
2817 if (SYMBOLP (object))
|
|
2818 retval = symbol_remprop (object, propname);
|
|
2819 else if (STRINGP (object))
|
|
2820 retval = string_remprop (XSTRING (object), propname);
|
|
2821 else if (LRECORDP (object))
|
|
2822 {
|
|
2823 CONST struct lrecord_implementation
|
211
|
2824 *imp = XRECORD_LHEADER_IMPLEMENTATION (object);
|
0
|
2825 if (imp->remprop)
|
|
2826 {
|
|
2827 retval = (imp->remprop) (object, propname);
|
|
2828 if (retval == -1)
|
|
2829 signal_simple_error ("Can't remove property from object",
|
|
2830 propname);
|
|
2831 }
|
|
2832 else
|
|
2833 goto noprops;
|
|
2834 }
|
|
2835 else
|
|
2836 {
|
|
2837 noprops:
|
|
2838 signal_simple_error ("Object type has no removable properties", object);
|
|
2839 }
|
|
2840
|
|
2841 return retval ? Qt : Qnil;
|
|
2842 }
|
|
2843
|
20
|
2844 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /*
|
0
|
2845 Return a property list of OBJECT's props.
|
|
2846 For a symbol this is equivalent to `symbol-plist'.
|
|
2847 Do not modify the property list directly; this may or may not have
|
|
2848 the desired effects. (In particular, for a property with a special
|
|
2849 interpretation, this will probably have no effect at all.)
|
20
|
2850 */
|
|
2851 (object))
|
0
|
2852 {
|
|
2853 if (SYMBOLP (object))
|
|
2854 return Fsymbol_plist (object);
|
|
2855 else if (STRINGP (object))
|
|
2856 return string_plist (XSTRING (object));
|
|
2857 else if (LRECORDP (object))
|
|
2858 {
|
|
2859 CONST struct lrecord_implementation
|
211
|
2860 *imp = XRECORD_LHEADER_IMPLEMENTATION (object);
|
0
|
2861 if (imp->plist)
|
|
2862 return (imp->plist) (object);
|
|
2863 else
|
|
2864 signal_simple_error ("Object type has no properties", object);
|
|
2865 }
|
|
2866 else
|
|
2867 signal_simple_error ("Object type has no properties", object);
|
|
2868
|
|
2869 return Qnil;
|
|
2870 }
|
|
2871
|
|
2872
|
|
2873 int
|
|
2874 internal_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2875 {
|
|
2876 if (depth > 200)
|
|
2877 error ("Stack overflow in equal");
|
223
|
2878 #ifndef LRECORD_CONS
|
0
|
2879 do_cdr:
|
223
|
2880 #endif
|
0
|
2881 QUIT;
|
70
|
2882 if (EQ_WITH_EBOLA_NOTICE (o1, o2))
|
149
|
2883 return 1;
|
0
|
2884 /* Note that (equal 20 20.0) should be nil */
|
173
|
2885 else if (XTYPE (o1) != XTYPE (o2))
|
149
|
2886 return 0;
|
207
|
2887 #ifndef LRECORD_CONS
|
0
|
2888 else if (CONSP (o1))
|
|
2889 {
|
165
|
2890 if (!internal_equal (XCAR (o1), XCAR (o2), depth + 1))
|
149
|
2891 return 0;
|
165
|
2892 o1 = XCDR (o1);
|
|
2893 o2 = XCDR (o2);
|
0
|
2894 goto do_cdr;
|
|
2895 }
|
207
|
2896 #endif
|
0
|
2897 #ifndef LRECORD_VECTOR
|
|
2898 else if (VECTORP (o1))
|
|
2899 {
|
272
|
2900 Lisp_Object *v1 = XVECTOR_DATA (o1);
|
|
2901 Lisp_Object *v2 = XVECTOR_DATA (o2);
|
173
|
2902 int len = XVECTOR_LENGTH (o1);
|
|
2903 if (len != XVECTOR_LENGTH (o2))
|
149
|
2904 return 0;
|
272
|
2905 while (len--)
|
|
2906 if (!internal_equal (*v1++, *v2++, depth + 1))
|
|
2907 return 0;
|
149
|
2908 return 1;
|
0
|
2909 }
|
207
|
2910 #endif
|
|
2911 #ifndef LRECORD_STRING
|
0
|
2912 else if (STRINGP (o1))
|
|
2913 {
|
272
|
2914 Bytecount len;
|
|
2915 return (((len = XSTRING_LENGTH (o1)) == XSTRING_LENGTH (o2)) &&
|
|
2916 !memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len));
|
0
|
2917 }
|
207
|
2918 #endif
|
0
|
2919 else if (LRECORDP (o1))
|
|
2920 {
|
|
2921 CONST struct lrecord_implementation
|
211
|
2922 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (o1),
|
|
2923 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (o2);
|
0
|
2924 if (imp1 != imp2)
|
149
|
2925 return 0;
|
0
|
2926 else if (imp1->equal == 0)
|
|
2927 /* EQ-ness of the objects was noticed above */
|
149
|
2928 return 0;
|
0
|
2929 else
|
149
|
2930 return (imp1->equal) (o1, o2, depth);
|
0
|
2931 }
|
|
2932
|
149
|
2933 return 0;
|
0
|
2934 }
|
|
2935
|
70
|
2936 /* Note that we may be calling sub-objects that will use
|
|
2937 internal_equal() (instead of internal_old_equal()). Oh well.
|
|
2938 We will get an Ebola note if there's any possibility of confusion,
|
|
2939 but that seems unlikely. */
|
|
2940
|
|
2941 static int
|
|
2942 internal_old_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2943 {
|
|
2944 if (depth > 200)
|
|
2945 error ("Stack overflow in equal");
|
223
|
2946 #ifndef LRECORD_CONS
|
70
|
2947 do_cdr:
|
223
|
2948 #endif
|
70
|
2949 QUIT;
|
|
2950 if (HACKEQ_UNSAFE (o1, o2))
|
149
|
2951 return 1;
|
70
|
2952 /* Note that (equal 20 20.0) should be nil */
|
173
|
2953 else if (XTYPE (o1) != XTYPE (o2))
|
149
|
2954 return 0;
|
207
|
2955 #ifndef LRECORD_CONS
|
70
|
2956 else if (CONSP (o1))
|
|
2957 {
|
165
|
2958 if (!internal_old_equal (XCAR (o1), XCAR (o2), depth + 1))
|
149
|
2959 return 0;
|
165
|
2960 o1 = XCDR (o1);
|
|
2961 o2 = XCDR (o2);
|
70
|
2962 goto do_cdr;
|
|
2963 }
|
207
|
2964 #endif
|
70
|
2965 #ifndef LRECORD_VECTOR
|
|
2966 else if (VECTORP (o1))
|
|
2967 {
|
173
|
2968 int indice;
|
|
2969 int len = XVECTOR_LENGTH (o1);
|
|
2970 if (len != XVECTOR_LENGTH (o2))
|
149
|
2971 return 0;
|
173
|
2972 for (indice = 0; indice < len; indice++)
|
70
|
2973 {
|
173
|
2974 if (!internal_old_equal (XVECTOR_DATA (o1) [indice],
|
|
2975 XVECTOR_DATA (o2) [indice],
|
|
2976 depth + 1))
|
149
|
2977 return 0;
|
70
|
2978 }
|
149
|
2979 return 1;
|
70
|
2980 }
|
207
|
2981 #endif
|
|
2982 #ifndef LRECORD_STRING
|
70
|
2983 else if (STRINGP (o1))
|
|
2984 {
|
|
2985 Bytecount len = XSTRING_LENGTH (o1);
|
|
2986 if (len != XSTRING_LENGTH (o2))
|
149
|
2987 return 0;
|
70
|
2988 if (memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len))
|
149
|
2989 return 0;
|
|
2990 return 1;
|
70
|
2991 }
|
207
|
2992 #endif
|
70
|
2993 else if (LRECORDP (o1))
|
|
2994 {
|
|
2995 CONST struct lrecord_implementation
|
211
|
2996 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (o1),
|
|
2997 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (o2);
|
70
|
2998 if (imp1 != imp2)
|
149
|
2999 return 0;
|
70
|
3000 else if (imp1->equal == 0)
|
|
3001 /* EQ-ness of the objects was noticed above */
|
149
|
3002 return 0;
|
70
|
3003 else
|
173
|
3004 return (imp1->equal) (o1, o2, depth);
|
70
|
3005 }
|
|
3006
|
149
|
3007 return 0;
|
70
|
3008 }
|
|
3009
|
20
|
3010 DEFUN ("equal", Fequal, 2, 2, 0, /*
|
272
|
3011 Return t if two Lisp objects have similar structure and contents.
|
0
|
3012 They must have the same data type.
|
|
3013 Conses are compared by comparing the cars and the cdrs.
|
|
3014 Vectors and strings are compared element by element.
|
|
3015 Numbers are compared by value. Symbols must match exactly.
|
20
|
3016 */
|
|
3017 (o1, o2))
|
0
|
3018 {
|
149
|
3019 return internal_equal (o1, o2, 0) ? Qt : Qnil;
|
0
|
3020 }
|
|
3021
|
70
|
3022 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /*
|
272
|
3023 Return t if two Lisp objects have similar structure and contents.
|
70
|
3024 They must have the same data type.
|
|
3025 \(Note, however, that an exception is made for characters and integers;
|
185
|
3026 this is known as the "char-int confoundance disease." See `eq' and
|
70
|
3027 `old-eq'.)
|
|
3028 This function is provided only for byte-code compatibility with v19.
|
|
3029 Do not use it.
|
|
3030 */
|
|
3031 (o1, o2))
|
|
3032 {
|
149
|
3033 return internal_old_equal (o1, o2, 0) ? Qt : Qnil;
|
70
|
3034 }
|
|
3035
|
0
|
3036
|
20
|
3037 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /*
|
0
|
3038 Store each element of ARRAY with ITEM.
|
|
3039 ARRAY is a vector, bit vector, or string.
|
20
|
3040 */
|
|
3041 (array, item))
|
0
|
3042 {
|
|
3043 retry:
|
76
|
3044 if (STRINGP (array))
|
|
3045 {
|
272
|
3046 Emchar charval;
|
|
3047 struct Lisp_String *s = XSTRING (array);
|
|
3048 Charcount len = string_char_length (s);
|
76
|
3049 Charcount i;
|
|
3050 CHECK_CHAR_COERCE_INT (item);
|
|
3051 CHECK_IMPURE (array);
|
|
3052 charval = XCHAR (item);
|
173
|
3053 for (i = 0; i < len; i++)
|
76
|
3054 set_string_char (s, i, charval);
|
|
3055 bump_string_modiff (array);
|
|
3056 }
|
|
3057 else if (VECTORP (array))
|
10
|
3058 {
|
272
|
3059 Lisp_Object *p = XVECTOR_DATA (array);
|
|
3060 int len = XVECTOR_LENGTH (array);
|
10
|
3061 CHECK_IMPURE (array);
|
272
|
3062 while (len--)
|
|
3063 *p++ = item;
|
10
|
3064 }
|
76
|
3065 else if (BIT_VECTORP (array))
|
0
|
3066 {
|
272
|
3067 struct Lisp_Bit_Vector *v = XBIT_VECTOR (array);
|
|
3068 int len = bit_vector_length (v);
|
|
3069 int bit;
|
0
|
3070 CHECK_BIT (item);
|
|
3071 CHECK_IMPURE (array);
|
272
|
3072 bit = XINT (item);
|
|
3073 while (len--)
|
|
3074 set_bit_vector_bit (v, len, bit);
|
0
|
3075 }
|
|
3076 else
|
|
3077 {
|
|
3078 array = wrong_type_argument (Qarrayp, array);
|
|
3079 goto retry;
|
|
3080 }
|
|
3081 return array;
|
|
3082 }
|
|
3083
|
|
3084 Lisp_Object
|
|
3085 nconc2 (Lisp_Object s1, Lisp_Object s2)
|
|
3086 {
|
|
3087 Lisp_Object args[2];
|
|
3088 args[0] = s1;
|
|
3089 args[1] = s2;
|
|
3090 return Fnconc (2, args);
|
|
3091 }
|
|
3092
|
20
|
3093 DEFUN ("nconc", Fnconc, 0, MANY, 0, /*
|
0
|
3094 Concatenate any number of lists by altering them.
|
|
3095 Only the last argument is not altered, and need not be a list.
|
201
|
3096 Also see: `append'.
|
272
|
3097 If the first argument is nil, there is no way to modify it by side
|
|
3098 effect; therefore, write `(setq foo (nconc foo list))' to be sure of
|
|
3099 changing the value of `foo'.
|
20
|
3100 */
|
|
3101 (int nargs, Lisp_Object *args))
|
0
|
3102 {
|
272
|
3103 int argnum = 0;
|
0
|
3104 struct gcpro gcpro1;
|
|
3105
|
|
3106 /* The modus operandi in Emacs is "caller gc-protects args".
|
|
3107 However, nconc (particularly nconc2 ()) is called many times
|
|
3108 in Emacs on freshly created stuff (e.g. you see the idiom
|
|
3109 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those
|
|
3110 callers out by protecting the args ourselves to save them
|
|
3111 a lot of temporary-variable grief. */
|
|
3112
|
|
3113 GCPRO1 (args[0]);
|
|
3114 gcpro1.nvars = nargs;
|
173
|
3115
|
272
|
3116 while (argnum < nargs)
|
0
|
3117 {
|
272
|
3118 Lisp_Object val = args[argnum];
|
|
3119 if (CONSP (val))
|
173
|
3120 {
|
272
|
3121 /* Found the first cons, which will be our return value. */
|
|
3122 Lisp_Object last = val;
|
|
3123
|
|
3124 for (argnum++; argnum < nargs; argnum++)
|
|
3125 {
|
|
3126 Lisp_Object next = args[argnum];
|
|
3127 redo:
|
|
3128 if (CONSP (next) || argnum == nargs -1)
|
|
3129 {
|
|
3130 /* (setcdr (last val) next) */
|
|
3131 while (CONSP (XCDR (last)))
|
|
3132 {
|
|
3133 last = XCDR (last);
|
|
3134 QUIT;
|
|
3135 }
|
|
3136 XCDR (last) = next;
|
|
3137 }
|
|
3138 else if (NILP (next))
|
|
3139 {
|
|
3140 continue;
|
|
3141 }
|
|
3142 else
|
|
3143 {
|
|
3144 next = wrong_type_argument (next, Qlistp);
|
|
3145 goto redo;
|
|
3146 }
|
|
3147 }
|
|
3148 RETURN_UNGCPRO (val);
|
|
3149 }
|
|
3150 else if (NILP (val))
|
|
3151 argnum++;
|
|
3152 else if (argnum == nargs - 1) /* last arg? */
|
|
3153 RETURN_UNGCPRO (val);
|
|
3154 else
|
|
3155 args[argnum] = wrong_type_argument (val, Qlistp);
|
0
|
3156 }
|
272
|
3157 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */
|
0
|
3158 }
|
|
3159
|
|
3160
|
|
3161 /* This is the guts of all mapping functions.
|
|
3162 Apply fn to each element of seq, one by one,
|
|
3163 storing the results into elements of vals, a C vector of Lisp_Objects.
|
|
3164 leni is the length of vals, which should also be the length of seq.
|
|
3165
|
|
3166 If VALS is a null pointer, do not accumulate the results. */
|
|
3167
|
|
3168 static void
|
|
3169 mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
|
|
3170 {
|
|
3171 Lisp_Object tail;
|
|
3172 Lisp_Object dummy = Qnil;
|
|
3173 int i;
|
|
3174 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3175 Lisp_Object result;
|
|
3176
|
|
3177 GCPRO3 (dummy, fn, seq);
|
|
3178
|
|
3179 if (vals)
|
|
3180 {
|
|
3181 /* Don't let vals contain any garbage when GC happens. */
|
|
3182 for (i = 0; i < leni; i++)
|
|
3183 vals[i] = Qnil;
|
|
3184 gcpro1.var = vals;
|
|
3185 gcpro1.nvars = leni;
|
|
3186 }
|
|
3187
|
|
3188 /* We need not explicitly protect `tail' because it is used only on
|
|
3189 lists, and 1) lists are not relocated and 2) the list is marked
|
|
3190 via `seq' so will not be freed */
|
|
3191
|
|
3192 if (VECTORP (seq))
|
|
3193 {
|
|
3194 for (i = 0; i < leni; i++)
|
|
3195 {
|
173
|
3196 dummy = XVECTOR_DATA (seq)[i];
|
0
|
3197 result = call1 (fn, dummy);
|
|
3198 if (vals)
|
|
3199 vals[i] = result;
|
|
3200 }
|
|
3201 }
|
|
3202 else if (BIT_VECTORP (seq))
|
|
3203 {
|
|
3204 struct Lisp_Bit_Vector *v = XBIT_VECTOR (seq);
|
|
3205 for (i = 0; i < leni; i++)
|
|
3206 {
|
|
3207 XSETINT (dummy, bit_vector_bit (v, i));
|
|
3208 result = call1 (fn, dummy);
|
|
3209 if (vals)
|
|
3210 vals[i] = result;
|
|
3211 }
|
|
3212 }
|
|
3213 else if (STRINGP (seq))
|
|
3214 {
|
|
3215 for (i = 0; i < leni; i++)
|
|
3216 {
|
|
3217 result = call1 (fn, make_char (string_char (XSTRING (seq), i)));
|
|
3218 if (vals)
|
|
3219 vals[i] = result;
|
|
3220 }
|
|
3221 }
|
|
3222 else /* Must be a list, since Flength did not get an error */
|
|
3223 {
|
|
3224 tail = seq;
|
|
3225 for (i = 0; i < leni; i++)
|
|
3226 {
|
|
3227 result = call1 (fn, Fcar (tail));
|
|
3228 if (vals)
|
|
3229 vals[i] = result;
|
|
3230 tail = Fcdr (tail);
|
|
3231 }
|
|
3232 }
|
|
3233
|
|
3234 UNGCPRO;
|
|
3235 }
|
|
3236
|
20
|
3237 DEFUN ("mapconcat", Fmapconcat, 3, 3, 0, /*
|
0
|
3238 Apply FN to each element of SEQ, and concat the results as strings.
|
|
3239 In between each pair of results, stick in SEP.
|
185
|
3240 Thus, " " as SEP results in spaces between the values returned by FN.
|
20
|
3241 */
|
|
3242 (fn, seq, sep))
|
0
|
3243 {
|
16
|
3244 int len = XINT (Flength (seq));
|
0
|
3245 Lisp_Object *args;
|
|
3246 int i;
|
|
3247 struct gcpro gcpro1;
|
272
|
3248 int nargs = len + len - 1;
|
|
3249
|
0
|
3250 if (nargs < 0) return build_string ("");
|
|
3251
|
185
|
3252 args = alloca_array (Lisp_Object, nargs);
|
0
|
3253
|
|
3254 GCPRO1 (sep);
|
16
|
3255 mapcar1 (len, args, fn, seq);
|
0
|
3256 UNGCPRO;
|
|
3257
|
16
|
3258 for (i = len - 1; i >= 0; i--)
|
0
|
3259 args[i + i] = args[i];
|
173
|
3260
|
0
|
3261 for (i = 1; i < nargs; i += 2)
|
|
3262 args[i] = sep;
|
|
3263
|
|
3264 return Fconcat (nargs, args);
|
|
3265 }
|
|
3266
|
20
|
3267 DEFUN ("mapcar", Fmapcar, 2, 2, 0, /*
|
0
|
3268 Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
|
|
3269 The result is a list just as long as SEQUENCE.
|
|
3270 SEQUENCE may be a list, a vector, a bit vector, or a string.
|
20
|
3271 */
|
|
3272 (fn, seq))
|
0
|
3273 {
|
16
|
3274 int len = XINT (Flength (seq));
|
185
|
3275 Lisp_Object *args = alloca_array (Lisp_Object, len);
|
16
|
3276
|
|
3277 mapcar1 (len, args, fn, seq);
|
|
3278
|
|
3279 return Flist (len, args);
|
0
|
3280 }
|
|
3281
|
163
|
3282 DEFUN ("mapvector", Fmapvector, 2, 2, 0, /*
|
|
3283 Apply FUNCTION to each element of SEQUENCE, making a vector of the results.
|
|
3284 The result is a vector of the same length as SEQUENCE.
|
|
3285 SEQUENCE may be a list, a vector or a string.
|
|
3286 */
|
|
3287 (fn, seq))
|
|
3288 {
|
|
3289 int len = XINT (Flength (seq));
|
219
|
3290 /* Ideally, this should call make_vector_internal, because we don't
|
|
3291 need initialization. */
|
|
3292 Lisp_Object result = make_vector (len, Qnil);
|
|
3293 struct gcpro gcpro1;
|
|
3294
|
|
3295 GCPRO1 (result);
|
|
3296 mapcar1 (len, XVECTOR_DATA (result), fn, seq);
|
|
3297 UNGCPRO;
|
|
3298
|
|
3299 return result;
|
163
|
3300 }
|
|
3301
|
187
|
3302 DEFUN ("mapc", Fmapc, 2, 2, 0, /*
|
0
|
3303 Apply FUNCTION to each element of SEQUENCE.
|
|
3304 SEQUENCE may be a list, a vector, a bit vector, or a string.
|
|
3305 This function is like `mapcar' but does not accumulate the results,
|
|
3306 which is more efficient if you do not use the results.
|
20
|
3307 */
|
|
3308 (fn, seq))
|
0
|
3309 {
|
16
|
3310 mapcar1 (XINT (Flength (seq)), 0, fn, seq);
|
0
|
3311
|
187
|
3312 return seq;
|
0
|
3313 }
|
|
3314
|
|
3315
|
|
3316 /* #### this function doesn't belong in this file! */
|
|
3317
|
20
|
3318 DEFUN ("load-average", Fload_average, 0, 0, 0, /*
|
0
|
3319 Return list of 1 minute, 5 minute and 15 minute load averages.
|
|
3320 Each of the three load averages is multiplied by 100,
|
|
3321 then converted to integer.
|
|
3322
|
|
3323 If the 5-minute or 15-minute load averages are not available, return a
|
|
3324 shortened list, containing only those averages which are available.
|
|
3325
|
272
|
3326 On some systems, this won't work due to permissions on /dev/kmem,
|
|
3327 in which case you can't use this.
|
20
|
3328 */
|
|
3329 ())
|
0
|
3330 {
|
272
|
3331 double load_ave[3];
|
|
3332 int loads = getloadavg (load_ave, countof (load_ave));
|
0
|
3333
|
|
3334 if (loads == -2)
|
|
3335 error ("load-average not implemented for this operating system.");
|
|
3336 else if (loads < 0)
|
|
3337 error ("could not get load-average; check permissions.");
|
|
3338
|
272
|
3339 {
|
|
3340 Lisp_Object ret = Qnil;
|
|
3341 while (loads > 0)
|
|
3342 ret = Fcons (make_int ((int) (load_ave[--loads] * 100.0)), ret);
|
|
3343 return ret;
|
|
3344 }
|
0
|
3345 }
|
|
3346
|
|
3347
|
|
3348 Lisp_Object Vfeatures;
|
|
3349
|
20
|
3350 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /*
|
207
|
3351 Return non-nil if feature FEXP is present in this Emacs.
|
70
|
3352 Use this to conditionalize execution of lisp code based on the
|
207
|
3353 presence or absence of emacs or environment extensions.
|
|
3354 FEXP can be a symbol, a number, or a list.
|
209
|
3355 If it is a symbol, that symbol is looked up in the `features' variable,
|
|
3356 and non-nil will be returned if found.
|
|
3357 If it is a number, the function will return non-nil if this Emacs
|
207
|
3358 has an equal or greater version number than FEXP.
|
209
|
3359 If it is a list whose car is the symbol `and', it will return
|
207
|
3360 non-nil if all the features in its cdr are non-nil.
|
209
|
3361 If it is a list whose car is the symbol `or', it will return non-nil
|
207
|
3362 if any of the features in its cdr are non-nil.
|
209
|
3363 If it is a list whose car is the symbol `not', it will return
|
207
|
3364 non-nil if the feature is not present.
|
209
|
3365
|
|
3366 Examples:
|
|
3367
|
|
3368 (featurep 'xemacs)
|
|
3369 => ; Non-nil on XEmacs.
|
|
3370
|
|
3371 (featurep '(and xemacs gnus))
|
|
3372 => ; Non-nil on XEmacs with Gnus loaded.
|
|
3373
|
|
3374 (featurep '(or tty-frames (and emacs 19.30)))
|
|
3375 => ; Non-nil if this Emacs supports TTY frames.
|
|
3376
|
|
3377 (featurep '(or (and xemacs 19.15) (and emacs 19.34)))
|
|
3378 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later.
|
|
3379
|
|
3380 NOTE: The advanced arguments of this function (anything other than a
|
|
3381 symbol) are not yet supported by FSF Emacs. If you feel they are useful
|
|
3382 for supporting multiple Emacs variants, lobby Richard Stallman at
|
|
3383 <bug-gnu-emacs@prep.ai.mit.edu>.
|
163
|
3384 */
|
|
3385 (fexp))
|
|
3386 {
|
207
|
3387 #ifndef FEATUREP_SYNTAX
|
|
3388 CHECK_SYMBOL (fexp);
|
|
3389 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt;
|
|
3390 #else /* FEATUREP_SYNTAX */
|
163
|
3391 static double featurep_emacs_version;
|
|
3392
|
|
3393 /* Brute force translation from Erik Naggum's lisp function. */
|
272
|
3394 if (SYMBOLP (fexp))
|
163
|
3395 {
|
|
3396 /* Original definition */
|
|
3397 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt;
|
|
3398 }
|
272
|
3399 else if (INTP (fexp) || FLOATP (fexp))
|
163
|
3400 {
|
272
|
3401 double d = extract_float (fexp);
|
163
|
3402
|
|
3403 if (featurep_emacs_version == 0.0)
|
|
3404 {
|
167
|
3405 featurep_emacs_version = XINT (Vemacs_major_version) +
|
|
3406 (XINT (Vemacs_minor_version) / 100.0);
|
163
|
3407 }
|
173
|
3408 return featurep_emacs_version >= d ? Qt : Qnil;
|
163
|
3409 }
|
272
|
3410 else if (CONSP (fexp))
|
163
|
3411 {
|
272
|
3412 Lisp_Object tem = XCAR (fexp);
|
|
3413 if (EQ (tem, Qnot))
|
163
|
3414 {
|
207
|
3415 Lisp_Object negate;
|
|
3416
|
|
3417 tem = XCDR (fexp);
|
|
3418 negate = Fcar (tem);
|
|
3419 if (!NILP (tem))
|
209
|
3420 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil;
|
163
|
3421 else
|
207
|
3422 return Fsignal (Qinvalid_read_syntax, list1 (tem));
|
163
|
3423 }
|
272
|
3424 else if (EQ (tem, Qand))
|
163
|
3425 {
|
272
|
3426 tem = XCDR (fexp);
|
207
|
3427 /* Use Fcar/Fcdr for error-checking. */
|
209
|
3428 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem))))
|
163
|
3429 {
|
207
|
3430 tem = Fcdr (tem);
|
163
|
3431 }
|
272
|
3432 return NILP (tem) ? Qt : Qnil;
|
163
|
3433 }
|
272
|
3434 else if (EQ (tem, Qor))
|
163
|
3435 {
|
207
|
3436 tem = XCDR (fexp);
|
|
3437 /* Use Fcar/Fcdr for error-checking. */
|
209
|
3438 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem))))
|
163
|
3439 {
|
207
|
3440 tem = Fcdr (tem);
|
163
|
3441 }
|
272
|
3442 return NILP (tem) ? Qnil : Qt;
|
163
|
3443 }
|
|
3444 else
|
|
3445 {
|
272
|
3446 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp)));
|
163
|
3447 }
|
|
3448 }
|
|
3449 else
|
|
3450 {
|
272
|
3451 return Fsignal (Qinvalid_read_syntax, list1 (fexp));
|
163
|
3452 }
|
|
3453 }
|
167
|
3454 #endif /* FEATUREP_SYNTAX */
|
0
|
3455
|
20
|
3456 DEFUN ("provide", Fprovide, 1, 1, 0, /*
|
0
|
3457 Announce that FEATURE is a feature of the current Emacs.
|
2
|
3458 This function updates the value of the variable `features'.
|
20
|
3459 */
|
|
3460 (feature))
|
0
|
3461 {
|
|
3462 Lisp_Object tem;
|
|
3463 CHECK_SYMBOL (feature);
|
|
3464 if (!NILP (Vautoload_queue))
|
|
3465 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
|
|
3466 tem = Fmemq (feature, Vfeatures);
|
|
3467 if (NILP (tem))
|
|
3468 Vfeatures = Fcons (feature, Vfeatures);
|
|
3469 LOADHIST_ATTACH (Fcons (Qprovide, feature));
|
|
3470 return feature;
|
|
3471 }
|
|
3472
|
20
|
3473 DEFUN ("require", Frequire, 1, 2, 0, /*
|
0
|
3474 If feature FEATURE is not loaded, load it from FILENAME.
|
|
3475 If FEATURE is not a member of the list `features', then the feature
|
|
3476 is not loaded; so load the file FILENAME.
|
|
3477 If FILENAME is omitted, the printname of FEATURE is used as the file name.
|
20
|
3478 */
|
|
3479 (feature, file_name))
|
0
|
3480 {
|
|
3481 Lisp_Object tem;
|
|
3482 CHECK_SYMBOL (feature);
|
|
3483 tem = Fmemq (feature, Vfeatures);
|
|
3484 LOADHIST_ATTACH (Fcons (Qrequire, feature));
|
|
3485 if (!NILP (tem))
|
149
|
3486 return feature;
|
0
|
3487 else
|
|
3488 {
|
|
3489 int speccount = specpdl_depth ();
|
|
3490
|
|
3491 /* Value saved here is to be restored into Vautoload_queue */
|
|
3492 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
3493 Vautoload_queue = Qt;
|
|
3494
|
|
3495 call4 (Qload, NILP (file_name) ? Fsymbol_name (feature) : file_name,
|
177
|
3496 Qnil, Qt, Qnil);
|
0
|
3497
|
|
3498 tem = Fmemq (feature, Vfeatures);
|
|
3499 if (NILP (tem))
|
|
3500 error ("Required feature %s was not provided",
|
|
3501 string_data (XSYMBOL (feature)->name));
|
|
3502
|
|
3503 /* Once loading finishes, don't undo it. */
|
|
3504 Vautoload_queue = Qt;
|
149
|
3505 return unbind_to (speccount, feature);
|
0
|
3506 }
|
|
3507 }
|
|
3508
|
|
3509
|
|
3510 Lisp_Object Qyes_or_no_p;
|
|
3511
|
|
3512 void
|
|
3513 syms_of_fns (void)
|
|
3514 {
|
|
3515 defsymbol (&Qstring_lessp, "string-lessp");
|
|
3516 defsymbol (&Qidentity, "identity");
|
|
3517 defsymbol (&Qyes_or_no_p, "yes-or-no-p");
|
|
3518
|
20
|
3519 DEFSUBR (Fidentity);
|
|
3520 DEFSUBR (Frandom);
|
|
3521 DEFSUBR (Flength);
|
|
3522 DEFSUBR (Fsafe_length);
|
|
3523 DEFSUBR (Fstring_equal);
|
|
3524 DEFSUBR (Fstring_lessp);
|
|
3525 DEFSUBR (Fstring_modified_tick);
|
|
3526 DEFSUBR (Fappend);
|
|
3527 DEFSUBR (Fconcat);
|
|
3528 DEFSUBR (Fvconcat);
|
|
3529 DEFSUBR (Fbvconcat);
|
|
3530 DEFSUBR (Fcopy_sequence);
|
|
3531 DEFSUBR (Fcopy_alist);
|
|
3532 DEFSUBR (Fcopy_tree);
|
|
3533 DEFSUBR (Fsubstring);
|
|
3534 DEFSUBR (Fsubseq);
|
|
3535 DEFSUBR (Fnthcdr);
|
|
3536 DEFSUBR (Fnth);
|
|
3537 DEFSUBR (Felt);
|
|
3538 DEFSUBR (Fmember);
|
70
|
3539 DEFSUBR (Fold_member);
|
20
|
3540 DEFSUBR (Fmemq);
|
70
|
3541 DEFSUBR (Fold_memq);
|
20
|
3542 DEFSUBR (Fassoc);
|
70
|
3543 DEFSUBR (Fold_assoc);
|
20
|
3544 DEFSUBR (Fassq);
|
70
|
3545 DEFSUBR (Fold_assq);
|
20
|
3546 DEFSUBR (Frassoc);
|
70
|
3547 DEFSUBR (Fold_rassoc);
|
20
|
3548 DEFSUBR (Frassq);
|
70
|
3549 DEFSUBR (Fold_rassq);
|
20
|
3550 DEFSUBR (Fdelete);
|
70
|
3551 DEFSUBR (Fold_delete);
|
20
|
3552 DEFSUBR (Fdelq);
|
70
|
3553 DEFSUBR (Fold_delq);
|
20
|
3554 DEFSUBR (Fremassoc);
|
|
3555 DEFSUBR (Fremassq);
|
|
3556 DEFSUBR (Fremrassoc);
|
|
3557 DEFSUBR (Fremrassq);
|
|
3558 DEFSUBR (Fnreverse);
|
|
3559 DEFSUBR (Freverse);
|
|
3560 DEFSUBR (Fsort);
|
|
3561 DEFSUBR (Fplists_eq);
|
|
3562 DEFSUBR (Fplists_equal);
|
|
3563 DEFSUBR (Flax_plists_eq);
|
|
3564 DEFSUBR (Flax_plists_equal);
|
|
3565 DEFSUBR (Fplist_get);
|
|
3566 DEFSUBR (Fplist_put);
|
|
3567 DEFSUBR (Fplist_remprop);
|
|
3568 DEFSUBR (Fplist_member);
|
|
3569 DEFSUBR (Fcheck_valid_plist);
|
|
3570 DEFSUBR (Fvalid_plist_p);
|
|
3571 DEFSUBR (Fcanonicalize_plist);
|
|
3572 DEFSUBR (Flax_plist_get);
|
|
3573 DEFSUBR (Flax_plist_put);
|
|
3574 DEFSUBR (Flax_plist_remprop);
|
|
3575 DEFSUBR (Flax_plist_member);
|
|
3576 DEFSUBR (Fcanonicalize_lax_plist);
|
|
3577 DEFSUBR (Fdestructive_alist_to_plist);
|
|
3578 DEFSUBR (Fget);
|
|
3579 DEFSUBR (Fput);
|
|
3580 DEFSUBR (Fremprop);
|
|
3581 DEFSUBR (Fobject_plist);
|
|
3582 DEFSUBR (Fequal);
|
70
|
3583 DEFSUBR (Fold_equal);
|
20
|
3584 DEFSUBR (Ffillarray);
|
|
3585 DEFSUBR (Fnconc);
|
|
3586 DEFSUBR (Fmapcar);
|
163
|
3587 DEFSUBR (Fmapvector);
|
187
|
3588 DEFSUBR (Fmapc);
|
20
|
3589 DEFSUBR (Fmapconcat);
|
|
3590 DEFSUBR (Fload_average);
|
|
3591 DEFSUBR (Ffeaturep);
|
|
3592 DEFSUBR (Frequire);
|
|
3593 DEFSUBR (Fprovide);
|
0
|
3594 }
|
|
3595
|
|
3596 void
|
|
3597 init_provide_once (void)
|
|
3598 {
|
|
3599 DEFVAR_LISP ("features", &Vfeatures /*
|
|
3600 A list of symbols which are the features of the executing emacs.
|
|
3601 Used by `featurep' and `require', and altered by `provide'.
|
|
3602 */ );
|
|
3603 Vfeatures = Qnil;
|
|
3604 }
|