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