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