Mercurial > hg > xemacs-beta
annotate src/fns.c @ 5066:545ec923b4eb
add documentation on keywords to cl*.el
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2010-02-22 Ben Wing <ben@xemacs.org>
* cl-seq.el:
* cl-seq.el (reduce):
* cl-seq.el (fill):
* cl-seq.el (replace):
* cl-seq.el (remove*):
* cl-seq.el (remove-if):
* cl-seq.el (remove-if-not):
* cl-seq.el (delete*):
* cl-seq.el (delete-if):
* cl-seq.el (delete-if-not):
* cl-seq.el (remove-duplicates):
* cl-seq.el (delete-duplicates):
* cl-seq.el (substitute):
* cl-seq.el (substitute-if):
* cl-seq.el (substitute-if-not):
* cl-seq.el (nsubstitute):
* cl-seq.el (nsubstitute-if):
* cl-seq.el (nsubstitute-if-not):
* cl-seq.el (find):
* cl-seq.el (find-if):
* cl-seq.el (find-if-not):
* cl-seq.el (position):
* cl-seq.el (position-if):
* cl-seq.el (position-if-not):
* cl-seq.el (count):
* cl-seq.el (count-if):
* cl-seq.el (count-if-not):
* cl-seq.el (mismatch):
* cl-seq.el (search):
* cl-seq.el (sort*):
* cl-seq.el (stable-sort):
* cl-seq.el (merge):
* cl-seq.el (member*):
* cl-seq.el (member-if):
* cl-seq.el (member-if-not):
* cl-seq.el (assoc*):
* cl-seq.el (assoc-if):
* cl-seq.el (assoc-if-not):
* cl-seq.el (rassoc*):
* cl-seq.el (rassoc-if):
* cl-seq.el (rassoc-if-not):
* cl-seq.el (union):
* cl-seq.el (nunion):
* cl-seq.el (intersection):
* cl-seq.el (nintersection):
* cl-seq.el (set-difference):
* cl-seq.el (nset-difference):
* cl-seq.el (set-exclusive-or):
* cl-seq.el (nset-exclusive-or):
* cl-seq.el (subsetp):
* cl-seq.el (subst-if):
* cl-seq.el (subst-if-not):
* cl-seq.el (nsubst):
* cl-seq.el (nsubst-if):
* cl-seq.el (nsubst-if-not):
* cl-seq.el (sublis):
* cl-seq.el (nsublis):
* cl-seq.el (tree-equal):
* cl-seq.el (cl-tree-equal-rec):
* cl.el:
* cl.el (pushnew):
* cl.el (adjoin):
* cl.el (subst):
Document the keywords to the various sequence/list functions.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Mon, 22 Feb 2010 21:17:47 -0600 |
parents | c3d372419e09 |
children | 99f8ebc082d9 2a462149bd6a |
rev | line source |
---|---|
428 | 1 /* Random utility Lisp functions. |
2 Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc. | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003, 2010 Ben Wing. |
428 | 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 | |
442 | 39 #include "sysfile.h" |
771 | 40 #include "sysproc.h" /* for qxe_getpid() */ |
428 | 41 |
42 #include "buffer.h" | |
43 #include "bytecode.h" | |
44 #include "device.h" | |
45 #include "events.h" | |
46 #include "extents.h" | |
47 #include "frame.h" | |
872 | 48 #include "process.h" |
428 | 49 #include "systime.h" |
50 #include "insdel.h" | |
51 #include "lstream.h" | |
52 #include "opaque.h" | |
53 | |
54 /* NOTE: This symbol is also used in lread.c */ | |
55 #define FEATUREP_SYNTAX | |
56 | |
57 Lisp_Object Qstring_lessp; | |
58 Lisp_Object Qidentity; | |
5002
0cd784a6ec44
fix some compile bugs of Aidan's
Ben Wing <ben@xemacs.org>
parents:
5001
diff
changeset
|
59 Lisp_Object Qvector, Qarray, Qbit_vector; |
428 | 60 |
563 | 61 Lisp_Object Qbase64_conversion_error; |
62 | |
771 | 63 Lisp_Object Vpath_separator; |
64 | |
428 | 65 static int internal_old_equal (Lisp_Object, Lisp_Object, int); |
454 | 66 Lisp_Object safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth); |
428 | 67 |
68 static Lisp_Object | |
2286 | 69 mark_bit_vector (Lisp_Object UNUSED (obj)) |
428 | 70 { |
71 return Qnil; | |
72 } | |
73 | |
74 static void | |
2286 | 75 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, |
76 int UNUSED (escapeflag)) | |
428 | 77 { |
665 | 78 Elemcount i; |
440 | 79 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
665 | 80 Elemcount len = bit_vector_length (v); |
81 Elemcount last = len; | |
428 | 82 |
83 if (INTP (Vprint_length)) | |
84 last = min (len, XINT (Vprint_length)); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
85 write_ascstring (printcharfun, "#*"); |
428 | 86 for (i = 0; i < last; i++) |
87 { | |
88 if (bit_vector_bit (v, i)) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
89 write_ascstring (printcharfun, "1"); |
428 | 90 else |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
91 write_ascstring (printcharfun, "0"); |
428 | 92 } |
93 | |
94 if (last != len) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
95 write_ascstring (printcharfun, "..."); |
428 | 96 } |
97 | |
98 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
99 bit_vector_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth), |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
100 int UNUSED (foldcase)) |
428 | 101 { |
440 | 102 Lisp_Bit_Vector *v1 = XBIT_VECTOR (obj1); |
103 Lisp_Bit_Vector *v2 = XBIT_VECTOR (obj2); | |
428 | 104 |
105 return ((bit_vector_length (v1) == bit_vector_length (v2)) && | |
106 !memcmp (v1->bits, v2->bits, | |
107 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) * | |
108 sizeof (long))); | |
109 } | |
110 | |
665 | 111 static Hashcode |
2286 | 112 bit_vector_hash (Lisp_Object obj, int UNUSED (depth)) |
428 | 113 { |
440 | 114 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
428 | 115 return HASH2 (bit_vector_length (v), |
116 memory_hash (v->bits, | |
117 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) * | |
118 sizeof (long))); | |
119 } | |
120 | |
665 | 121 static Bytecount |
442 | 122 size_bit_vector (const void *lheader) |
123 { | |
124 Lisp_Bit_Vector *v = (Lisp_Bit_Vector *) lheader; | |
456 | 125 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, unsigned long, bits, |
442 | 126 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v))); |
127 } | |
128 | |
1204 | 129 static const struct memory_description bit_vector_description[] = { |
428 | 130 { XD_END } |
131 }; | |
132 | |
133 | |
1204 | 134 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("bit-vector", bit_vector, |
135 1, /*dumpable-flag*/ | |
136 mark_bit_vector, | |
137 print_bit_vector, 0, | |
138 bit_vector_equal, | |
139 bit_vector_hash, | |
140 bit_vector_description, | |
141 size_bit_vector, | |
142 Lisp_Bit_Vector); | |
934 | 143 |
428 | 144 |
145 DEFUN ("identity", Fidentity, 1, 1, 0, /* | |
146 Return the argument unchanged. | |
147 */ | |
148 (arg)) | |
149 { | |
150 return arg; | |
151 } | |
152 | |
153 DEFUN ("random", Frandom, 0, 1, 0, /* | |
154 Return a pseudo-random number. | |
1983 | 155 All fixnums are equally likely. On most systems, this is 31 bits' worth. |
428 | 156 With positive integer argument N, return random number in interval [0,N). |
1983 | 157 N can be a bignum, in which case the range of possible values is extended. |
428 | 158 With argument t, set the random number seed from the current time and pid. |
159 */ | |
160 (limit)) | |
161 { | |
162 EMACS_INT val; | |
163 unsigned long denominator; | |
164 | |
165 if (EQ (limit, Qt)) | |
771 | 166 seed_random (qxe_getpid () + time (NULL)); |
428 | 167 if (NATNUMP (limit) && !ZEROP (limit)) |
168 { | |
169 /* Try to take our random number from the higher bits of VAL, | |
170 not the lower, since (says Gentzel) the low bits of `random' | |
171 are less random than the higher ones. We do this by using the | |
172 quotient rather than the remainder. At the high end of the RNG | |
173 it's possible to get a quotient larger than limit; discarding | |
174 these values eliminates the bias that would otherwise appear | |
175 when using a large limit. */ | |
2039 | 176 denominator = ((unsigned long)1 << INT_VALBITS) / XINT (limit); |
428 | 177 do |
178 val = get_random () / denominator; | |
179 while (val >= XINT (limit)); | |
180 } | |
1983 | 181 #ifdef HAVE_BIGNUM |
182 else if (BIGNUMP (limit)) | |
183 { | |
184 bignum_random (scratch_bignum, XBIGNUM_DATA (limit)); | |
185 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
186 } | |
187 #endif | |
428 | 188 else |
189 val = get_random (); | |
190 | |
191 return make_int (val); | |
192 } | |
193 | |
194 /* Random data-structure functions */ | |
195 | |
196 #ifdef LOSING_BYTECODE | |
197 | |
198 /* #### Delete this shit */ | |
199 | |
200 /* Charcount is a misnomer here as we might be dealing with the | |
201 length of a vector or list, but emphasizes that we're not dealing | |
202 with Bytecounts in strings */ | |
203 static Charcount | |
204 length_with_bytecode_hack (Lisp_Object seq) | |
205 { | |
206 if (!COMPILED_FUNCTIONP (seq)) | |
207 return XINT (Flength (seq)); | |
208 else | |
209 { | |
440 | 210 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (seq); |
428 | 211 |
212 return (f->flags.interactivep ? COMPILED_INTERACTIVE : | |
213 f->flags.domainp ? COMPILED_DOMAIN : | |
214 COMPILED_DOC_STRING) | |
215 + 1; | |
216 } | |
217 } | |
218 | |
219 #endif /* LOSING_BYTECODE */ | |
220 | |
221 void | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
222 check_losing_bytecode (const Ascbyte *function, Lisp_Object seq) |
428 | 223 { |
224 if (COMPILED_FUNCTIONP (seq)) | |
563 | 225 signal_ferror_with_frob |
226 (Qinvalid_argument, seq, | |
428 | 227 "As of 20.3, `%s' no longer works with compiled-function objects", |
228 function); | |
229 } | |
230 | |
231 DEFUN ("length", Flength, 1, 1, 0, /* | |
232 Return the length of vector, bit vector, list or string SEQUENCE. | |
233 */ | |
234 (sequence)) | |
235 { | |
236 retry: | |
237 if (STRINGP (sequence)) | |
826 | 238 return make_int (string_char_length (sequence)); |
428 | 239 else if (CONSP (sequence)) |
240 { | |
665 | 241 Elemcount len; |
428 | 242 GET_EXTERNAL_LIST_LENGTH (sequence, len); |
243 return make_int (len); | |
244 } | |
245 else if (VECTORP (sequence)) | |
246 return make_int (XVECTOR_LENGTH (sequence)); | |
247 else if (NILP (sequence)) | |
248 return Qzero; | |
249 else if (BIT_VECTORP (sequence)) | |
250 return make_int (bit_vector_length (XBIT_VECTOR (sequence))); | |
251 else | |
252 { | |
253 check_losing_bytecode ("length", sequence); | |
254 sequence = wrong_type_argument (Qsequencep, sequence); | |
255 goto retry; | |
256 } | |
257 } | |
258 | |
259 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /* | |
260 Return the length of a list, but avoid error or infinite loop. | |
261 This function never gets an error. If LIST is not really a list, | |
262 it returns 0. If LIST is circular, it returns a finite value | |
263 which is at least the number of distinct elements. | |
264 */ | |
265 (list)) | |
266 { | |
267 Lisp_Object hare, tortoise; | |
665 | 268 Elemcount len; |
428 | 269 |
270 for (hare = tortoise = list, len = 0; | |
271 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); | |
272 hare = XCDR (hare), len++) | |
273 { | |
274 if (len & 1) | |
275 tortoise = XCDR (tortoise); | |
276 } | |
277 | |
278 return make_int (len); | |
279 } | |
280 | |
281 /*** string functions. ***/ | |
282 | |
283 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /* | |
284 Return t if two strings have identical contents. | |
285 Case is significant. Text properties are ignored. | |
286 \(Under XEmacs, `equal' also ignores text properties and extents in | |
287 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20 | |
288 `equal' is the same as in XEmacs, in that respect.) | |
289 Symbols are also allowed; their print names are used instead. | |
290 */ | |
444 | 291 (string1, string2)) |
428 | 292 { |
293 Bytecount len; | |
793 | 294 Lisp_Object p1, p2; |
428 | 295 |
444 | 296 if (SYMBOLP (string1)) |
297 p1 = XSYMBOL (string1)->name; | |
428 | 298 else |
299 { | |
444 | 300 CHECK_STRING (string1); |
793 | 301 p1 = string1; |
428 | 302 } |
303 | |
444 | 304 if (SYMBOLP (string2)) |
305 p2 = XSYMBOL (string2)->name; | |
428 | 306 else |
307 { | |
444 | 308 CHECK_STRING (string2); |
793 | 309 p2 = string2; |
428 | 310 } |
311 | |
793 | 312 return (((len = XSTRING_LENGTH (p1)) == XSTRING_LENGTH (p2)) && |
313 !memcmp (XSTRING_DATA (p1), XSTRING_DATA (p2), len)) ? Qt : Qnil; | |
428 | 314 } |
315 | |
801 | 316 DEFUN ("compare-strings", Fcompare_strings, 6, 7, 0, /* |
317 Compare the contents of two strings, maybe ignoring case. | |
318 In string STR1, skip the first START1 characters and stop at END1. | |
319 In string STR2, skip the first START2 characters and stop at END2. | |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
320 END1 and END2 default to the full lengths of the respective strings, |
4797
a5eca70cf401
Fix typo in last patch.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4796
diff
changeset
|
321 and arguments that are outside the string (negative STARTi or ENDi |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
322 greater than length) are coerced to 0 or string length as appropriate. |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
323 |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
324 Optional IGNORE-CASE non-nil means use case-insensitive comparison. |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
325 Case is significant by default. |
801 | 326 |
327 The value is t if the strings (or specified portions) match. | |
328 If string STR1 is less, the value is a negative number N; | |
329 - 1 - N is the number of characters that match at the beginning. | |
330 If string STR1 is greater, the value is a positive number N; | |
331 N - 1 is the number of characters that match at the beginning. | |
332 */ | |
333 (str1, start1, end1, str2, start2, end2, ignore_case)) | |
334 { | |
335 Charcount ccstart1, ccend1, ccstart2, ccend2; | |
336 Bytecount bstart1, blen1, bstart2, blen2; | |
337 Charcount matching; | |
338 int res; | |
339 | |
340 CHECK_STRING (str1); | |
341 CHECK_STRING (str2); | |
342 get_string_range_char (str1, start1, end1, &ccstart1, &ccend1, | |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
343 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 344 get_string_range_char (str2, start2, end2, &ccstart2, &ccend2, |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
345 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 346 |
347 bstart1 = string_index_char_to_byte (str1, ccstart1); | |
348 blen1 = string_offset_char_to_byte_len (str1, bstart1, ccend1 - ccstart1); | |
349 bstart2 = string_index_char_to_byte (str2, ccstart2); | |
350 blen2 = string_offset_char_to_byte_len (str2, bstart2, ccend2 - ccstart2); | |
351 | |
352 res = ((NILP (ignore_case) ? qxetextcmp_matching : qxetextcasecmp_matching) | |
353 (XSTRING_DATA (str1) + bstart1, blen1, | |
354 XSTRING_DATA (str2) + bstart2, blen2, | |
355 &matching)); | |
356 | |
357 if (!res) | |
358 return Qt; | |
359 else if (res > 0) | |
360 return make_int (1 + matching); | |
361 else | |
362 return make_int (-1 - matching); | |
363 } | |
364 | |
428 | 365 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /* |
366 Return t if first arg string is less than second in lexicographic order. | |
771 | 367 Comparison is simply done on a character-by-character basis using the |
368 numeric value of a character. (Note that this may not produce | |
369 particularly meaningful results under Mule if characters from | |
370 different charsets are being compared.) | |
428 | 371 |
372 Symbols are also allowed; their print names are used instead. | |
373 | |
771 | 374 Currently we don't do proper language-specific collation or handle |
375 multiple character sets. This may be changed when Unicode support | |
376 is implemented. | |
428 | 377 */ |
444 | 378 (string1, string2)) |
428 | 379 { |
793 | 380 Lisp_Object p1, p2; |
428 | 381 Charcount end, len2; |
382 int i; | |
383 | |
444 | 384 if (SYMBOLP (string1)) |
385 p1 = XSYMBOL (string1)->name; | |
793 | 386 else |
387 { | |
444 | 388 CHECK_STRING (string1); |
793 | 389 p1 = string1; |
428 | 390 } |
391 | |
444 | 392 if (SYMBOLP (string2)) |
393 p2 = XSYMBOL (string2)->name; | |
428 | 394 else |
395 { | |
444 | 396 CHECK_STRING (string2); |
793 | 397 p2 = string2; |
428 | 398 } |
399 | |
826 | 400 end = string_char_length (p1); |
401 len2 = string_char_length (p2); | |
428 | 402 if (end > len2) |
403 end = len2; | |
404 | |
405 { | |
867 | 406 Ibyte *ptr1 = XSTRING_DATA (p1); |
407 Ibyte *ptr2 = XSTRING_DATA (p2); | |
428 | 408 |
409 /* #### It is not really necessary to do this: We could compare | |
410 byte-by-byte and still get a reasonable comparison, since this | |
411 would compare characters with a charset in the same way. With | |
412 a little rearrangement of the leading bytes, we could make most | |
413 inter-charset comparisons work out the same, too; even if some | |
414 don't, this is not a big deal because inter-charset comparisons | |
415 aren't really well-defined anyway. */ | |
416 for (i = 0; i < end; i++) | |
417 { | |
867 | 418 if (itext_ichar (ptr1) != itext_ichar (ptr2)) |
419 return itext_ichar (ptr1) < itext_ichar (ptr2) ? Qt : Qnil; | |
420 INC_IBYTEPTR (ptr1); | |
421 INC_IBYTEPTR (ptr2); | |
428 | 422 } |
423 } | |
424 /* Can't do i < len2 because then comparison between "foo" and "foo^@" | |
425 won't work right in I18N2 case */ | |
426 return end < len2 ? Qt : Qnil; | |
427 } | |
428 | |
429 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /* | |
430 Return STRING's tick counter, incremented for each change to the string. | |
431 Each string has a tick counter which is incremented each time the contents | |
432 of the string are changed (e.g. with `aset'). It wraps around occasionally. | |
433 */ | |
434 (string)) | |
435 { | |
436 CHECK_STRING (string); | |
793 | 437 if (CONSP (XSTRING_PLIST (string)) && INTP (XCAR (XSTRING_PLIST (string)))) |
438 return XCAR (XSTRING_PLIST (string)); | |
428 | 439 else |
440 return Qzero; | |
441 } | |
442 | |
443 void | |
444 bump_string_modiff (Lisp_Object str) | |
445 { | |
793 | 446 Lisp_Object *ptr = &XSTRING_PLIST (str); |
428 | 447 |
448 #ifdef I18N3 | |
449 /* #### remove the `string-translatable' property from the string, | |
450 if there is one. */ | |
451 #endif | |
452 /* skip over extent info if it's there */ | |
453 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
454 ptr = &XCDR (*ptr); | |
455 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
793 | 456 XCAR (*ptr) = make_int (1+XINT (XCAR (*ptr))); |
428 | 457 else |
458 *ptr = Fcons (make_int (1), *ptr); | |
459 } | |
460 | |
461 | |
462 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector }; | |
463 static Lisp_Object concat (int nargs, Lisp_Object *args, | |
464 enum concat_target_type target_type, | |
465 int last_special); | |
466 | |
467 Lisp_Object | |
444 | 468 concat2 (Lisp_Object string1, Lisp_Object string2) |
428 | 469 { |
470 Lisp_Object args[2]; | |
444 | 471 args[0] = string1; |
472 args[1] = string2; | |
428 | 473 return concat (2, args, c_string, 0); |
474 } | |
475 | |
476 Lisp_Object | |
444 | 477 concat3 (Lisp_Object string1, Lisp_Object string2, Lisp_Object string3) |
428 | 478 { |
479 Lisp_Object args[3]; | |
444 | 480 args[0] = string1; |
481 args[1] = string2; | |
482 args[2] = string3; | |
428 | 483 return concat (3, args, c_string, 0); |
484 } | |
485 | |
486 Lisp_Object | |
444 | 487 vconcat2 (Lisp_Object vec1, Lisp_Object vec2) |
428 | 488 { |
489 Lisp_Object args[2]; | |
444 | 490 args[0] = vec1; |
491 args[1] = vec2; | |
428 | 492 return concat (2, args, c_vector, 0); |
493 } | |
494 | |
495 Lisp_Object | |
444 | 496 vconcat3 (Lisp_Object vec1, Lisp_Object vec2, Lisp_Object vec3) |
428 | 497 { |
498 Lisp_Object args[3]; | |
444 | 499 args[0] = vec1; |
500 args[1] = vec2; | |
501 args[2] = vec3; | |
428 | 502 return concat (3, args, c_vector, 0); |
503 } | |
504 | |
505 DEFUN ("append", Fappend, 0, MANY, 0, /* | |
506 Concatenate all the arguments and make the result a list. | |
507 The result is a list whose elements are the elements of all the arguments. | |
508 Each argument may be a list, vector, bit vector, or string. | |
509 The last argument is not copied, just used as the tail of the new list. | |
510 Also see: `nconc'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
511 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
512 arguments: (&rest ARGS) |
428 | 513 */ |
514 (int nargs, Lisp_Object *args)) | |
515 { | |
516 return concat (nargs, args, c_cons, 1); | |
517 } | |
518 | |
519 DEFUN ("concat", Fconcat, 0, MANY, 0, /* | |
520 Concatenate all the arguments and make the result a string. | |
521 The result is a string whose elements are the elements of all the arguments. | |
522 Each argument may be a string or a list or vector of characters. | |
523 | |
524 As of XEmacs 21.0, this function does NOT accept individual integers | |
525 as arguments. Old code that relies on, for example, (concat "foo" 50) | |
526 returning "foo50" will fail. To fix such code, either apply | |
527 `int-to-string' to the integer argument, or use `format'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
528 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
529 arguments: (&rest ARGS) |
428 | 530 */ |
531 (int nargs, Lisp_Object *args)) | |
532 { | |
533 return concat (nargs, args, c_string, 0); | |
534 } | |
535 | |
536 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /* | |
537 Concatenate all the arguments and make the result a vector. | |
538 The result is a vector whose elements are the elements of all the arguments. | |
539 Each argument may be a list, vector, bit vector, or string. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
540 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
541 arguments: (&rest ARGS) |
428 | 542 */ |
543 (int nargs, Lisp_Object *args)) | |
544 { | |
545 return concat (nargs, args, c_vector, 0); | |
546 } | |
547 | |
548 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /* | |
549 Concatenate all the arguments and make the result a bit vector. | |
550 The result is a bit vector whose elements are the elements of all the | |
551 arguments. Each argument may be a list, vector, bit vector, or string. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
552 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
553 arguments: (&rest ARGS) |
428 | 554 */ |
555 (int nargs, Lisp_Object *args)) | |
556 { | |
557 return concat (nargs, args, c_bit_vector, 0); | |
558 } | |
559 | |
560 /* Copy a (possibly dotted) list. LIST must be a cons. | |
561 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */ | |
562 static Lisp_Object | |
563 copy_list (Lisp_Object list) | |
564 { | |
565 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list)); | |
566 Lisp_Object last = list_copy; | |
567 Lisp_Object hare, tortoise; | |
665 | 568 Elemcount len; |
428 | 569 |
570 for (tortoise = hare = XCDR (list), len = 1; | |
571 CONSP (hare); | |
572 hare = XCDR (hare), len++) | |
573 { | |
574 XCDR (last) = Fcons (XCAR (hare), XCDR (hare)); | |
575 last = XCDR (last); | |
576 | |
577 if (len < CIRCULAR_LIST_SUSPICION_LENGTH) | |
578 continue; | |
579 if (len & 1) | |
580 tortoise = XCDR (tortoise); | |
581 if (EQ (tortoise, hare)) | |
582 signal_circular_list_error (list); | |
583 } | |
584 | |
585 return list_copy; | |
586 } | |
587 | |
588 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /* | |
589 Return a copy of list LIST, which may be a dotted list. | |
590 The elements of LIST are not copied; they are shared | |
591 with the original. | |
592 */ | |
593 (list)) | |
594 { | |
595 again: | |
596 if (NILP (list)) return list; | |
597 if (CONSP (list)) return copy_list (list); | |
598 | |
599 list = wrong_type_argument (Qlistp, list); | |
600 goto again; | |
601 } | |
602 | |
603 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /* | |
604 Return a copy of list, vector, bit vector or string SEQUENCE. | |
605 The elements of a list or vector are not copied; they are shared | |
606 with the original. SEQUENCE may be a dotted list. | |
607 */ | |
608 (sequence)) | |
609 { | |
610 again: | |
611 if (NILP (sequence)) return sequence; | |
612 if (CONSP (sequence)) return copy_list (sequence); | |
613 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0); | |
614 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0); | |
615 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0); | |
616 | |
617 check_losing_bytecode ("copy-sequence", sequence); | |
618 sequence = wrong_type_argument (Qsequencep, sequence); | |
619 goto again; | |
620 } | |
621 | |
622 struct merge_string_extents_struct | |
623 { | |
624 Lisp_Object string; | |
625 Bytecount entry_offset; | |
626 Bytecount entry_length; | |
627 }; | |
628 | |
629 static Lisp_Object | |
630 concat (int nargs, Lisp_Object *args, | |
631 enum concat_target_type target_type, | |
632 int last_special) | |
633 { | |
634 Lisp_Object val; | |
635 Lisp_Object tail = Qnil; | |
636 int toindex; | |
637 int argnum; | |
638 Lisp_Object last_tail; | |
639 Lisp_Object prev; | |
640 struct merge_string_extents_struct *args_mse = 0; | |
867 | 641 Ibyte *string_result = 0; |
642 Ibyte *string_result_ptr = 0; | |
428 | 643 struct gcpro gcpro1; |
851 | 644 int sdep = specpdl_depth (); |
428 | 645 |
646 /* The modus operandi in Emacs is "caller gc-protects args". | |
647 However, concat is called many times in Emacs on freshly | |
648 created stuff. So we help those callers out by protecting | |
649 the args ourselves to save them a lot of temporary-variable | |
650 grief. */ | |
651 | |
652 GCPRO1 (args[0]); | |
653 gcpro1.nvars = nargs; | |
654 | |
655 #ifdef I18N3 | |
656 /* #### if the result is a string and any of the strings have a string | |
657 for the `string-translatable' property, then concat should also | |
658 concat the args but use the `string-translatable' strings, and store | |
659 the result in the returned string's `string-translatable' property. */ | |
660 #endif | |
661 if (target_type == c_string) | |
662 args_mse = alloca_array (struct merge_string_extents_struct, nargs); | |
663 | |
664 /* In append, the last arg isn't treated like the others */ | |
665 if (last_special && nargs > 0) | |
666 { | |
667 nargs--; | |
668 last_tail = args[nargs]; | |
669 } | |
670 else | |
671 last_tail = Qnil; | |
672 | |
673 /* Check and coerce the arguments. */ | |
674 for (argnum = 0; argnum < nargs; argnum++) | |
675 { | |
676 Lisp_Object seq = args[argnum]; | |
677 if (LISTP (seq)) | |
678 ; | |
679 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq)) | |
680 ; | |
681 #ifdef LOSING_BYTECODE | |
682 else if (COMPILED_FUNCTIONP (seq)) | |
683 /* Urk! We allow this, for "compatibility"... */ | |
684 ; | |
685 #endif | |
686 #if 0 /* removed for XEmacs 21 */ | |
687 else if (INTP (seq)) | |
688 /* This is too revolting to think about but maintains | |
689 compatibility with FSF (and lots and lots of old code). */ | |
690 args[argnum] = Fnumber_to_string (seq); | |
691 #endif | |
692 else | |
693 { | |
694 check_losing_bytecode ("concat", seq); | |
695 args[argnum] = wrong_type_argument (Qsequencep, seq); | |
696 } | |
697 | |
698 if (args_mse) | |
699 { | |
700 if (STRINGP (seq)) | |
701 args_mse[argnum].string = seq; | |
702 else | |
703 args_mse[argnum].string = Qnil; | |
704 } | |
705 } | |
706 | |
707 { | |
708 /* Charcount is a misnomer here as we might be dealing with the | |
709 length of a vector or list, but emphasizes that we're not dealing | |
710 with Bytecounts in strings */ | |
711 Charcount total_length; | |
712 | |
713 for (argnum = 0, total_length = 0; argnum < nargs; argnum++) | |
714 { | |
715 #ifdef LOSING_BYTECODE | |
716 Charcount thislen = length_with_bytecode_hack (args[argnum]); | |
717 #else | |
718 Charcount thislen = XINT (Flength (args[argnum])); | |
719 #endif | |
720 total_length += thislen; | |
721 } | |
722 | |
723 switch (target_type) | |
724 { | |
725 case c_cons: | |
726 if (total_length == 0) | |
851 | 727 { |
728 unbind_to (sdep); | |
729 /* In append, if all but last arg are nil, return last arg */ | |
730 RETURN_UNGCPRO (last_tail); | |
731 } | |
428 | 732 val = Fmake_list (make_int (total_length), Qnil); |
733 break; | |
734 case c_vector: | |
735 val = make_vector (total_length, Qnil); | |
736 break; | |
737 case c_bit_vector: | |
738 val = make_bit_vector (total_length, Qzero); | |
739 break; | |
740 case c_string: | |
741 /* We don't make the string yet because we don't know the | |
742 actual number of bytes. This loop was formerly written | |
743 to call Fmake_string() here and then call set_string_char() | |
744 for each char. This seems logical enough but is waaaaaaaay | |
745 slow -- set_string_char() has to scan the whole string up | |
746 to the place where the substitution is called for in order | |
747 to find the place to change, and may have to do some | |
748 realloc()ing in order to make the char fit properly. | |
749 O(N^2) yuckage. */ | |
750 val = Qnil; | |
851 | 751 string_result = |
867 | 752 (Ibyte *) MALLOC_OR_ALLOCA (total_length * MAX_ICHAR_LEN); |
428 | 753 string_result_ptr = string_result; |
754 break; | |
755 default: | |
442 | 756 val = Qnil; |
2500 | 757 ABORT (); |
428 | 758 } |
759 } | |
760 | |
761 | |
762 if (CONSP (val)) | |
763 tail = val, toindex = -1; /* -1 in toindex is flag we are | |
764 making a list */ | |
765 else | |
766 toindex = 0; | |
767 | |
768 prev = Qnil; | |
769 | |
770 for (argnum = 0; argnum < nargs; argnum++) | |
771 { | |
772 Charcount thisleni = 0; | |
773 Charcount thisindex = 0; | |
774 Lisp_Object seq = args[argnum]; | |
867 | 775 Ibyte *string_source_ptr = 0; |
776 Ibyte *string_prev_result_ptr = string_result_ptr; | |
428 | 777 |
778 if (!CONSP (seq)) | |
779 { | |
780 #ifdef LOSING_BYTECODE | |
781 thisleni = length_with_bytecode_hack (seq); | |
782 #else | |
783 thisleni = XINT (Flength (seq)); | |
784 #endif | |
785 } | |
786 if (STRINGP (seq)) | |
787 string_source_ptr = XSTRING_DATA (seq); | |
788 | |
789 while (1) | |
790 { | |
791 Lisp_Object elt; | |
792 | |
793 /* We've come to the end of this arg, so exit. */ | |
794 if (NILP (seq)) | |
795 break; | |
796 | |
797 /* Fetch next element of `seq' arg into `elt' */ | |
798 if (CONSP (seq)) | |
799 { | |
800 elt = XCAR (seq); | |
801 seq = XCDR (seq); | |
802 } | |
803 else | |
804 { | |
805 if (thisindex >= thisleni) | |
806 break; | |
807 | |
808 if (STRINGP (seq)) | |
809 { | |
867 | 810 elt = make_char (itext_ichar (string_source_ptr)); |
811 INC_IBYTEPTR (string_source_ptr); | |
428 | 812 } |
813 else if (VECTORP (seq)) | |
814 elt = XVECTOR_DATA (seq)[thisindex]; | |
815 else if (BIT_VECTORP (seq)) | |
816 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq), | |
817 thisindex)); | |
818 else | |
819 elt = Felt (seq, make_int (thisindex)); | |
820 thisindex++; | |
821 } | |
822 | |
823 /* Store into result */ | |
824 if (toindex < 0) | |
825 { | |
826 /* toindex negative means we are making a list */ | |
827 XCAR (tail) = elt; | |
828 prev = tail; | |
829 tail = XCDR (tail); | |
830 } | |
831 else if (VECTORP (val)) | |
832 XVECTOR_DATA (val)[toindex++] = elt; | |
833 else if (BIT_VECTORP (val)) | |
834 { | |
835 CHECK_BIT (elt); | |
836 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt)); | |
837 } | |
838 else | |
839 { | |
840 CHECK_CHAR_COERCE_INT (elt); | |
867 | 841 string_result_ptr += set_itext_ichar (string_result_ptr, |
428 | 842 XCHAR (elt)); |
843 } | |
844 } | |
845 if (args_mse) | |
846 { | |
847 args_mse[argnum].entry_offset = | |
848 string_prev_result_ptr - string_result; | |
849 args_mse[argnum].entry_length = | |
850 string_result_ptr - string_prev_result_ptr; | |
851 } | |
852 } | |
853 | |
854 /* Now we finally make the string. */ | |
855 if (target_type == c_string) | |
856 { | |
857 val = make_string (string_result, string_result_ptr - string_result); | |
858 for (argnum = 0; argnum < nargs; argnum++) | |
859 { | |
860 if (STRINGP (args_mse[argnum].string)) | |
861 copy_string_extents (val, args_mse[argnum].string, | |
862 args_mse[argnum].entry_offset, 0, | |
863 args_mse[argnum].entry_length); | |
864 } | |
865 } | |
866 | |
867 if (!NILP (prev)) | |
868 XCDR (prev) = last_tail; | |
869 | |
851 | 870 unbind_to (sdep); |
428 | 871 RETURN_UNGCPRO (val); |
872 } | |
873 | |
874 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /* | |
875 Return a copy of ALIST. | |
876 This is an alist which represents the same mapping from objects to objects, | |
877 but does not share the alist structure with ALIST. | |
878 The objects mapped (cars and cdrs of elements of the alist) | |
879 are shared, however. | |
880 Elements of ALIST that are not conses are also shared. | |
881 */ | |
882 (alist)) | |
883 { | |
884 Lisp_Object tail; | |
885 | |
886 if (NILP (alist)) | |
887 return alist; | |
888 CHECK_CONS (alist); | |
889 | |
890 alist = concat (1, &alist, c_cons, 0); | |
891 for (tail = alist; CONSP (tail); tail = XCDR (tail)) | |
892 { | |
893 Lisp_Object car = XCAR (tail); | |
894 | |
895 if (CONSP (car)) | |
896 XCAR (tail) = Fcons (XCAR (car), XCDR (car)); | |
897 } | |
898 return alist; | |
899 } | |
900 | |
901 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /* | |
902 Return a copy of a list and substructures. | |
903 The argument is copied, and any lists contained within it are copied | |
904 recursively. Circularities and shared substructures are not preserved. | |
905 Second arg VECP causes vectors to be copied, too. Strings and bit vectors | |
906 are not copied. | |
907 */ | |
908 (arg, vecp)) | |
909 { | |
454 | 910 return safe_copy_tree (arg, vecp, 0); |
911 } | |
912 | |
913 Lisp_Object | |
914 safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth) | |
915 { | |
916 if (depth > 200) | |
563 | 917 stack_overflow ("Stack overflow in copy-tree", arg); |
454 | 918 |
428 | 919 if (CONSP (arg)) |
920 { | |
921 Lisp_Object rest; | |
922 rest = arg = Fcopy_sequence (arg); | |
923 while (CONSP (rest)) | |
924 { | |
925 Lisp_Object elt = XCAR (rest); | |
926 QUIT; | |
927 if (CONSP (elt) || VECTORP (elt)) | |
454 | 928 XCAR (rest) = safe_copy_tree (elt, vecp, depth + 1); |
428 | 929 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */ |
454 | 930 XCDR (rest) = safe_copy_tree (XCDR (rest), vecp, depth +1); |
428 | 931 rest = XCDR (rest); |
932 } | |
933 } | |
934 else if (VECTORP (arg) && ! NILP (vecp)) | |
935 { | |
936 int i = XVECTOR_LENGTH (arg); | |
937 int j; | |
938 arg = Fcopy_sequence (arg); | |
939 for (j = 0; j < i; j++) | |
940 { | |
941 Lisp_Object elt = XVECTOR_DATA (arg) [j]; | |
942 QUIT; | |
943 if (CONSP (elt) || VECTORP (elt)) | |
454 | 944 XVECTOR_DATA (arg) [j] = safe_copy_tree (elt, vecp, depth + 1); |
428 | 945 } |
946 } | |
947 return arg; | |
948 } | |
949 | |
950 DEFUN ("substring", Fsubstring, 2, 3, 0, /* | |
444 | 951 Return the substring of STRING starting at START and ending before END. |
952 END may be nil or omitted; then the substring runs to the end of STRING. | |
953 If START or END is negative, it counts from the end. | |
954 Relevant parts of the string-extent-data are copied to the new string. | |
428 | 955 */ |
444 | 956 (string, start, end)) |
428 | 957 { |
444 | 958 Charcount ccstart, ccend; |
959 Bytecount bstart, blen; | |
428 | 960 Lisp_Object val; |
961 | |
962 CHECK_STRING (string); | |
444 | 963 CHECK_INT (start); |
964 get_string_range_char (string, start, end, &ccstart, &ccend, | |
428 | 965 GB_HISTORICAL_STRING_BEHAVIOR); |
793 | 966 bstart = string_index_char_to_byte (string, ccstart); |
967 blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart); | |
444 | 968 val = make_string (XSTRING_DATA (string) + bstart, blen); |
969 /* Copy any applicable extent information into the new string. */ | |
970 copy_string_extents (val, string, 0, bstart, blen); | |
428 | 971 return val; |
972 } | |
973 | |
974 DEFUN ("subseq", Fsubseq, 2, 3, 0, /* | |
442 | 975 Return the subsequence of SEQUENCE starting at START and ending before END. |
976 END may be omitted; then the subsequence runs to the end of SEQUENCE. | |
977 If START or END is negative, it counts from the end. | |
978 The returned subsequence is always of the same type as SEQUENCE. | |
979 If SEQUENCE is a string, relevant parts of the string-extent-data | |
980 are copied to the new string. | |
428 | 981 */ |
442 | 982 (sequence, start, end)) |
428 | 983 { |
442 | 984 EMACS_INT len, s, e; |
985 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
986 CHECK_SEQUENCE (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
987 |
442 | 988 if (STRINGP (sequence)) |
989 return Fsubstring (sequence, start, end); | |
990 | |
991 len = XINT (Flength (sequence)); | |
992 | |
993 CHECK_INT (start); | |
994 s = XINT (start); | |
995 if (s < 0) | |
996 s = len + s; | |
997 | |
998 if (NILP (end)) | |
999 e = len; | |
428 | 1000 else |
1001 { | |
442 | 1002 CHECK_INT (end); |
1003 e = XINT (end); | |
1004 if (e < 0) | |
1005 e = len + e; | |
428 | 1006 } |
1007 | |
442 | 1008 if (!(0 <= s && s <= e && e <= len)) |
1009 args_out_of_range_3 (sequence, make_int (s), make_int (e)); | |
1010 | |
1011 if (VECTORP (sequence)) | |
428 | 1012 { |
442 | 1013 Lisp_Object result = make_vector (e - s, Qnil); |
428 | 1014 EMACS_INT i; |
442 | 1015 Lisp_Object *in_elts = XVECTOR_DATA (sequence); |
428 | 1016 Lisp_Object *out_elts = XVECTOR_DATA (result); |
1017 | |
442 | 1018 for (i = s; i < e; i++) |
1019 out_elts[i - s] = in_elts[i]; | |
428 | 1020 return result; |
1021 } | |
442 | 1022 else if (LISTP (sequence)) |
428 | 1023 { |
1024 Lisp_Object result = Qnil; | |
1025 EMACS_INT i; | |
1026 | |
442 | 1027 sequence = Fnthcdr (make_int (s), sequence); |
1028 | |
1029 for (i = s; i < e; i++) | |
428 | 1030 { |
442 | 1031 result = Fcons (Fcar (sequence), result); |
1032 sequence = Fcdr (sequence); | |
428 | 1033 } |
1034 | |
1035 return Fnreverse (result); | |
1036 } | |
442 | 1037 else if (BIT_VECTORP (sequence)) |
1038 { | |
1039 Lisp_Object result = make_bit_vector (e - s, Qzero); | |
1040 EMACS_INT i; | |
1041 | |
1042 for (i = s; i < e; i++) | |
1043 set_bit_vector_bit (XBIT_VECTOR (result), i - s, | |
1044 bit_vector_bit (XBIT_VECTOR (sequence), i)); | |
1045 return result; | |
1046 } | |
1047 else | |
1048 { | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1049 ABORT (); /* unreachable, since CHECK_SEQUENCE (sequence) did not |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1050 error */ |
442 | 1051 return Qnil; |
1052 } | |
428 | 1053 } |
1054 | |
771 | 1055 /* Split STRING into a list of substrings. The substrings are the |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1056 parts of original STRING separated by SEPCHAR. |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1057 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1058 If UNESCAPE is non-zero, ESCAPECHAR specifies a character that will quote |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1059 SEPCHAR, and cause it not to split STRING. A double ESCAPECHAR is |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1060 necessary for ESCAPECHAR to appear once in a substring. */ |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1061 |
771 | 1062 static Lisp_Object |
867 | 1063 split_string_by_ichar_1 (const Ibyte *string, Bytecount size, |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1064 Ichar sepchar, int unescape, Ichar escapechar) |
771 | 1065 { |
1066 Lisp_Object result = Qnil; | |
867 | 1067 const Ibyte *end = string + size; |
771 | 1068 |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1069 if (unescape) |
771 | 1070 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1071 Ibyte unescape_buffer[64], *unescape_buffer_ptr = unescape_buffer, |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1072 escaped[MAX_ICHAR_LEN], *unescape_cursor; |
5036
9624523604c5
Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5035
diff
changeset
|
1073 Bytecount unescape_buffer_size = countof (unescape_buffer), |
9624523604c5
Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5035
diff
changeset
|
1074 escaped_len = set_itext_ichar (escaped, escapechar); |
9624523604c5
Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5035
diff
changeset
|
1075 Boolint deleting_escapes, previous_escaped; |
9624523604c5
Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5035
diff
changeset
|
1076 Ichar pchar; |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1077 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1078 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1079 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1080 const Ibyte *p = string, *cursor; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1081 deleting_escapes = 0; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1082 previous_escaped = 0; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1083 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1084 while (p < end) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1085 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1086 pchar = itext_ichar (p); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1087 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1088 if (pchar == sepchar) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1089 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1090 if (!previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1091 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1092 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1093 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1094 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1095 else if (pchar == escapechar |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1096 /* Doubled escapes don't escape: */ |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1097 && !previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1098 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1099 ++deleting_escapes; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1100 previous_escaped = 1; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1101 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1102 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1103 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1104 previous_escaped = 0; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1105 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1106 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1107 INC_IBYTEPTR (p); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1108 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1109 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1110 if (deleting_escapes) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1111 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1112 if (((p - string) - (escaped_len * deleting_escapes)) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1113 > unescape_buffer_size) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1114 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1115 unescape_buffer_size = |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1116 ((p - string) - (escaped_len * deleting_escapes)) * 1.5; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1117 unescape_buffer_ptr = alloca_ibytes (unescape_buffer_size); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1118 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1119 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1120 cursor = string; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1121 unescape_cursor = unescape_buffer_ptr; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1122 previous_escaped = 0; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1123 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1124 while (cursor < p) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1125 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1126 pchar = itext_ichar (cursor); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1127 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1128 if (pchar != escapechar || previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1129 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1130 memcpy (unescape_cursor, cursor, |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1131 itext_ichar_len (cursor)); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1132 INC_IBYTEPTR (unescape_cursor); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1133 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1134 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1135 previous_escaped = !previous_escaped |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1136 && (pchar == escapechar); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1137 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1138 INC_IBYTEPTR (cursor); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1139 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1140 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1141 result = Fcons (make_string (unescape_buffer_ptr, |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1142 unescape_cursor |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1143 - unescape_buffer_ptr), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1144 result); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1145 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1146 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1147 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1148 result = Fcons (make_string (string, p - string), result); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1149 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1150 if (p < end) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1151 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1152 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1153 INC_IBYTEPTR (string); /* skip sepchar */ |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1154 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1155 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1156 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1157 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1158 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1159 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1160 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1161 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1162 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1163 const Ibyte *p = string; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1164 while (p < end) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1165 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1166 if (itext_ichar (p) == sepchar) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1167 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1168 INC_IBYTEPTR (p); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1169 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1170 result = Fcons (make_string (string, p - string), result); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1171 if (p < end) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1172 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1173 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1174 INC_IBYTEPTR (string); /* skip sepchar */ |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1175 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1176 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1177 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1178 } |
771 | 1179 } |
1180 return Fnreverse (result); | |
1181 } | |
1182 | |
1183 /* The same as the above, except PATH is an external C string (it is | |
1184 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR | |
1185 (':' or whatever). */ | |
1186 Lisp_Object | |
1187 split_external_path (const Extbyte *path) | |
1188 { | |
1189 Bytecount newlen; | |
867 | 1190 Ibyte *newpath; |
771 | 1191 if (!path) |
1192 return Qnil; | |
1193 | |
1194 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name); | |
1195 | |
1196 /* #### Does this make sense? It certainly does for | |
1197 split_env_path(), but it looks dubious here. Does any code | |
1198 depend on split_external_path("") returning nil instead of an empty | |
1199 string? */ | |
1200 if (!newlen) | |
1201 return Qnil; | |
1202 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1203 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR, 0, 0); |
771 | 1204 } |
1205 | |
1206 Lisp_Object | |
867 | 1207 split_env_path (const CIbyte *evarname, const Ibyte *default_) |
771 | 1208 { |
867 | 1209 const Ibyte *path = 0; |
771 | 1210 if (evarname) |
1211 path = egetenv (evarname); | |
1212 if (!path) | |
1213 path = default_; | |
1214 if (!path) | |
1215 return Qnil; | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1216 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR, 0, 0); |
771 | 1217 } |
1218 | |
1219 /* Ben thinks this function should not exist or be exported to Lisp. | |
1220 We use it to define split-path-string in subr.el (not!). */ | |
1221 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1222 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 3, 0, /* |
771 | 1223 Split STRING into a list of substrings originally separated by SEPCHAR. |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1224 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1225 With optional ESCAPE-CHAR, any instances of SEPCHAR preceded by that |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1226 character will not split the string, and a double instance of ESCAPE-CHAR |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1227 will be necessary for a single ESCAPE-CHAR to appear in the output string. |
771 | 1228 */ |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1229 (string, sepchar, escape_char)) |
771 | 1230 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1231 Ichar escape_ichar = 0; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1232 |
771 | 1233 CHECK_STRING (string); |
1234 CHECK_CHAR (sepchar); | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1235 if (!NILP (escape_char)) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1236 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1237 CHECK_CHAR (escape_char); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1238 escape_ichar = XCHAR (escape_char); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1239 } |
867 | 1240 return split_string_by_ichar_1 (XSTRING_DATA (string), |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1241 XSTRING_LENGTH (string), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1242 XCHAR (sepchar), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1243 !NILP (escape_char), escape_ichar); |
771 | 1244 } |
1245 | |
1246 /* #### This was supposed to be in subr.el, but is used VERY early in | |
1247 the bootstrap process, so it goes here. Damn. */ | |
1248 | |
1249 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /* | |
1250 Explode a search path into a list of strings. | |
1251 The path components are separated with the characters specified | |
1252 with `path-separator'. | |
1253 */ | |
1254 (path)) | |
1255 { | |
1256 CHECK_STRING (path); | |
1257 | |
1258 while (!STRINGP (Vpath_separator) | |
826 | 1259 || (string_char_length (Vpath_separator) != 1)) |
771 | 1260 Vpath_separator = signal_continuable_error |
1261 (Qinvalid_state, | |
1262 "`path-separator' should be set to a single-character string", | |
1263 Vpath_separator); | |
1264 | |
867 | 1265 return (split_string_by_ichar_1 |
771 | 1266 (XSTRING_DATA (path), XSTRING_LENGTH (path), |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1267 itext_ichar (XSTRING_DATA (Vpath_separator)), 0, 0)); |
771 | 1268 } |
1269 | |
428 | 1270 |
1271 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* | |
1272 Take cdr N times on LIST, and return the result. | |
1273 */ | |
1274 (n, list)) | |
1275 { | |
1920 | 1276 /* This function can GC */ |
647 | 1277 REGISTER EMACS_INT i; |
428 | 1278 REGISTER Lisp_Object tail = list; |
1279 CHECK_NATNUM (n); | |
1280 for (i = XINT (n); i; i--) | |
1281 { | |
1282 if (CONSP (tail)) | |
1283 tail = XCDR (tail); | |
1284 else if (NILP (tail)) | |
1285 return Qnil; | |
1286 else | |
1287 { | |
1288 tail = wrong_type_argument (Qlistp, tail); | |
1289 i++; | |
1290 } | |
1291 } | |
1292 return tail; | |
1293 } | |
1294 | |
1295 DEFUN ("nth", Fnth, 2, 2, 0, /* | |
1296 Return the Nth element of LIST. | |
1297 N counts from zero. If LIST is not that long, nil is returned. | |
1298 */ | |
1299 (n, list)) | |
1300 { | |
1920 | 1301 /* This function can GC */ |
428 | 1302 return Fcar (Fnthcdr (n, list)); |
1303 } | |
1304 | |
1305 DEFUN ("elt", Felt, 2, 2, 0, /* | |
1306 Return element of SEQUENCE at index N. | |
1307 */ | |
1308 (sequence, n)) | |
1309 { | |
1920 | 1310 /* This function can GC */ |
428 | 1311 retry: |
1312 CHECK_INT_COERCE_CHAR (n); /* yuck! */ | |
1313 if (LISTP (sequence)) | |
1314 { | |
1315 Lisp_Object tem = Fnthcdr (n, sequence); | |
1316 /* #### Utterly, completely, fucking disgusting. | |
1317 * #### The whole point of "elt" is that it operates on | |
1318 * #### sequences, and does error- (bounds-) checking. | |
1319 */ | |
1320 if (CONSP (tem)) | |
1321 return XCAR (tem); | |
1322 else | |
1323 #if 1 | |
1324 /* This is The Way It Has Always Been. */ | |
1325 return Qnil; | |
1326 #else | |
1327 /* This is The Way Mly and Cltl2 say It Should Be. */ | |
1328 args_out_of_range (sequence, n); | |
1329 #endif | |
1330 } | |
1331 else if (STRINGP (sequence) || | |
1332 VECTORP (sequence) || | |
1333 BIT_VECTORP (sequence)) | |
1334 return Faref (sequence, n); | |
1335 #ifdef LOSING_BYTECODE | |
1336 else if (COMPILED_FUNCTIONP (sequence)) | |
1337 { | |
1338 EMACS_INT idx = XINT (n); | |
1339 if (idx < 0) | |
1340 { | |
1341 lose: | |
1342 args_out_of_range (sequence, n); | |
1343 } | |
1344 /* Utter perversity */ | |
1345 { | |
1346 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence); | |
1347 switch (idx) | |
1348 { | |
1349 case COMPILED_ARGLIST: | |
1350 return compiled_function_arglist (f); | |
1351 case COMPILED_INSTRUCTIONS: | |
1352 return compiled_function_instructions (f); | |
1353 case COMPILED_CONSTANTS: | |
1354 return compiled_function_constants (f); | |
1355 case COMPILED_STACK_DEPTH: | |
1356 return compiled_function_stack_depth (f); | |
1357 case COMPILED_DOC_STRING: | |
1358 return compiled_function_documentation (f); | |
1359 case COMPILED_DOMAIN: | |
1360 return compiled_function_domain (f); | |
1361 case COMPILED_INTERACTIVE: | |
1362 if (f->flags.interactivep) | |
1363 return compiled_function_interactive (f); | |
1364 /* if we return nil, can't tell interactive with no args | |
1365 from noninteractive. */ | |
1366 goto lose; | |
1367 default: | |
1368 goto lose; | |
1369 } | |
1370 } | |
1371 } | |
1372 #endif /* LOSING_BYTECODE */ | |
1373 else | |
1374 { | |
1375 check_losing_bytecode ("elt", sequence); | |
1376 sequence = wrong_type_argument (Qsequencep, sequence); | |
1377 goto retry; | |
1378 } | |
1379 } | |
1380 | |
1381 DEFUN ("last", Flast, 1, 2, 0, /* | |
1382 Return the tail of list LIST, of length N (default 1). | |
1383 LIST may be a dotted list, but not a circular list. | |
1384 Optional argument N must be a non-negative integer. | |
1385 If N is zero, then the atom that terminates the list is returned. | |
1386 If N is greater than the length of LIST, then LIST itself is returned. | |
1387 */ | |
1388 (list, n)) | |
1389 { | |
1390 EMACS_INT int_n, count; | |
1391 Lisp_Object retval, tortoise, hare; | |
1392 | |
1393 CHECK_LIST (list); | |
1394 | |
1395 if (NILP (n)) | |
1396 int_n = 1; | |
1397 else | |
1398 { | |
1399 CHECK_NATNUM (n); | |
1400 int_n = XINT (n); | |
1401 } | |
1402 | |
1403 for (retval = tortoise = hare = list, count = 0; | |
1404 CONSP (hare); | |
1405 hare = XCDR (hare), | |
1406 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0), | |
1407 count++) | |
1408 { | |
1409 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
1410 | |
1411 if (count & 1) | |
1412 tortoise = XCDR (tortoise); | |
1413 if (EQ (hare, tortoise)) | |
1414 signal_circular_list_error (list); | |
1415 } | |
1416 | |
1417 return retval; | |
1418 } | |
1419 | |
1420 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /* | |
1421 Modify LIST to remove the last N (default 1) elements. | |
1422 If LIST has N or fewer elements, nil is returned and LIST is unmodified. | |
1423 */ | |
1424 (list, n)) | |
1425 { | |
1426 EMACS_INT int_n; | |
1427 | |
1428 CHECK_LIST (list); | |
1429 | |
1430 if (NILP (n)) | |
1431 int_n = 1; | |
1432 else | |
1433 { | |
1434 CHECK_NATNUM (n); | |
1435 int_n = XINT (n); | |
1436 } | |
1437 | |
1438 { | |
1439 Lisp_Object last_cons = list; | |
1440 | |
1441 EXTERNAL_LIST_LOOP_1 (list) | |
1442 { | |
1443 if (int_n-- < 0) | |
1444 last_cons = XCDR (last_cons); | |
1445 } | |
1446 | |
1447 if (int_n >= 0) | |
1448 return Qnil; | |
1449 | |
1450 XCDR (last_cons) = Qnil; | |
1451 return list; | |
1452 } | |
1453 } | |
1454 | |
1455 DEFUN ("butlast", Fbutlast, 1, 2, 0, /* | |
1456 Return a copy of LIST with the last N (default 1) elements removed. | |
1457 If LIST has N or fewer elements, nil is returned. | |
1458 */ | |
1459 (list, n)) | |
1460 { | |
444 | 1461 EMACS_INT int_n; |
428 | 1462 |
1463 CHECK_LIST (list); | |
1464 | |
1465 if (NILP (n)) | |
1466 int_n = 1; | |
1467 else | |
1468 { | |
1469 CHECK_NATNUM (n); | |
1470 int_n = XINT (n); | |
1471 } | |
1472 | |
1473 { | |
1474 Lisp_Object retval = Qnil; | |
1475 Lisp_Object tail = list; | |
1476 | |
1477 EXTERNAL_LIST_LOOP_1 (list) | |
1478 { | |
1479 if (--int_n < 0) | |
1480 { | |
1481 retval = Fcons (XCAR (tail), retval); | |
1482 tail = XCDR (tail); | |
1483 } | |
1484 } | |
1485 | |
1486 return Fnreverse (retval); | |
1487 } | |
1488 } | |
1489 | |
1490 DEFUN ("member", Fmember, 2, 2, 0, /* | |
1491 Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | |
1492 The value is actually the tail of LIST whose car is ELT. | |
1493 */ | |
1494 (elt, list)) | |
1495 { | |
1496 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1497 { | |
1498 if (internal_equal (elt, list_elt, 0)) | |
1499 return tail; | |
1500 } | |
1501 return Qnil; | |
1502 } | |
1503 | |
1504 DEFUN ("old-member", Fold_member, 2, 2, 0, /* | |
1505 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'. | |
1506 The value is actually the tail of LIST whose car is ELT. | |
1507 This function is provided only for byte-code compatibility with v19. | |
1508 Do not use it. | |
1509 */ | |
1510 (elt, list)) | |
1511 { | |
1512 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1513 { | |
1514 if (internal_old_equal (elt, list_elt, 0)) | |
1515 return tail; | |
1516 } | |
1517 return Qnil; | |
1518 } | |
1519 | |
1520 DEFUN ("memq", Fmemq, 2, 2, 0, /* | |
1521 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. | |
1522 The value is actually the tail of LIST whose car is ELT. | |
1523 */ | |
1524 (elt, list)) | |
1525 { | |
1526 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1527 { | |
1528 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1529 return tail; | |
1530 } | |
1531 return Qnil; | |
1532 } | |
1533 | |
1534 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /* | |
1535 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'. | |
1536 The value is actually the tail of LIST whose car is ELT. | |
1537 This function is provided only for byte-code compatibility with v19. | |
1538 Do not use it. | |
1539 */ | |
1540 (elt, list)) | |
1541 { | |
1542 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1543 { | |
1544 if (HACKEQ_UNSAFE (elt, list_elt)) | |
1545 return tail; | |
1546 } | |
1547 return Qnil; | |
1548 } | |
1549 | |
1550 Lisp_Object | |
1551 memq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1552 { | |
1553 LIST_LOOP_3 (list_elt, list, tail) | |
1554 { | |
1555 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1556 return tail; | |
1557 } | |
1558 return Qnil; | |
1559 } | |
1560 | |
1561 DEFUN ("assoc", Fassoc, 2, 2, 0, /* | |
444 | 1562 Return non-nil if KEY is `equal' to the car of an element of ALIST. |
1563 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1564 */ |
444 | 1565 (key, alist)) |
428 | 1566 { |
1567 /* This function can GC. */ | |
444 | 1568 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1569 { |
1570 if (internal_equal (key, elt_car, 0)) | |
1571 return elt; | |
1572 } | |
1573 return Qnil; | |
1574 } | |
1575 | |
1576 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /* | |
444 | 1577 Return non-nil if KEY is `old-equal' to the car of an element of ALIST. |
1578 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1579 */ |
444 | 1580 (key, alist)) |
428 | 1581 { |
1582 /* This function can GC. */ | |
444 | 1583 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1584 { |
1585 if (internal_old_equal (key, elt_car, 0)) | |
1586 return elt; | |
1587 } | |
1588 return Qnil; | |
1589 } | |
1590 | |
1591 Lisp_Object | |
444 | 1592 assoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1593 { |
1594 int speccount = specpdl_depth (); | |
1595 specbind (Qinhibit_quit, Qt); | |
771 | 1596 return unbind_to_1 (speccount, Fassoc (key, alist)); |
428 | 1597 } |
1598 | |
1599 DEFUN ("assq", Fassq, 2, 2, 0, /* | |
444 | 1600 Return non-nil if KEY is `eq' to the car of an element of ALIST. |
1601 The value is actually the element of ALIST whose car is KEY. | |
1602 Elements of ALIST that are not conses are ignored. | |
428 | 1603 */ |
444 | 1604 (key, alist)) |
428 | 1605 { |
444 | 1606 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1607 { |
1608 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1609 return elt; | |
1610 } | |
1611 return Qnil; | |
1612 } | |
1613 | |
1614 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /* | |
444 | 1615 Return non-nil if KEY is `old-eq' to the car of an element of ALIST. |
1616 The value is actually the element of ALIST whose car is KEY. | |
1617 Elements of ALIST that are not conses are ignored. | |
428 | 1618 This function is provided only for byte-code compatibility with v19. |
1619 Do not use it. | |
1620 */ | |
444 | 1621 (key, alist)) |
428 | 1622 { |
444 | 1623 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1624 { |
1625 if (HACKEQ_UNSAFE (key, elt_car)) | |
1626 return elt; | |
1627 } | |
1628 return Qnil; | |
1629 } | |
1630 | |
1631 /* Like Fassq but never report an error and do not allow quits. | |
1632 Use only on lists known never to be circular. */ | |
1633 | |
1634 Lisp_Object | |
444 | 1635 assq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1636 { |
1637 /* This cannot GC. */ | |
444 | 1638 LIST_LOOP_2 (elt, alist) |
428 | 1639 { |
1640 Lisp_Object elt_car = XCAR (elt); | |
1641 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1642 return elt; | |
1643 } | |
1644 return Qnil; | |
1645 } | |
1646 | |
1647 DEFUN ("rassoc", Frassoc, 2, 2, 0, /* | |
444 | 1648 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST. |
1649 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1650 */ |
444 | 1651 (value, alist)) |
428 | 1652 { |
444 | 1653 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1654 { |
444 | 1655 if (internal_equal (value, elt_cdr, 0)) |
428 | 1656 return elt; |
1657 } | |
1658 return Qnil; | |
1659 } | |
1660 | |
1661 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /* | |
444 | 1662 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST. |
1663 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1664 */ |
444 | 1665 (value, alist)) |
428 | 1666 { |
444 | 1667 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1668 { |
444 | 1669 if (internal_old_equal (value, elt_cdr, 0)) |
428 | 1670 return elt; |
1671 } | |
1672 return Qnil; | |
1673 } | |
1674 | |
1675 DEFUN ("rassq", Frassq, 2, 2, 0, /* | |
444 | 1676 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST. |
1677 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1678 */ |
444 | 1679 (value, alist)) |
428 | 1680 { |
444 | 1681 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1682 { |
444 | 1683 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1684 return elt; |
1685 } | |
1686 return Qnil; | |
1687 } | |
1688 | |
1689 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /* | |
444 | 1690 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST. |
1691 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1692 */ |
444 | 1693 (value, alist)) |
428 | 1694 { |
444 | 1695 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1696 { |
444 | 1697 if (HACKEQ_UNSAFE (value, elt_cdr)) |
428 | 1698 return elt; |
1699 } | |
1700 return Qnil; | |
1701 } | |
1702 | |
444 | 1703 /* Like Frassq, but caller must ensure that ALIST is properly |
428 | 1704 nil-terminated and ebola-free. */ |
1705 Lisp_Object | |
444 | 1706 rassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1707 { |
444 | 1708 LIST_LOOP_2 (elt, alist) |
428 | 1709 { |
1710 Lisp_Object elt_cdr = XCDR (elt); | |
444 | 1711 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1712 return elt; |
1713 } | |
1714 return Qnil; | |
1715 } | |
1716 | |
1717 | |
1718 DEFUN ("delete", Fdelete, 2, 2, 0, /* | |
1719 Delete by side effect any occurrences of ELT as a member of LIST. | |
1720 The modified LIST is returned. Comparison is done with `equal'. | |
1721 If the first member of LIST is ELT, there is no way to remove it by side | |
1722 effect; therefore, write `(setq foo (delete element foo))' to be sure | |
1723 of changing the value of `foo'. | |
1724 Also see: `remove'. | |
1725 */ | |
1726 (elt, list)) | |
1727 { | |
1728 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1729 (internal_equal (elt, list_elt, 0))); | |
1730 return list; | |
1731 } | |
1732 | |
1733 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /* | |
1734 Delete by side effect any occurrences of ELT as a member of LIST. | |
1735 The modified LIST is returned. Comparison is done with `old-equal'. | |
1736 If the first member of LIST is ELT, there is no way to remove it by side | |
1737 effect; therefore, write `(setq foo (old-delete element foo))' to be sure | |
1738 of changing the value of `foo'. | |
1739 */ | |
1740 (elt, list)) | |
1741 { | |
1742 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1743 (internal_old_equal (elt, list_elt, 0))); | |
1744 return list; | |
1745 } | |
1746 | |
1747 DEFUN ("delq", Fdelq, 2, 2, 0, /* | |
1748 Delete by side effect any occurrences of ELT as a member of LIST. | |
1749 The modified LIST is returned. Comparison is done with `eq'. | |
1750 If the first member of LIST is ELT, there is no way to remove it by side | |
1751 effect; therefore, write `(setq foo (delq element foo))' to be sure of | |
1752 changing the value of `foo'. | |
1753 */ | |
1754 (elt, list)) | |
1755 { | |
1756 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1757 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1758 return list; | |
1759 } | |
1760 | |
1761 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /* | |
1762 Delete by side effect any occurrences of ELT as a member of LIST. | |
1763 The modified LIST is returned. Comparison is done with `old-eq'. | |
1764 If the first member of LIST is ELT, there is no way to remove it by side | |
1765 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of | |
1766 changing the value of `foo'. | |
1767 */ | |
1768 (elt, list)) | |
1769 { | |
1770 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1771 (HACKEQ_UNSAFE (elt, list_elt))); | |
1772 return list; | |
1773 } | |
1774 | |
1775 /* Like Fdelq, but caller must ensure that LIST is properly | |
1776 nil-terminated and ebola-free. */ | |
1777 | |
1778 Lisp_Object | |
1779 delq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1780 { | |
1781 LIST_LOOP_DELETE_IF (list_elt, list, | |
1782 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1783 return list; | |
1784 } | |
1785 | |
1786 /* Be VERY careful with this. This is like delq_no_quit() but | |
1787 also calls free_cons() on the removed conses. You must be SURE | |
1788 that no pointers to the freed conses remain around (e.g. | |
1789 someone else is pointing to part of the list). This function | |
1790 is useful on internal lists that are used frequently and where | |
1791 the actual list doesn't escape beyond known code bounds. */ | |
1792 | |
1793 Lisp_Object | |
1794 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list) | |
1795 { | |
1796 REGISTER Lisp_Object tail = list; | |
1797 REGISTER Lisp_Object prev = Qnil; | |
1798 | |
1799 while (!NILP (tail)) | |
1800 { | |
1801 REGISTER Lisp_Object tem = XCAR (tail); | |
1802 if (EQ (elt, tem)) | |
1803 { | |
1804 Lisp_Object cons_to_free = tail; | |
1805 if (NILP (prev)) | |
1806 list = XCDR (tail); | |
1807 else | |
1808 XCDR (prev) = XCDR (tail); | |
1809 tail = XCDR (tail); | |
853 | 1810 free_cons (cons_to_free); |
428 | 1811 } |
1812 else | |
1813 { | |
1814 prev = tail; | |
1815 tail = XCDR (tail); | |
1816 } | |
1817 } | |
1818 return list; | |
1819 } | |
1820 | |
1821 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /* | |
444 | 1822 Delete by side effect any elements of ALIST whose car is `equal' to KEY. |
1823 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1824 that is `equal' to KEY, there is no way to remove it by side effect; |
1825 therefore, write `(setq foo (remassoc key foo))' to be sure of changing | |
1826 the value of `foo'. | |
1827 */ | |
444 | 1828 (key, alist)) |
428 | 1829 { |
444 | 1830 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1831 (CONSP (elt) && |
1832 internal_equal (key, XCAR (elt), 0))); | |
444 | 1833 return alist; |
428 | 1834 } |
1835 | |
1836 Lisp_Object | |
444 | 1837 remassoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1838 { |
1839 int speccount = specpdl_depth (); | |
1840 specbind (Qinhibit_quit, Qt); | |
771 | 1841 return unbind_to_1 (speccount, Fremassoc (key, alist)); |
428 | 1842 } |
1843 | |
1844 DEFUN ("remassq", Fremassq, 2, 2, 0, /* | |
444 | 1845 Delete by side effect any elements of ALIST whose car is `eq' to KEY. |
1846 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1847 that is `eq' to KEY, there is no way to remove it by side effect; |
1848 therefore, write `(setq foo (remassq key foo))' to be sure of changing | |
1849 the value of `foo'. | |
1850 */ | |
444 | 1851 (key, alist)) |
428 | 1852 { |
444 | 1853 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1854 (CONSP (elt) && |
1855 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1856 return alist; |
428 | 1857 } |
1858 | |
1859 /* no quit, no errors; be careful */ | |
1860 | |
1861 Lisp_Object | |
444 | 1862 remassq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1863 { |
444 | 1864 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1865 (CONSP (elt) && |
1866 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1867 return alist; |
428 | 1868 } |
1869 | |
1870 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /* | |
444 | 1871 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE. |
1872 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1873 that is `equal' to VALUE, there is no way to remove it by side effect; |
1874 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing | |
1875 the value of `foo'. | |
1876 */ | |
444 | 1877 (value, alist)) |
428 | 1878 { |
444 | 1879 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1880 (CONSP (elt) && |
1881 internal_equal (value, XCDR (elt), 0))); | |
444 | 1882 return alist; |
428 | 1883 } |
1884 | |
1885 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /* | |
444 | 1886 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE. |
1887 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1888 that is `eq' to VALUE, there is no way to remove it by side effect; |
1889 therefore, write `(setq foo (remrassq value foo))' to be sure of changing | |
1890 the value of `foo'. | |
1891 */ | |
444 | 1892 (value, alist)) |
428 | 1893 { |
444 | 1894 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1895 (CONSP (elt) && |
1896 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1897 return alist; |
428 | 1898 } |
1899 | |
1900 /* Like Fremrassq, fast and unsafe; be careful */ | |
1901 Lisp_Object | |
444 | 1902 remrassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1903 { |
444 | 1904 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1905 (CONSP (elt) && |
1906 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1907 return alist; |
428 | 1908 } |
1909 | |
1910 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /* | |
1911 Reverse LIST by destructively modifying cdr pointers. | |
1912 Return the beginning of the reversed list. | |
1913 Also see: `reverse'. | |
1914 */ | |
1915 (list)) | |
1916 { | |
1917 struct gcpro gcpro1, gcpro2; | |
1849 | 1918 Lisp_Object prev = Qnil; |
1919 Lisp_Object tail = list; | |
428 | 1920 |
1921 /* We gcpro our args; see `nconc' */ | |
1922 GCPRO2 (prev, tail); | |
1923 while (!NILP (tail)) | |
1924 { | |
1925 REGISTER Lisp_Object next; | |
1926 CONCHECK_CONS (tail); | |
1927 next = XCDR (tail); | |
1928 XCDR (tail) = prev; | |
1929 prev = tail; | |
1930 tail = next; | |
1931 } | |
1932 UNGCPRO; | |
1933 return prev; | |
1934 } | |
1935 | |
1936 DEFUN ("reverse", Freverse, 1, 1, 0, /* | |
1937 Reverse LIST, copying. Return the beginning of the reversed list. | |
1938 See also the function `nreverse', which is used more often. | |
1939 */ | |
1940 (list)) | |
1941 { | |
1942 Lisp_Object reversed_list = Qnil; | |
1943 EXTERNAL_LIST_LOOP_2 (elt, list) | |
1944 { | |
1945 reversed_list = Fcons (elt, reversed_list); | |
1946 } | |
1947 return reversed_list; | |
1948 } | |
1949 | |
1950 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
1951 Lisp_Object lisp_arg, | |
1952 int (*pred_fn) (Lisp_Object, Lisp_Object, | |
1953 Lisp_Object lisp_arg)); | |
1954 | |
872 | 1955 /* The sort function should return > 0 if OBJ1 < OBJ2, < 0 otherwise. |
1956 NOTE: This is backwards from the way qsort() works. */ | |
1957 | |
428 | 1958 Lisp_Object |
1959 list_sort (Lisp_Object list, | |
1960 Lisp_Object lisp_arg, | |
872 | 1961 int (*pred_fn) (Lisp_Object obj1, Lisp_Object obj2, |
428 | 1962 Lisp_Object lisp_arg)) |
1963 { | |
1964 struct gcpro gcpro1, gcpro2, gcpro3; | |
1965 Lisp_Object back, tem; | |
1966 Lisp_Object front = list; | |
1967 Lisp_Object len = Flength (list); | |
444 | 1968 |
1969 if (XINT (len) < 2) | |
428 | 1970 return list; |
1971 | |
444 | 1972 len = make_int (XINT (len) / 2 - 1); |
428 | 1973 tem = Fnthcdr (len, list); |
1974 back = Fcdr (tem); | |
1975 Fsetcdr (tem, Qnil); | |
1976 | |
1977 GCPRO3 (front, back, lisp_arg); | |
1978 front = list_sort (front, lisp_arg, pred_fn); | |
1979 back = list_sort (back, lisp_arg, pred_fn); | |
1980 UNGCPRO; | |
1981 return list_merge (front, back, lisp_arg, pred_fn); | |
1982 } | |
1983 | |
1984 | |
1985 static int | |
1986 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2, | |
1987 Lisp_Object pred) | |
1988 { | |
1989 Lisp_Object tmp; | |
1990 | |
1991 /* prevents the GC from happening in call2 */ | |
853 | 1992 /* Emacs' GC doesn't actually relocate pointers, so this probably |
1993 isn't strictly necessary */ | |
771 | 1994 int speccount = begin_gc_forbidden (); |
428 | 1995 tmp = call2 (pred, obj1, obj2); |
771 | 1996 unbind_to (speccount); |
428 | 1997 |
1998 if (NILP (tmp)) | |
1999 return -1; | |
2000 else | |
2001 return 1; | |
2002 } | |
2003 | |
2004 DEFUN ("sort", Fsort, 2, 2, 0, /* | |
2005 Sort LIST, stably, comparing elements using PREDICATE. | |
2006 Returns the sorted list. LIST is modified by side effects. | |
2007 PREDICATE is called with two elements of LIST, and should return T | |
2008 if the first element is "less" than the second. | |
2009 */ | |
444 | 2010 (list, predicate)) |
428 | 2011 { |
444 | 2012 return list_sort (list, predicate, merge_pred_function); |
428 | 2013 } |
2014 | |
2015 Lisp_Object | |
2016 merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
2017 Lisp_Object pred) | |
2018 { | |
2019 return list_merge (org_l1, org_l2, pred, merge_pred_function); | |
2020 } | |
2021 | |
2022 | |
2023 static Lisp_Object | |
2024 list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
2025 Lisp_Object lisp_arg, | |
2026 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg)) | |
2027 { | |
2028 Lisp_Object value; | |
2029 Lisp_Object tail; | |
2030 Lisp_Object tem; | |
2031 Lisp_Object l1, l2; | |
2032 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
2033 | |
2034 l1 = org_l1; | |
2035 l2 = org_l2; | |
2036 tail = Qnil; | |
2037 value = Qnil; | |
2038 | |
2039 /* It is sufficient to protect org_l1 and org_l2. | |
2040 When l1 and l2 are updated, we copy the new values | |
2041 back into the org_ vars. */ | |
2042 | |
2043 GCPRO4 (org_l1, org_l2, lisp_arg, value); | |
2044 | |
2045 while (1) | |
2046 { | |
2047 if (NILP (l1)) | |
2048 { | |
2049 UNGCPRO; | |
2050 if (NILP (tail)) | |
2051 return l2; | |
2052 Fsetcdr (tail, l2); | |
2053 return value; | |
2054 } | |
2055 if (NILP (l2)) | |
2056 { | |
2057 UNGCPRO; | |
2058 if (NILP (tail)) | |
2059 return l1; | |
2060 Fsetcdr (tail, l1); | |
2061 return value; | |
2062 } | |
2063 | |
2064 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0) | |
2065 { | |
2066 tem = l1; | |
2067 l1 = Fcdr (l1); | |
2068 org_l1 = l1; | |
2069 } | |
2070 else | |
2071 { | |
2072 tem = l2; | |
2073 l2 = Fcdr (l2); | |
2074 org_l2 = l2; | |
2075 } | |
2076 if (NILP (tail)) | |
2077 value = tem; | |
2078 else | |
2079 Fsetcdr (tail, tem); | |
2080 tail = tem; | |
2081 } | |
2082 } | |
2083 | |
2084 | |
2085 /************************************************************************/ | |
2086 /* property-list functions */ | |
2087 /************************************************************************/ | |
2088 | |
2089 /* For properties of text, we need to do order-insensitive comparison of | |
2090 plists. That is, we need to compare two plists such that they are the | |
2091 same if they have the same set of keys, and equivalent values. | |
2092 So (a 1 b 2) would be equal to (b 2 a 1). | |
2093 | |
2094 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc. | |
2095 LAXP means use `equal' for comparisons. | |
2096 */ | |
2097 int | |
2098 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present, | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2099 int laxp, int depth, int foldcase) |
428 | 2100 { |
438 | 2101 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */ |
428 | 2102 int la, lb, m, i, fill; |
2103 Lisp_Object *keys, *vals; | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
2104 Boolbyte *flags; |
428 | 2105 Lisp_Object rest; |
2106 | |
2107 if (NILP (a) && NILP (b)) | |
2108 return 0; | |
2109 | |
2110 Fcheck_valid_plist (a); | |
2111 Fcheck_valid_plist (b); | |
2112 | |
2113 la = XINT (Flength (a)); | |
2114 lb = XINT (Flength (b)); | |
2115 m = (la > lb ? la : lb); | |
2116 fill = 0; | |
2117 keys = alloca_array (Lisp_Object, m); | |
2118 vals = alloca_array (Lisp_Object, m); | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
2119 flags = alloca_array (Boolbyte, m); |
428 | 2120 |
2121 /* First extract the pairs from A. */ | |
2122 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2123 { | |
2124 Lisp_Object k = XCAR (rest); | |
2125 Lisp_Object v = XCAR (XCDR (rest)); | |
2126 /* Maybe be Ebolified. */ | |
2127 if (nil_means_not_present && NILP (v)) continue; | |
2128 keys [fill] = k; | |
2129 vals [fill] = v; | |
2130 flags[fill] = 0; | |
2131 fill++; | |
2132 } | |
2133 /* Now iterate over B, and stop if we find something that's not in A, | |
2134 or that doesn't match. As we match, mark them. */ | |
2135 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2136 { | |
2137 Lisp_Object k = XCAR (rest); | |
2138 Lisp_Object v = XCAR (XCDR (rest)); | |
2139 /* Maybe be Ebolified. */ | |
2140 if (nil_means_not_present && NILP (v)) continue; | |
2141 for (i = 0; i < fill; i++) | |
2142 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2143 if (!laxp ? EQ (k, keys [i]) : |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2144 internal_equal_0 (k, keys [i], depth, foldcase)) |
428 | 2145 { |
434 | 2146 if (eqp |
2147 /* We narrowly escaped being Ebolified here. */ | |
2148 ? !EQ_WITH_EBOLA_NOTICE (v, vals [i]) | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2149 : !internal_equal_0 (v, vals [i], depth, foldcase)) |
428 | 2150 /* a property in B has a different value than in A */ |
2151 goto MISMATCH; | |
2152 flags [i] = 1; | |
2153 break; | |
2154 } | |
2155 } | |
2156 if (i == fill) | |
2157 /* there are some properties in B that are not in A */ | |
2158 goto MISMATCH; | |
2159 } | |
2160 /* Now check to see that all the properties in A were also in B */ | |
2161 for (i = 0; i < fill; i++) | |
2162 if (flags [i] == 0) | |
2163 goto MISMATCH; | |
2164 | |
2165 /* Ok. */ | |
2166 return 0; | |
2167 | |
2168 MISMATCH: | |
2169 return 1; | |
2170 } | |
2171 | |
2172 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /* | |
2173 Return non-nil if property lists A and B are `eq'. | |
2174 A property list is an alternating list of keywords and values. | |
2175 This function does order-insensitive comparisons of the property lists: | |
2176 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2177 Comparison between values is done using `eq'. See also `plists-equal'. | |
2178 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2179 a nil value is ignored. This feature is a virus that has infected | |
2180 old Lisp implementations, but should not be used except for backward | |
2181 compatibility. | |
2182 */ | |
2183 (a, b, nil_means_not_present)) | |
2184 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2185 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1, 0) |
428 | 2186 ? Qnil : Qt); |
2187 } | |
2188 | |
2189 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /* | |
2190 Return non-nil if property lists A and B are `equal'. | |
2191 A property list is an alternating list of keywords and values. This | |
2192 function does order-insensitive comparisons of the property lists: For | |
2193 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2194 Comparison between values is done using `equal'. See also `plists-eq'. | |
2195 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2196 a nil value is ignored. This feature is a virus that has infected | |
2197 old Lisp implementations, but should not be used except for backward | |
2198 compatibility. | |
2199 */ | |
2200 (a, b, nil_means_not_present)) | |
2201 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2202 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1, 0) |
428 | 2203 ? Qnil : Qt); |
2204 } | |
2205 | |
2206 | |
2207 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /* | |
2208 Return non-nil if lax property lists A and B are `eq'. | |
2209 A property list is an alternating list of keywords and values. | |
2210 This function does order-insensitive comparisons of the property lists: | |
2211 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2212 Comparison between values is done using `eq'. See also `plists-equal'. | |
2213 A lax property list is like a regular one except that comparisons between | |
2214 keywords is done using `equal' instead of `eq'. | |
2215 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2216 a nil value is ignored. This feature is a virus that has infected | |
2217 old Lisp implementations, but should not be used except for backward | |
2218 compatibility. | |
2219 */ | |
2220 (a, b, nil_means_not_present)) | |
2221 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2222 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1, 0) |
428 | 2223 ? Qnil : Qt); |
2224 } | |
2225 | |
2226 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /* | |
2227 Return non-nil if lax property lists A and B are `equal'. | |
2228 A property list is an alternating list of keywords and values. This | |
2229 function does order-insensitive comparisons of the property lists: For | |
2230 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2231 Comparison between values is done using `equal'. See also `plists-eq'. | |
2232 A lax property list is like a regular one except that comparisons between | |
2233 keywords is done using `equal' instead of `eq'. | |
2234 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2235 a nil value is ignored. This feature is a virus that has infected | |
2236 old Lisp implementations, but should not be used except for backward | |
2237 compatibility. | |
2238 */ | |
2239 (a, b, nil_means_not_present)) | |
2240 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2241 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1, 0) |
428 | 2242 ? Qnil : Qt); |
2243 } | |
2244 | |
2245 /* Return the value associated with key PROPERTY in property list PLIST. | |
2246 Return nil if key not found. This function is used for internal | |
2247 property lists that cannot be directly manipulated by the user. | |
2248 */ | |
2249 | |
2250 Lisp_Object | |
2251 internal_plist_get (Lisp_Object plist, Lisp_Object property) | |
2252 { | |
2253 Lisp_Object tail; | |
2254 | |
2255 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2256 { | |
2257 if (EQ (XCAR (tail), property)) | |
2258 return XCAR (XCDR (tail)); | |
2259 } | |
2260 | |
2261 return Qunbound; | |
2262 } | |
2263 | |
2264 /* Set PLIST's value for PROPERTY to VALUE. Analogous to | |
2265 internal_plist_get(). */ | |
2266 | |
2267 void | |
2268 internal_plist_put (Lisp_Object *plist, Lisp_Object property, | |
2269 Lisp_Object value) | |
2270 { | |
2271 Lisp_Object tail; | |
2272 | |
2273 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2274 { | |
2275 if (EQ (XCAR (tail), property)) | |
2276 { | |
2277 XCAR (XCDR (tail)) = value; | |
2278 return; | |
2279 } | |
2280 } | |
2281 | |
2282 *plist = Fcons (property, Fcons (value, *plist)); | |
2283 } | |
2284 | |
2285 int | |
2286 internal_remprop (Lisp_Object *plist, Lisp_Object property) | |
2287 { | |
2288 Lisp_Object tail, prev; | |
2289 | |
2290 for (tail = *plist, prev = Qnil; | |
2291 !NILP (tail); | |
2292 tail = XCDR (XCDR (tail))) | |
2293 { | |
2294 if (EQ (XCAR (tail), property)) | |
2295 { | |
2296 if (NILP (prev)) | |
2297 *plist = XCDR (XCDR (tail)); | |
2298 else | |
2299 XCDR (XCDR (prev)) = XCDR (XCDR (tail)); | |
2300 return 1; | |
2301 } | |
2302 else | |
2303 prev = tail; | |
2304 } | |
2305 | |
2306 return 0; | |
2307 } | |
2308 | |
2309 /* Called on a malformed property list. BADPLACE should be some | |
2310 place where truncating will form a good list -- i.e. we shouldn't | |
2311 result in a list with an odd length. */ | |
2312 | |
2313 static Lisp_Object | |
578 | 2314 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2315 { |
2316 if (ERRB_EQ (errb, ERROR_ME)) | |
2317 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace)); | |
2318 else | |
2319 { | |
2320 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2321 { | |
2322 warn_when_safe_lispobj | |
2323 (Qlist, Qwarning, | |
771 | 2324 list2 (build_msg_string |
428 | 2325 ("Malformed property list -- list has been truncated"), |
2326 *plist)); | |
793 | 2327 /* #### WARNING: This is more dangerous than it seems; perhaps |
2328 not a good idea. It also violates the principle of least | |
2329 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2330 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2331 *badplace = Qnil; |
2332 } | |
2333 return Qunbound; | |
2334 } | |
2335 } | |
2336 | |
2337 /* Called on a circular property list. BADPLACE should be some place | |
2338 where truncating will result in an even-length list, as above. | |
2339 If doesn't particularly matter where we truncate -- anywhere we | |
2340 truncate along the entire list will break the circularity, because | |
2341 it will create a terminus and the list currently doesn't have one. | |
2342 */ | |
2343 | |
2344 static Lisp_Object | |
578 | 2345 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2346 { |
2347 if (ERRB_EQ (errb, ERROR_ME)) | |
2348 return Fsignal (Qcircular_property_list, list1 (*plist)); | |
2349 else | |
2350 { | |
2351 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2352 { | |
2353 warn_when_safe_lispobj | |
2354 (Qlist, Qwarning, | |
771 | 2355 list2 (build_msg_string |
428 | 2356 ("Circular property list -- list has been truncated"), |
2357 *plist)); | |
793 | 2358 /* #### WARNING: This is more dangerous than it seems; perhaps |
2359 not a good idea. It also violates the principle of least | |
2360 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2361 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2362 *badplace = Qnil; |
2363 } | |
2364 return Qunbound; | |
2365 } | |
2366 } | |
2367 | |
2368 /* Advance the tortoise pointer by two (one iteration of a property-list | |
2369 loop) and the hare pointer by four and verify that no malformations | |
2370 or circularities exist. If so, return zero and store a value into | |
2371 RETVAL that should be returned by the calling function. Otherwise, | |
2372 return 1. See external_plist_get(). | |
2373 */ | |
2374 | |
2375 static int | |
2376 advance_plist_pointers (Lisp_Object *plist, | |
2377 Lisp_Object **tortoise, Lisp_Object **hare, | |
578 | 2378 Error_Behavior errb, Lisp_Object *retval) |
428 | 2379 { |
2380 int i; | |
2381 Lisp_Object *tortsave = *tortoise; | |
2382 | |
2383 /* Note that our "fixing" may be more brutal than necessary, | |
2384 but it's the user's own problem, not ours, if they went in and | |
2385 manually fucked up a plist. */ | |
2386 | |
2387 for (i = 0; i < 2; i++) | |
2388 { | |
2389 /* This is a standard iteration of a defensive-loop-checking | |
2390 loop. We just do it twice because we want to advance past | |
2391 both the property and its value. | |
2392 | |
2393 If the pointer indirection is confusing you, remember that | |
2394 one level of indirection on the hare and tortoise pointers | |
2395 is only due to pass-by-reference for this function. The other | |
2396 level is so that the plist can be fixed in place. */ | |
2397 | |
2398 /* When we reach the end of a well-formed plist, **HARE is | |
2399 nil. In that case, we don't do anything at all except | |
2400 advance TORTOISE by one. Otherwise, we advance HARE | |
2401 by two (making sure it's OK to do so), then advance | |
2402 TORTOISE by one (it will always be OK to do so because | |
2403 the HARE is always ahead of the TORTOISE and will have | |
2404 already verified the path), then make sure TORTOISE and | |
2405 HARE don't contain the same non-nil object -- if the | |
2406 TORTOISE and the HARE ever meet, then obviously we're | |
2407 in a circularity, and if we're in a circularity, then | |
2408 the TORTOISE and the HARE can't cross paths without | |
2409 meeting, since the HARE only gains one step over the | |
2410 TORTOISE per iteration. */ | |
2411 | |
2412 if (!NILP (**hare)) | |
2413 { | |
2414 Lisp_Object *haresave = *hare; | |
2415 if (!CONSP (**hare)) | |
2416 { | |
2417 *retval = bad_bad_bunny (plist, haresave, errb); | |
2418 return 0; | |
2419 } | |
2420 *hare = &XCDR (**hare); | |
2421 /* In a non-plist, we'd check here for a nil value for | |
2422 **HARE, which is OK (it just means the list has an | |
2423 odd number of elements). In a plist, it's not OK | |
2424 for the list to have an odd number of elements. */ | |
2425 if (!CONSP (**hare)) | |
2426 { | |
2427 *retval = bad_bad_bunny (plist, haresave, errb); | |
2428 return 0; | |
2429 } | |
2430 *hare = &XCDR (**hare); | |
2431 } | |
2432 | |
2433 *tortoise = &XCDR (**tortoise); | |
2434 if (!NILP (**hare) && EQ (**tortoise, **hare)) | |
2435 { | |
2436 *retval = bad_bad_turtle (plist, tortsave, errb); | |
2437 return 0; | |
2438 } | |
2439 } | |
2440 | |
2441 return 1; | |
2442 } | |
2443 | |
2444 /* Return the value of PROPERTY from PLIST, or Qunbound if | |
2445 property is not on the list. | |
2446 | |
2447 PLIST is a Lisp-accessible property list, meaning that it | |
2448 has to be checked for malformations and circularities. | |
2449 | |
2450 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the | |
2451 function will never signal an error; and if ERRB is ERROR_ME_WARN, | |
2452 on finding a malformation or a circularity, it issues a warning and | |
2453 attempts to silently fix the problem. | |
2454 | |
2455 A pointer to PLIST is passed in so that PLIST can be successfully | |
2456 "fixed" even if the error is at the beginning of the plist. */ | |
2457 | |
2458 Lisp_Object | |
2459 external_plist_get (Lisp_Object *plist, Lisp_Object property, | |
578 | 2460 int laxp, Error_Behavior errb) |
428 | 2461 { |
2462 Lisp_Object *tortoise = plist; | |
2463 Lisp_Object *hare = plist; | |
2464 | |
2465 while (!NILP (*tortoise)) | |
2466 { | |
2467 Lisp_Object *tortsave = tortoise; | |
2468 Lisp_Object retval; | |
2469 | |
2470 /* We do the standard tortoise/hare march. We isolate the | |
2471 grungy stuff to do this in advance_plist_pointers(), though. | |
2472 To us, all this function does is advance the tortoise | |
2473 pointer by two and the hare pointer by four and make sure | |
2474 everything's OK. We first advance the pointers and then | |
2475 check if a property matched; this ensures that our | |
2476 check for a matching property is safe. */ | |
2477 | |
2478 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2479 return retval; | |
2480 | |
2481 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2482 : internal_equal (XCAR (*tortsave), property, 0)) | |
2483 return XCAR (XCDR (*tortsave)); | |
2484 } | |
2485 | |
2486 return Qunbound; | |
2487 } | |
2488 | |
2489 /* Set PLIST's value for PROPERTY to VALUE, given a possibly | |
2490 malformed or circular plist. Analogous to external_plist_get(). */ | |
2491 | |
2492 void | |
2493 external_plist_put (Lisp_Object *plist, Lisp_Object property, | |
578 | 2494 Lisp_Object value, int laxp, Error_Behavior errb) |
428 | 2495 { |
2496 Lisp_Object *tortoise = plist; | |
2497 Lisp_Object *hare = plist; | |
2498 | |
2499 while (!NILP (*tortoise)) | |
2500 { | |
2501 Lisp_Object *tortsave = tortoise; | |
2502 Lisp_Object retval; | |
2503 | |
2504 /* See above */ | |
2505 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2506 return; | |
2507 | |
2508 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2509 : internal_equal (XCAR (*tortsave), property, 0)) | |
2510 { | |
2511 XCAR (XCDR (*tortsave)) = value; | |
2512 return; | |
2513 } | |
2514 } | |
2515 | |
2516 *plist = Fcons (property, Fcons (value, *plist)); | |
2517 } | |
2518 | |
2519 int | |
2520 external_remprop (Lisp_Object *plist, Lisp_Object property, | |
578 | 2521 int laxp, Error_Behavior errb) |
428 | 2522 { |
2523 Lisp_Object *tortoise = plist; | |
2524 Lisp_Object *hare = plist; | |
2525 | |
2526 while (!NILP (*tortoise)) | |
2527 { | |
2528 Lisp_Object *tortsave = tortoise; | |
2529 Lisp_Object retval; | |
2530 | |
2531 /* See above */ | |
2532 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2533 return 0; | |
2534 | |
2535 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2536 : internal_equal (XCAR (*tortsave), property, 0)) | |
2537 { | |
2538 /* Now you see why it's so convenient to have that level | |
2539 of indirection. */ | |
2540 *tortsave = XCDR (XCDR (*tortsave)); | |
2541 return 1; | |
2542 } | |
2543 } | |
2544 | |
2545 return 0; | |
2546 } | |
2547 | |
2548 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /* | |
2549 Extract a value from a property list. | |
2550 PLIST is a property list, which is a list of the form | |
444 | 2551 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...). |
2552 PROPERTY is usually a symbol. | |
2553 This function returns the value corresponding to the PROPERTY, | |
2554 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 2555 */ |
444 | 2556 (plist, property, default_)) |
428 | 2557 { |
444 | 2558 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME); |
2559 return UNBOUNDP (value) ? default_ : value; | |
428 | 2560 } |
2561 | |
2562 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /* | |
444 | 2563 Change value in PLIST of PROPERTY to VALUE. |
2564 PLIST is a property list, which is a list of the form | |
2565 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
2566 PROPERTY is usually a symbol and VALUE is any object. | |
2567 If PROPERTY is already a property on the list, its value is set to VALUE, | |
2568 otherwise the new PROPERTY VALUE pair is added. | |
2569 The new plist is returned; use `(setq x (plist-put x property value))' | |
2570 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 2571 */ |
444 | 2572 (plist, property, value)) |
428 | 2573 { |
444 | 2574 external_plist_put (&plist, property, value, 0, ERROR_ME); |
428 | 2575 return plist; |
2576 } | |
2577 | |
2578 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /* | |
444 | 2579 Remove from PLIST the property PROPERTY and its value. |
2580 PLIST is a property list, which is a list of the form | |
2581 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
2582 PROPERTY is usually a symbol. | |
2583 The new plist is returned; use `(setq x (plist-remprop x property))' | |
2584 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 2585 */ |
444 | 2586 (plist, property)) |
428 | 2587 { |
444 | 2588 external_remprop (&plist, property, 0, ERROR_ME); |
428 | 2589 return plist; |
2590 } | |
2591 | |
2592 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /* | |
444 | 2593 Return t if PROPERTY has a value specified in PLIST. |
428 | 2594 */ |
444 | 2595 (plist, property)) |
428 | 2596 { |
444 | 2597 Lisp_Object value = Fplist_get (plist, property, Qunbound); |
2598 return UNBOUNDP (value) ? Qnil : Qt; | |
428 | 2599 } |
2600 | |
2601 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /* | |
2602 Given a plist, signal an error if there is anything wrong with it. | |
2603 This means that it's a malformed or circular plist. | |
2604 */ | |
2605 (plist)) | |
2606 { | |
2607 Lisp_Object *tortoise; | |
2608 Lisp_Object *hare; | |
2609 | |
2610 start_over: | |
2611 tortoise = &plist; | |
2612 hare = &plist; | |
2613 while (!NILP (*tortoise)) | |
2614 { | |
2615 Lisp_Object retval; | |
2616 | |
2617 /* See above */ | |
2618 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME, | |
2619 &retval)) | |
2620 goto start_over; | |
2621 } | |
2622 | |
2623 return Qnil; | |
2624 } | |
2625 | |
2626 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /* | |
2627 Given a plist, return non-nil if its format is correct. | |
2628 If it returns nil, `check-valid-plist' will signal an error when given | |
442 | 2629 the plist; that means it's a malformed or circular plist. |
428 | 2630 */ |
2631 (plist)) | |
2632 { | |
2633 Lisp_Object *tortoise; | |
2634 Lisp_Object *hare; | |
2635 | |
2636 tortoise = &plist; | |
2637 hare = &plist; | |
2638 while (!NILP (*tortoise)) | |
2639 { | |
2640 Lisp_Object retval; | |
2641 | |
2642 /* See above */ | |
2643 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT, | |
2644 &retval)) | |
2645 return Qnil; | |
2646 } | |
2647 | |
2648 return Qt; | |
2649 } | |
2650 | |
2651 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /* | |
2652 Destructively remove any duplicate entries from a plist. | |
2653 In such cases, the first entry applies. | |
2654 | |
2655 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2656 a nil value is removed. This feature is a virus that has infected | |
2657 old Lisp implementations, but should not be used except for backward | |
2658 compatibility. | |
2659 | |
2660 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
2661 return value may not be EQ to the passed-in value, so make sure to | |
2662 `setq' the value back into where it came from. | |
2663 */ | |
2664 (plist, nil_means_not_present)) | |
2665 { | |
2666 Lisp_Object head = plist; | |
2667 | |
2668 Fcheck_valid_plist (plist); | |
2669 | |
2670 while (!NILP (plist)) | |
2671 { | |
2672 Lisp_Object prop = Fcar (plist); | |
2673 Lisp_Object next = Fcdr (plist); | |
2674 | |
2675 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
2676 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
2677 { | |
2678 if (EQ (head, plist)) | |
2679 head = Fcdr (next); | |
2680 plist = Fcdr (next); | |
2681 continue; | |
2682 } | |
2683 /* external_remprop returns 1 if it removed any property. | |
2684 We have to loop till it didn't remove anything, in case | |
2685 the property occurs many times. */ | |
2686 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME)) | |
2687 DO_NOTHING; | |
2688 plist = Fcdr (next); | |
2689 } | |
2690 | |
2691 return head; | |
2692 } | |
2693 | |
2694 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /* | |
2695 Extract a value from a lax property list. | |
444 | 2696 LAX-PLIST is a lax property list, which is a list of the form |
2697 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2698 properties is done using `equal' instead of `eq'. | |
2699 PROPERTY is usually a symbol. | |
2700 This function returns the value corresponding to PROPERTY, | |
2701 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 2702 */ |
444 | 2703 (lax_plist, property, default_)) |
428 | 2704 { |
444 | 2705 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME); |
2706 return UNBOUNDP (value) ? default_ : value; | |
428 | 2707 } |
2708 | |
2709 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /* | |
444 | 2710 Change value in LAX-PLIST of PROPERTY to VALUE. |
2711 LAX-PLIST is a lax property list, which is a list of the form | |
2712 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2713 properties is done using `equal' instead of `eq'. | |
2714 PROPERTY is usually a symbol and VALUE is any object. | |
2715 If PROPERTY is already a property on the list, its value is set to | |
2716 VALUE, otherwise the new PROPERTY VALUE pair is added. | |
2717 The new plist is returned; use `(setq x (lax-plist-put x property value))' | |
2718 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 2719 */ |
444 | 2720 (lax_plist, property, value)) |
428 | 2721 { |
444 | 2722 external_plist_put (&lax_plist, property, value, 1, ERROR_ME); |
428 | 2723 return lax_plist; |
2724 } | |
2725 | |
2726 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /* | |
444 | 2727 Remove from LAX-PLIST the property PROPERTY and its value. |
2728 LAX-PLIST is a lax property list, which is a list of the form | |
2729 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2730 properties is done using `equal' instead of `eq'. | |
2731 PROPERTY is usually a symbol. | |
2732 The new plist is returned; use `(setq x (lax-plist-remprop x property))' | |
2733 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 2734 */ |
444 | 2735 (lax_plist, property)) |
428 | 2736 { |
444 | 2737 external_remprop (&lax_plist, property, 1, ERROR_ME); |
428 | 2738 return lax_plist; |
2739 } | |
2740 | |
2741 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /* | |
444 | 2742 Return t if PROPERTY has a value specified in LAX-PLIST. |
2743 LAX-PLIST is a lax property list, which is a list of the form | |
2744 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2745 properties is done using `equal' instead of `eq'. | |
428 | 2746 */ |
444 | 2747 (lax_plist, property)) |
428 | 2748 { |
444 | 2749 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt; |
428 | 2750 } |
2751 | |
2752 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /* | |
2753 Destructively remove any duplicate entries from a lax plist. | |
2754 In such cases, the first entry applies. | |
2755 | |
2756 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2757 a nil value is removed. This feature is a virus that has infected | |
2758 old Lisp implementations, but should not be used except for backward | |
2759 compatibility. | |
2760 | |
2761 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
2762 return value may not be EQ to the passed-in value, so make sure to | |
2763 `setq' the value back into where it came from. | |
2764 */ | |
2765 (lax_plist, nil_means_not_present)) | |
2766 { | |
2767 Lisp_Object head = lax_plist; | |
2768 | |
2769 Fcheck_valid_plist (lax_plist); | |
2770 | |
2771 while (!NILP (lax_plist)) | |
2772 { | |
2773 Lisp_Object prop = Fcar (lax_plist); | |
2774 Lisp_Object next = Fcdr (lax_plist); | |
2775 | |
2776 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
2777 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
2778 { | |
2779 if (EQ (head, lax_plist)) | |
2780 head = Fcdr (next); | |
2781 lax_plist = Fcdr (next); | |
2782 continue; | |
2783 } | |
2784 /* external_remprop returns 1 if it removed any property. | |
2785 We have to loop till it didn't remove anything, in case | |
2786 the property occurs many times. */ | |
2787 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME)) | |
2788 DO_NOTHING; | |
2789 lax_plist = Fcdr (next); | |
2790 } | |
2791 | |
2792 return head; | |
2793 } | |
2794 | |
2795 /* In C because the frame props stuff uses it */ | |
2796 | |
2797 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /* | |
2798 Convert association list ALIST into the equivalent property-list form. | |
2799 The plist is returned. This converts from | |
2800 | |
2801 \((a . 1) (b . 2) (c . 3)) | |
2802 | |
2803 into | |
2804 | |
2805 \(a 1 b 2 c 3) | |
2806 | |
2807 The original alist is destroyed in the process of constructing the plist. | |
2808 See also `alist-to-plist'. | |
2809 */ | |
2810 (alist)) | |
2811 { | |
2812 Lisp_Object head = alist; | |
2813 while (!NILP (alist)) | |
2814 { | |
2815 /* remember the alist element. */ | |
2816 Lisp_Object el = Fcar (alist); | |
2817 | |
2818 Fsetcar (alist, Fcar (el)); | |
2819 Fsetcar (el, Fcdr (el)); | |
2820 Fsetcdr (el, Fcdr (alist)); | |
2821 Fsetcdr (alist, el); | |
2822 alist = Fcdr (Fcdr (alist)); | |
2823 } | |
2824 | |
2825 return head; | |
2826 } | |
2827 | |
2828 DEFUN ("get", Fget, 2, 3, 0, /* | |
442 | 2829 Return the value of OBJECT's PROPERTY property. |
2830 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'. | |
428 | 2831 If there is no such property, return optional third arg DEFAULT |
442 | 2832 \(which defaults to `nil'). OBJECT can be a symbol, string, extent, |
2833 face, or glyph. See also `put', `remprop', and `object-plist'. | |
428 | 2834 */ |
442 | 2835 (object, property, default_)) |
428 | 2836 { |
2837 /* Various places in emacs call Fget() and expect it not to quit, | |
2838 so don't quit. */ | |
442 | 2839 Lisp_Object val; |
2840 | |
2841 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop) | |
2842 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property); | |
428 | 2843 else |
563 | 2844 invalid_operation ("Object type has no properties", object); |
442 | 2845 |
2846 return UNBOUNDP (val) ? default_ : val; | |
428 | 2847 } |
2848 | |
2849 DEFUN ("put", Fput, 3, 3, 0, /* | |
442 | 2850 Set OBJECT's PROPERTY to VALUE. |
2851 It can be subsequently retrieved with `(get OBJECT PROPERTY)'. | |
2852 OBJECT can be a symbol, face, extent, or string. | |
428 | 2853 For a string, no properties currently have predefined meanings. |
2854 For the predefined properties for extents, see `set-extent-property'. | |
2855 For the predefined properties for faces, see `set-face-property'. | |
2856 See also `get', `remprop', and `object-plist'. | |
2857 */ | |
442 | 2858 (object, property, value)) |
428 | 2859 { |
1920 | 2860 /* This function cannot GC */ |
428 | 2861 CHECK_LISP_WRITEABLE (object); |
2862 | |
442 | 2863 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop) |
428 | 2864 { |
442 | 2865 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop |
2866 (object, property, value)) | |
563 | 2867 invalid_change ("Can't set property on object", property); |
428 | 2868 } |
2869 else | |
563 | 2870 invalid_change ("Object type has no settable properties", object); |
428 | 2871 |
2872 return value; | |
2873 } | |
2874 | |
2875 DEFUN ("remprop", Fremprop, 2, 2, 0, /* | |
442 | 2876 Remove, from OBJECT's property list, PROPERTY and its corresponding value. |
2877 OBJECT can be a symbol, string, extent, face, or glyph. Return non-nil | |
2878 if the property list was actually modified (i.e. if PROPERTY was present | |
2879 in the property list). See also `get', `put', and `object-plist'. | |
428 | 2880 */ |
442 | 2881 (object, property)) |
428 | 2882 { |
442 | 2883 int ret = 0; |
2884 | |
428 | 2885 CHECK_LISP_WRITEABLE (object); |
2886 | |
442 | 2887 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop) |
428 | 2888 { |
442 | 2889 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property); |
2890 if (ret == -1) | |
563 | 2891 invalid_change ("Can't remove property from object", property); |
428 | 2892 } |
2893 else | |
563 | 2894 invalid_change ("Object type has no removable properties", object); |
442 | 2895 |
2896 return ret ? Qt : Qnil; | |
428 | 2897 } |
2898 | |
2899 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /* | |
442 | 2900 Return a property list of OBJECT's properties. |
2901 For a symbol, this is equivalent to `symbol-plist'. | |
2902 OBJECT can be a symbol, string, extent, face, or glyph. | |
2903 Do not modify the returned property list directly; | |
2904 this may or may not have the desired effects. Use `put' instead. | |
428 | 2905 */ |
2906 (object)) | |
2907 { | |
442 | 2908 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist) |
2909 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object); | |
428 | 2910 else |
563 | 2911 invalid_operation ("Object type has no properties", object); |
428 | 2912 |
2913 return Qnil; | |
2914 } | |
2915 | |
2916 | |
853 | 2917 static Lisp_Object |
2918 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2, | |
2919 Lisp_Object depth) | |
2920 { | |
2921 return make_int (internal_equal (obj1, obj2, XINT (depth))); | |
2922 } | |
2923 | |
2924 int | |
2925 internal_equal_trapping_problems (Lisp_Object warning_class, | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
2926 const Ascbyte *warning_string, |
853 | 2927 int flags, |
2928 struct call_trapping_problems_result *p, | |
2929 int retval, | |
2930 Lisp_Object obj1, Lisp_Object obj2, | |
2931 int depth) | |
2932 { | |
2933 Lisp_Object glorp = | |
2934 va_call_trapping_problems (warning_class, warning_string, | |
2935 flags, p, | |
2936 (lisp_fn_t) tweaked_internal_equal, | |
2937 3, obj1, obj2, make_int (depth)); | |
2938 if (UNBOUNDP (glorp)) | |
2939 return retval; | |
2940 else | |
2941 return XINT (glorp); | |
2942 } | |
2943 | |
428 | 2944 int |
2945 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2946 { | |
2947 if (depth > 200) | |
563 | 2948 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 2949 QUIT; |
2950 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
2951 return 1; | |
2952 /* Note that (equal 20 20.0) should be nil */ | |
2953 if (XTYPE (obj1) != XTYPE (obj2)) | |
2954 return 0; | |
2955 if (LRECORDP (obj1)) | |
2956 { | |
442 | 2957 const struct lrecord_implementation |
428 | 2958 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), |
2959 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
2960 | |
2961 return (imp1 == imp2) && | |
2962 /* EQ-ness of the objects was noticed above */ | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2963 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 0)); |
428 | 2964 } |
2965 | |
2966 return 0; | |
2967 } | |
2968 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2969 enum array_type |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2970 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2971 ARRAY_NONE = 0, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2972 ARRAY_STRING, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2973 ARRAY_VECTOR, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2974 ARRAY_BIT_VECTOR |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2975 }; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2976 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2977 static enum array_type |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2978 array_type (Lisp_Object obj) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2979 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2980 if (STRINGP (obj)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2981 return ARRAY_STRING; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2982 if (VECTORP (obj)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2983 return ARRAY_VECTOR; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2984 if (BIT_VECTORP (obj)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2985 return ARRAY_BIT_VECTOR; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2986 return ARRAY_NONE; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2987 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2988 |
801 | 2989 int |
2990 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2991 { | |
2992 if (depth > 200) | |
2993 stack_overflow ("Stack overflow in equalp", Qunbound); | |
2994 QUIT; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2995 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2996 /* 1. Objects that are `eq' are equal. This will catch the common case |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2997 of two equal fixnums or the same object seen twice. */ |
801 | 2998 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) |
2999 return 1; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3000 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3001 /* 2. If both numbers, compare with `='. */ |
1983 | 3002 if (NUMBERP (obj1) && NUMBERP (obj2)) |
3003 { | |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
3004 return (0 == bytecode_arithcompare (obj1, obj2)); |
1983 | 3005 } |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3006 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3007 /* 3. If characters, compare case-insensitively. */ |
801 | 3008 if (CHARP (obj1) && CHARP (obj2)) |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
3009 return CANONCASE (0, XCHAR (obj1)) == CANONCASE (0, XCHAR (obj2)); |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3010 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3011 /* 4. If arrays of different types, compare their lengths, and |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3012 then compare element-by-element. */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3013 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3014 enum array_type artype1, artype2; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3015 artype1 = array_type (obj1); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3016 artype2 = array_type (obj2); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3017 if (artype1 != artype2 && artype1 && artype2) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3018 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3019 EMACS_INT i; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3020 EMACS_INT l1 = XINT (Flength (obj1)); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3021 EMACS_INT l2 = XINT (Flength (obj2)); |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
3022 /* Both arrays, but of different lengths */ |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3023 if (l1 != l2) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3024 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3025 for (i = 0; i < l1; i++) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3026 if (!internal_equalp (Faref (obj1, make_int (i)), |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3027 Faref (obj2, make_int (i)), depth + 1)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3028 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3029 return 1; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3030 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3031 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3032 /* 5. Else, they must be the same type. If so, call the equal() method, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3033 telling it to fold case. For objects that care about case-folding |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3034 their contents, the equal() method will call internal_equal_0(). */ |
801 | 3035 if (XTYPE (obj1) != XTYPE (obj2)) |
3036 return 0; | |
3037 if (LRECORDP (obj1)) | |
3038 { | |
3039 const struct lrecord_implementation | |
3040 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), | |
3041 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3042 | |
3043 return (imp1 == imp2) && | |
3044 /* EQ-ness of the objects was noticed above */ | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3045 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 1)); |
801 | 3046 } |
3047 | |
3048 return 0; | |
3049 } | |
3050 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3051 int |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3052 internal_equal_0 (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3053 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3054 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3055 return internal_equalp (obj1, obj2, depth); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3056 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3057 return internal_equal (obj1, obj2, depth); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3058 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3059 |
428 | 3060 /* Note that we may be calling sub-objects that will use |
3061 internal_equal() (instead of internal_old_equal()). Oh well. | |
3062 We will get an Ebola note if there's any possibility of confusion, | |
3063 but that seems unlikely. */ | |
3064 | |
3065 static int | |
3066 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3067 { | |
3068 if (depth > 200) | |
563 | 3069 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3070 QUIT; |
3071 if (HACKEQ_UNSAFE (obj1, obj2)) | |
3072 return 1; | |
3073 /* Note that (equal 20 20.0) should be nil */ | |
3074 if (XTYPE (obj1) != XTYPE (obj2)) | |
3075 return 0; | |
3076 | |
3077 return internal_equal (obj1, obj2, depth); | |
3078 } | |
3079 | |
3080 DEFUN ("equal", Fequal, 2, 2, 0, /* | |
3081 Return t if two Lisp objects have similar structure and contents. | |
3082 They must have the same data type. | |
3083 Conses are compared by comparing the cars and the cdrs. | |
3084 Vectors and strings are compared element by element. | |
3085 Numbers are compared by value. Symbols must match exactly. | |
3086 */ | |
444 | 3087 (object1, object2)) |
428 | 3088 { |
444 | 3089 return internal_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3090 } |
3091 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3092 DEFUN ("equalp", Fequalp, 2, 2, 0, /* |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3093 Return t if two Lisp objects have similar structure and contents. |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3094 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3095 This is like `equal', except that it accepts numerically equal |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3096 numbers of different types (float, integer, bignum, bigfloat), and also |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3097 compares strings and characters case-insensitively. |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3098 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3099 Type objects that are arrays (that is, strings, bit-vectors, and vectors) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3100 of the same length and with contents that are `equalp' are themselves |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3101 `equalp', regardless of whether the two objects have the same type. |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3102 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3103 Other objects whose primary purpose is as containers of other objects are |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3104 `equalp' if they would otherwise be equal (same length, type, etc.) and |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3105 their contents are `equalp'. This goes for conses, weak lists, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3106 weak boxes, ephemerons, specifiers, hash tables, char tables and range |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3107 tables. However, objects that happen to contain other objects but are not |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3108 primarily designed for this purpose (e.g. compiled functions, events or |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3109 display-related objects such as glyphs, faces or extents) are currently |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3110 compared using `equalp' the same way as using `equal'. |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3111 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3112 More specifically, two hash tables are `equalp' if they have the same test |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3113 (see `hash-table-test'), the same number of entries, and the same value for |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3114 `hash-table-weakness', and if, for each entry in one hash table, its key is |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3115 equivalent to a key in the other hash table using the hash table test, and |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3116 its value is `equalp' to the other hash table's value for that key. |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3117 */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3118 (object1, object2)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3119 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3120 return internal_equalp (object1, object2, 0) ? Qt : Qnil; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3121 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3122 |
428 | 3123 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* |
3124 Return t if two Lisp objects have similar structure and contents. | |
3125 They must have the same data type. | |
3126 \(Note, however, that an exception is made for characters and integers; | |
3127 this is known as the "char-int confoundance disease." See `eq' and | |
3128 `old-eq'.) | |
3129 This function is provided only for byte-code compatibility with v19. | |
3130 Do not use it. | |
3131 */ | |
444 | 3132 (object1, object2)) |
428 | 3133 { |
444 | 3134 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3135 } |
3136 | |
3137 | |
3138 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /* | |
434 | 3139 Destructively modify ARRAY by replacing each element with ITEM. |
428 | 3140 ARRAY is a vector, bit vector, or string. |
3141 */ | |
3142 (array, item)) | |
3143 { | |
3144 retry: | |
3145 if (STRINGP (array)) | |
3146 { | |
793 | 3147 Bytecount old_bytecount = XSTRING_LENGTH (array); |
434 | 3148 Bytecount new_bytecount; |
3149 Bytecount item_bytecount; | |
867 | 3150 Ibyte item_buf[MAX_ICHAR_LEN]; |
3151 Ibyte *p; | |
3152 Ibyte *end; | |
434 | 3153 |
428 | 3154 CHECK_CHAR_COERCE_INT (item); |
2720 | 3155 |
428 | 3156 CHECK_LISP_WRITEABLE (array); |
771 | 3157 sledgehammer_check_ascii_begin (array); |
867 | 3158 item_bytecount = set_itext_ichar (item_buf, XCHAR (item)); |
826 | 3159 new_bytecount = item_bytecount * (Bytecount) string_char_length (array); |
793 | 3160 |
3161 resize_string (array, -1, new_bytecount - old_bytecount); | |
3162 | |
3163 for (p = XSTRING_DATA (array), end = p + new_bytecount; | |
434 | 3164 p < end; |
3165 p += item_bytecount) | |
3166 memcpy (p, item_buf, item_bytecount); | |
3167 *p = '\0'; | |
3168 | |
793 | 3169 XSET_STRING_ASCII_BEGIN (array, |
3170 item_bytecount == 1 ? | |
3171 min (new_bytecount, MAX_STRING_ASCII_BEGIN) : | |
3172 0); | |
428 | 3173 bump_string_modiff (array); |
771 | 3174 sledgehammer_check_ascii_begin (array); |
428 | 3175 } |
3176 else if (VECTORP (array)) | |
3177 { | |
3178 Lisp_Object *p = XVECTOR_DATA (array); | |
665 | 3179 Elemcount len = XVECTOR_LENGTH (array); |
428 | 3180 CHECK_LISP_WRITEABLE (array); |
3181 while (len--) | |
3182 *p++ = item; | |
3183 } | |
3184 else if (BIT_VECTORP (array)) | |
3185 { | |
440 | 3186 Lisp_Bit_Vector *v = XBIT_VECTOR (array); |
665 | 3187 Elemcount len = bit_vector_length (v); |
428 | 3188 int bit; |
3189 CHECK_BIT (item); | |
444 | 3190 bit = XINT (item); |
428 | 3191 CHECK_LISP_WRITEABLE (array); |
3192 while (len--) | |
3193 set_bit_vector_bit (v, len, bit); | |
3194 } | |
3195 else | |
3196 { | |
3197 array = wrong_type_argument (Qarrayp, array); | |
3198 goto retry; | |
3199 } | |
3200 return array; | |
3201 } | |
3202 | |
3203 Lisp_Object | |
3204 nconc2 (Lisp_Object arg1, Lisp_Object arg2) | |
3205 { | |
3206 Lisp_Object args[2]; | |
3207 struct gcpro gcpro1; | |
3208 args[0] = arg1; | |
3209 args[1] = arg2; | |
3210 | |
3211 GCPRO1 (args[0]); | |
3212 gcpro1.nvars = 2; | |
3213 | |
3214 RETURN_UNGCPRO (bytecode_nconc2 (args)); | |
3215 } | |
3216 | |
3217 Lisp_Object | |
3218 bytecode_nconc2 (Lisp_Object *args) | |
3219 { | |
3220 retry: | |
3221 | |
3222 if (CONSP (args[0])) | |
3223 { | |
3224 /* (setcdr (last args[0]) args[1]) */ | |
3225 Lisp_Object tortoise, hare; | |
665 | 3226 Elemcount count; |
428 | 3227 |
3228 for (hare = tortoise = args[0], count = 0; | |
3229 CONSP (XCDR (hare)); | |
3230 hare = XCDR (hare), count++) | |
3231 { | |
3232 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3233 | |
3234 if (count & 1) | |
3235 tortoise = XCDR (tortoise); | |
3236 if (EQ (hare, tortoise)) | |
3237 signal_circular_list_error (args[0]); | |
3238 } | |
3239 XCDR (hare) = args[1]; | |
3240 return args[0]; | |
3241 } | |
3242 else if (NILP (args[0])) | |
3243 { | |
3244 return args[1]; | |
3245 } | |
3246 else | |
3247 { | |
3248 args[0] = wrong_type_argument (args[0], Qlistp); | |
3249 goto retry; | |
3250 } | |
3251 } | |
3252 | |
3253 DEFUN ("nconc", Fnconc, 0, MANY, 0, /* | |
3254 Concatenate any number of lists by altering them. | |
3255 Only the last argument is not altered, and need not be a list. | |
3256 Also see: `append'. | |
3257 If the first argument is nil, there is no way to modify it by side | |
3258 effect; therefore, write `(setq foo (nconc foo list))' to be sure of | |
3259 changing the value of `foo'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
3260 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
3261 arguments: (&rest ARGS) |
428 | 3262 */ |
3263 (int nargs, Lisp_Object *args)) | |
3264 { | |
3265 int argnum = 0; | |
3266 struct gcpro gcpro1; | |
3267 | |
3268 /* The modus operandi in Emacs is "caller gc-protects args". | |
3269 However, nconc (particularly nconc2 ()) is called many times | |
3270 in Emacs on freshly created stuff (e.g. you see the idiom | |
3271 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those | |
3272 callers out by protecting the args ourselves to save them | |
3273 a lot of temporary-variable grief. */ | |
3274 | |
3275 GCPRO1 (args[0]); | |
3276 gcpro1.nvars = nargs; | |
3277 | |
3278 while (argnum < nargs) | |
3279 { | |
3280 Lisp_Object val; | |
3281 retry: | |
3282 val = args[argnum]; | |
3283 if (CONSP (val)) | |
3284 { | |
3285 /* `val' is the first cons, which will be our return value. */ | |
3286 /* `last_cons' will be the cons cell to mutate. */ | |
3287 Lisp_Object last_cons = val; | |
3288 Lisp_Object tortoise = val; | |
3289 | |
3290 for (argnum++; argnum < nargs; argnum++) | |
3291 { | |
3292 Lisp_Object next = args[argnum]; | |
3293 retry_next: | |
3294 if (CONSP (next) || argnum == nargs -1) | |
3295 { | |
3296 /* (setcdr (last val) next) */ | |
665 | 3297 Elemcount count; |
428 | 3298 |
3299 for (count = 0; | |
3300 CONSP (XCDR (last_cons)); | |
3301 last_cons = XCDR (last_cons), count++) | |
3302 { | |
3303 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3304 | |
3305 if (count & 1) | |
3306 tortoise = XCDR (tortoise); | |
3307 if (EQ (last_cons, tortoise)) | |
3308 signal_circular_list_error (args[argnum-1]); | |
3309 } | |
3310 XCDR (last_cons) = next; | |
3311 } | |
3312 else if (NILP (next)) | |
3313 { | |
3314 continue; | |
3315 } | |
3316 else | |
3317 { | |
3318 next = wrong_type_argument (Qlistp, next); | |
3319 goto retry_next; | |
3320 } | |
3321 } | |
3322 RETURN_UNGCPRO (val); | |
3323 } | |
3324 else if (NILP (val)) | |
3325 argnum++; | |
3326 else if (argnum == nargs - 1) /* last arg? */ | |
3327 RETURN_UNGCPRO (val); | |
3328 else | |
3329 { | |
3330 args[argnum] = wrong_type_argument (Qlistp, val); | |
3331 goto retry; | |
3332 } | |
3333 } | |
3334 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */ | |
3335 } | |
3336 | |
3337 | |
434 | 3338 /* This is the guts of several mapping functions. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3339 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3340 Call FUNCTION CALL_COUNT times, with NSEQUENCES arguments each time, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3341 taking the elements from SEQUENCES. If VALS is non-NULL, store the |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3342 results into VALS, a C array of Lisp_Objects; else, if LISP_VALS is |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3343 non-nil, store the results into LISP_VALS, a sequence with sufficient |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3344 room for CALL_COUNT results (but see the documentation of SOME_OR_EVERY.) |
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3345 Else, do not accumulate any result. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3346 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3347 If VALS is non-NULL, NSEQUENCES is one, and SEQUENCES[0] is a cons, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3348 mapcarX will store the elements of SEQUENCES[0] in stack and GCPRO them, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3349 so FUNCTION cannot insert a non-cons into SEQUENCES[0] and throw off |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3350 mapcarX. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3351 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3352 Otherwise, mapcarX signals a wrong-type-error if it encounters a |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3353 non-cons, non-array when traversing SEQUENCES. Common Lisp specifies in |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3354 MAPPING-DESTRUCTIVE-INTERACTION that it is an error when FUNCTION |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3355 destructively modifies SEQUENCES in a way that might affect the ongoing |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3356 traversal operation. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3357 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3358 If SOME_OR_EVERY is SOME_OR_EVERY_SOME, return the (possibly multiple) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3359 values given by FUNCTION the first time it is non-nil, and abandon the |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3360 iterations. LISP_VALS must be a cons, and the return value will be |
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3361 stored in its car. If SOME_OR_EVERY is SOME_OR_EVERY_EVERY, store Qnil |
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3362 in the car of LISP_VALS if FUNCTION gives nil; otherwise leave it |
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3363 alone. */ |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3364 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3365 #define SOME_OR_EVERY_NEITHER 0 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3366 #define SOME_OR_EVERY_SOME 1 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3367 #define SOME_OR_EVERY_EVERY 2 |
428 | 3368 |
3369 static void | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3370 mapcarX (Elemcount call_count, Lisp_Object *vals, Lisp_Object lisp_vals, |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3371 Lisp_Object function, int nsequences, Lisp_Object *sequences, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3372 int some_or_every) |
428 | 3373 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3374 Lisp_Object called, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3375 struct gcpro gcpro1, gcpro2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3376 int i, j; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3377 enum lrecord_type lisp_vals_type; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3378 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3379 assert (LRECORDP (lisp_vals)); |
4999 | 3380 lisp_vals_type = (enum lrecord_type) XRECORD_LHEADER (lisp_vals)->type; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3381 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3382 args = alloca_array (Lisp_Object, nsequences + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3383 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3384 for (i = 1; i <= nsequences; ++i) |
428 | 3385 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3386 args[i] = Qnil; |
428 | 3387 } |
3388 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3389 if (vals != NULL) |
428 | 3390 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3391 GCPRO2 (args[0], vals[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3392 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3393 gcpro2.nvars = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3394 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3395 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3396 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3397 GCPRO1 (args[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3398 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3399 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3400 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3401 /* Be extra nice in the event that we've been handed one list and one |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3402 only; make it possible for FUNCTION to set cdrs not yet processed to |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3403 non-cons, non-nil objects without ill-effect, if we have been handed |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3404 the stack space to do that. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3405 if (vals != NULL && 1 == nsequences && CONSP (sequences[0])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3406 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3407 Lisp_Object lst = sequences[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3408 Lisp_Object *val = vals; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3409 for (i = 0; i < call_count; ++i) |
434 | 3410 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3411 *val++ = XCAR (lst); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3412 lst = XCDR (lst); |
428 | 3413 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3414 gcpro2.nvars = call_count; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3415 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3416 for (i = 0; i < call_count; ++i) |
428 | 3417 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3418 args[1] = vals[i]; |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3419 vals[i] = IGNORE_MULTIPLE_VALUES (Ffuncall (nsequences + 1, args)); |
428 | 3420 } |
3421 } | |
3422 else | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3423 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3424 Binbyte *sequence_types = alloca_array (Binbyte, nsequences); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3425 for (j = 0; j < nsequences; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3426 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3427 sequence_types[j] = XRECORD_LHEADER (sequences[j])->type; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3428 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3429 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3430 for (i = 0; i < call_count; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3431 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3432 for (j = 0; j < nsequences; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3433 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3434 switch (sequence_types[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3435 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3436 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3437 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3438 if (!CONSP (sequences[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3439 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3440 /* This means FUNCTION has probably messed |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3441 around with a cons in one of the sequences, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3442 since we checked the type |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3443 (CHECK_SEQUENCE()) and the length and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3444 structure (with Flength()) correctly in our |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3445 callers. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3446 dead_wrong_type_argument (Qconsp, sequences[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3447 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3448 args[j + 1] = XCAR (sequences[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3449 sequences[j] = XCDR (sequences[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3450 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3451 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3452 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3453 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3454 args[j + 1] = XVECTOR_DATA (sequences[j])[i]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3455 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3456 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3457 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3458 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3459 args[j + 1] = make_char (string_ichar (sequences[j], i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3460 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3461 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3462 case lrecord_type_bit_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3463 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3464 args[j + 1] |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3465 = make_int (bit_vector_bit (XBIT_VECTOR (sequences[j]), |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3466 i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3467 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3468 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3469 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3470 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3471 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3472 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3473 called = Ffuncall (nsequences + 1, args); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3474 if (vals != NULL) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3475 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3476 vals[i] = IGNORE_MULTIPLE_VALUES (called); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3477 gcpro2.nvars += 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3478 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3479 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3480 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3481 switch (lisp_vals_type) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3482 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3483 case lrecord_type_symbol: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3484 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3485 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3486 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3487 if (SOME_OR_EVERY_NEITHER == some_or_every) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3488 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3489 called = IGNORE_MULTIPLE_VALUES (called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3490 if (!CONSP (lisp_vals)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3491 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3492 /* If FUNCTION has inserted a non-cons non-nil |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3493 cdr into the list before we've processed the |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3494 relevant part, error. */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3495 dead_wrong_type_argument (Qconsp, lisp_vals); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3496 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3497 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3498 XSETCAR (lisp_vals, called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3499 lisp_vals = XCDR (lisp_vals); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3500 break; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3501 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3502 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3503 if (SOME_OR_EVERY_SOME == some_or_every) |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3504 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3505 if (!NILP (IGNORE_MULTIPLE_VALUES (called))) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3506 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3507 XCAR (lisp_vals) = called; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3508 UNGCPRO; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3509 return; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3510 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3511 break; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3512 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3513 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3514 if (SOME_OR_EVERY_EVERY == some_or_every) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3515 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3516 called = IGNORE_MULTIPLE_VALUES (called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3517 if (NILP (called)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3518 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3519 XCAR (lisp_vals) = Qnil; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3520 UNGCPRO; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3521 return; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3522 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3523 break; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3524 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3525 |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3526 goto bad_some_or_every_flag; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3527 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3528 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3529 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3530 called = IGNORE_MULTIPLE_VALUES (called); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3531 i < XVECTOR_LENGTH (lisp_vals) ? |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3532 (XVECTOR_DATA (lisp_vals)[i] = called) : |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3533 /* Let #'aset error. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3534 Faset (lisp_vals, make_int (i), called); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3535 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3536 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3537 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3538 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3539 /* If this ever becomes a code hotspot, we can keep |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3540 around pointers into the data of the string, checking |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3541 each time that it hasn't been relocated. */ |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3542 called = IGNORE_MULTIPLE_VALUES (called); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3543 Faset (lisp_vals, make_int (i), called); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3544 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3545 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3546 case lrecord_type_bit_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3547 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3548 called = IGNORE_MULTIPLE_VALUES (called); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3549 (BITP (called) && |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3550 i < bit_vector_length (XBIT_VECTOR (lisp_vals))) ? |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3551 set_bit_vector_bit (XBIT_VECTOR (lisp_vals), i, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3552 XINT (called)) : |
5002
0cd784a6ec44
fix some compile bugs of Aidan's
Ben Wing <ben@xemacs.org>
parents:
5001
diff
changeset
|
3553 (void) Faset (lisp_vals, make_int (i), called); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3554 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3555 } |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3556 bad_some_or_every_flag: |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3557 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3558 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3559 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3560 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3561 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3562 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3563 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3564 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3565 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3566 UNGCPRO; |
428 | 3567 } |
3568 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3569 DEFUN ("mapconcat", Fmapconcat, 3, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3570 Call FUNCTION on each element of SEQUENCE, and concat results to a string. |
751 | 3571 Between each pair of results, insert SEPARATOR. |
3572 | |
3573 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR | |
3574 results in spaces between the values returned by FUNCTION. SEQUENCE itself | |
3575 may be a list, a vector, a bit vector, or a string. | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3576 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3577 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3578 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3579 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3580 `mapconcat' will give up once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3581 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3582 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES) |
428 | 3583 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3584 (int nargs, Lisp_Object *args)) |
428 | 3585 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3586 Lisp_Object function = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3587 Lisp_Object sequence = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3588 Lisp_Object separator = args[2]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3589 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3590 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3591 EMACS_INT i, nargs0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3592 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3593 args[2] = sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3594 args[1] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3595 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3596 for (i = 2; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3597 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3598 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3599 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3600 } |
428 | 3601 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3602 if (len == 0) return build_ascstring (""); |
428 | 3603 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3604 nargs0 = len + len - 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3605 args0 = alloca_array (Lisp_Object, nargs0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3606 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3607 /* Special-case this, it's very common and doesn't require any |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3608 funcalls. Upside of doing it here, instead of cl-macs.el: no consing, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3609 apart from the final string, we allocate everything on the stack. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3610 if (EQ (function, Qidentity) && 3 == nargs && CONSP (sequence)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3611 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3612 for (i = 0; i < len; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3613 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3614 args0[i] = XCAR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3615 sequence = XCDR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3616 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3617 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3618 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3619 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3620 mapcarX (len, args0, Qnil, function, nargs - 2, args + 2, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3621 SOME_OR_EVERY_NEITHER); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3622 } |
428 | 3623 |
3624 for (i = len - 1; i >= 0; i--) | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3625 args0[i + i] = args0[i]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3626 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3627 for (i = 1; i < nargs0; i += 2) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3628 args0[i] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3629 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3630 return Fconcat (nargs0, args0); |
428 | 3631 } |
3632 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3633 DEFUN ("mapcar*", FmapcarX, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3634 Call FUNCTION on each element of SEQUENCE; return a list of the results. |
434 | 3635 The result is a list of the same length as SEQUENCE. |
428 | 3636 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3637 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3638 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3639 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3640 from each sequence will be used each time FUNCTION is called, and `mapcar' |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3641 stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3642 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3643 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3644 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3645 (int nargs, Lisp_Object *args)) |
428 | 3646 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3647 Lisp_Object function = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3648 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3649 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3650 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3651 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3652 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3653 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3654 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3655 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3656 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3657 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3658 args0 = alloca_array (Lisp_Object, len); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3659 mapcarX (len, args0, Qnil, function, nargs - 1, args + 1, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3660 SOME_OR_EVERY_NEITHER); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3661 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3662 return Flist ((int) len, args0); |
428 | 3663 } |
3664 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3665 DEFUN ("mapvector", Fmapvector, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3666 Call FUNCTION on each element of SEQUENCE; return a vector of the results. |
428 | 3667 The result is a vector of the same length as SEQUENCE. |
434 | 3668 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3669 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3670 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3671 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3672 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3673 `mapvector' stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3674 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3675 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3676 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3677 (int nargs, Lisp_Object *args)) |
428 | 3678 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3679 Lisp_Object function = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3680 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3681 Lisp_Object result; |
428 | 3682 struct gcpro gcpro1; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3683 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3684 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3685 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3686 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3687 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3688 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3689 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3690 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3691 result = make_vector (len, Qnil); |
428 | 3692 GCPRO1 (result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3693 /* Don't pass result as the lisp_object argument, we want mapcarX to protect |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3694 a single list argument's elements from being garbage-collected. */ |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3695 mapcarX (len, XVECTOR_DATA (result), Qnil, function, nargs - 1, args +1, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3696 SOME_OR_EVERY_NEITHER); |
428 | 3697 UNGCPRO; |
3698 | |
3699 return result; | |
3700 } | |
3701 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3702 DEFUN ("mapcan", Fmapcan, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3703 Call FUNCTION on each element of SEQUENCE; chain the results together. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3704 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3705 FUNCTION must normally return a list; the results will be concatenated |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3706 together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3707 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3708 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3709 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3710 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3711 `mapcan' stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3712 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3713 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3714 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3715 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3716 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3717 Lisp_Object function = args[0], nconcing; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3718 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3719 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3720 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3721 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3722 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3723 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3724 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3725 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3726 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3727 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3728 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3729 args0 = alloca_array (Lisp_Object, len + 1); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3730 mapcarX (len, args0 + 1, Qnil, function, nargs - 1, args + 1, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3731 SOME_OR_EVERY_NEITHER); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3732 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3733 if (len < 2) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3734 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3735 return len ? args0[1] : Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3736 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3737 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3738 /* bytecode_nconc2 can signal and return, we need to GCPRO the args, since |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3739 mapcarX is no longer doing this for us. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3740 args0[0] = Fcons (Qnil, Qnil); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3741 GCPRO1 (args0[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3742 gcpro1.nvars = len + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3743 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3744 for (i = 0; i < len; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3745 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3746 nconcing = bytecode_nconc2 (args0 + i); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3747 args0[i + 1] = nconcing; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3748 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3749 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3750 RETURN_UNGCPRO (XCDR (nconcing)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3751 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3752 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3753 DEFUN ("mapc", Fmapc, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3754 Call FUNCTION on each element of SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3755 |
428 | 3756 SEQUENCE may be a list, a vector, a bit vector, or a string. |
3757 This function is like `mapcar' but does not accumulate the results, | |
3758 which is more efficient if you do not use the results. | |
3759 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3760 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3761 there are SEQUENCES, plus one for the elements from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3762 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3763 `mapc' stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3764 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3765 Return SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3766 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3767 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3768 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3769 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3770 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3771 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3772 Lisp_Object sequence = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3773 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3774 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3775 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3776 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3777 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3778 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3779 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3780 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3781 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3782 /* We need to GCPRO sequence, because mapcarX will modify the |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3783 elements of the args array handed to it, and this may involve |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3784 elements of sequence getting garbage collected. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3785 GCPRO1 (sequence); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3786 mapcarX (len, NULL, Qnil, args[0], nargs - 1, args + 1, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3787 SOME_OR_EVERY_NEITHER); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3788 RETURN_UNGCPRO (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3789 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3790 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3791 DEFUN ("map", Fmap, 3, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3792 Map FUNCTION across one or more sequences, returning a sequence. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3793 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3794 TYPE is the sequence type to return, FUNCTION is the function, SEQUENCE is |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3795 the first argument sequence, SEQUENCES are the other argument sequences. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3796 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3797 FUNCTION will be called with (1+ (length SEQUENCES)) arguments, and must be |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3798 capable of accepting this number of arguments. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3799 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3800 Certain TYPEs are recognised internally by `map', but others are not, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3801 `coerce' may throw an error on an attempt to convert to a TYPE it does not |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3802 understand. A null TYPE means do not accumulate any values. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3803 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3804 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3805 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3806 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3807 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3808 Lisp_Object type = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3809 Lisp_Object function = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3810 Lisp_Object result = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3811 Lisp_Object *args0 = NULL; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3812 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3813 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3814 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3815 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3816 for (i = 2; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3817 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3818 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3819 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3820 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3821 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3822 if (!NILP (type)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3823 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3824 args0 = alloca_array (Lisp_Object, len); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3825 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3826 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3827 mapcarX (len, args0, Qnil, function, nargs - 2, args + 2, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3828 SOME_OR_EVERY_NEITHER); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3829 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3830 if (EQ (type, Qnil)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3831 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3832 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3833 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3834 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3835 if (EQ (type, Qvector) || EQ (type, Qarray)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3836 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3837 result = Fvector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3838 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3839 else if (EQ (type, Qstring)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3840 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3841 result = Fstring (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3842 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3843 else if (EQ (type, Qlist)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3844 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3845 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3846 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3847 else if (EQ (type, Qbit_vector)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3848 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3849 result = Fbit_vector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3850 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3851 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3852 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3853 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3854 GCPRO1 (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3855 result = call2 (Qcoerce, result, type); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3856 UNGCPRO; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3857 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3858 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3859 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3860 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3861 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3862 DEFUN ("map-into", Fmap_into, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3863 Modify RESULT-SEQUENCE using the return values of FUNCTION on SEQUENCES. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3864 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3865 RESULT-SEQUENCE and SEQUENCES can be lists or arrays. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3866 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3867 FUNCTION must accept at least as many arguments as there are SEQUENCES |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3868 \(possibly zero). If RESULT-SEQUENCE and the elements of SEQUENCES are not |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3869 the same length, stop when the shortest is exhausted; any elements of |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3870 RESULT-SEQUENCE beyond that are unmodified. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3871 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3872 Return RESULT-SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3873 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3874 arguments: (RESULT-SEQUENCE FUNCTION &rest SEQUENCES) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3875 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3876 (int nargs, Lisp_Object *args)) |
428 | 3877 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3878 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3879 Lisp_Object result_sequence = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3880 Lisp_Object function = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3881 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3882 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3883 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3884 args[1] = result_sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3885 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3886 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3887 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3888 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3889 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3890 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3891 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3892 mapcarX (len, NULL, result_sequence, function, nargs - 2, args + 2, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3893 SOME_OR_EVERY_NEITHER); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3894 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3895 return result_sequence; |
428 | 3896 } |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3897 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3898 DEFUN ("some", Fsome, 2, MANY, 0, /* |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3899 Return true if PREDICATE gives non-nil for an element of SEQUENCE. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3900 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3901 If so, return the value (possibly multiple) given by PREDICATE. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3902 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3903 With optional SEQUENCES, call PREDICATE each time with as many arguments as |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3904 there are SEQUENCES (plus one for the element from SEQUENCE). |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3905 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3906 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3907 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3908 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3909 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3910 Lisp_Object result_box = Fcons (Qnil, Qnil); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3911 struct gcpro gcpro1; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3912 Elemcount len = EMACS_INT_MAX; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3913 int i; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3914 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3915 GCPRO1 (result_box); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3916 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3917 for (i = 1; i < nargs; ++i) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3918 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3919 CHECK_SEQUENCE (args[i]); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3920 len = min (len, XINT (Flength (args[i]))); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3921 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3922 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3923 mapcarX (len, NULL, result_box, args[0], nargs - 1, args +1, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3924 SOME_OR_EVERY_SOME); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3925 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3926 RETURN_UNGCPRO (XCAR (result_box)); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3927 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3928 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3929 DEFUN ("every", Fevery, 2, MANY, 0, /* |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3930 Return true if PREDICATE is true of every element of SEQUENCE. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3931 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3932 With optional SEQUENCES, call PREDICATE each time with as many arguments as |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3933 there are SEQUENCES (plus one for the element from SEQUENCE). |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3934 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3935 In contrast to `some', `every' never returns multiple values. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3936 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3937 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3938 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3939 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3940 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3941 Lisp_Object result_box = Fcons (Qt, Qnil); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3942 struct gcpro gcpro1; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3943 Elemcount len = EMACS_INT_MAX; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3944 int i; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3945 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3946 GCPRO1 (result_box); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3947 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3948 for (i = 1; i < nargs; ++i) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3949 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3950 CHECK_SEQUENCE (args[i]); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3951 len = min (len, XINT (Flength (args[i]))); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3952 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3953 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3954 mapcarX (len, NULL, result_box, args[0], nargs - 1, args +1, |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3955 SOME_OR_EVERY_EVERY); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3956 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3957 RETURN_UNGCPRO (XCAR (result_box)); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3958 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3959 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3960 /* Call FUNCTION with NLISTS arguments repeatedly, each Nth argument |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3961 corresponding to the result of calling (nthcdr ITERATION-COUNT LISTS[N]), |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3962 until that #'nthcdr expression gives nil for some element of LISTS. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3963 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3964 If MAPLP is zero, return LISTS[0]. Otherwise, return a list of the return |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3965 values from FUNCTION; if NCONCP is non-zero, nconc them together. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3966 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3967 In contrast to mapcarX, we don't require our callers to check LISTS for |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3968 well-formedness, we signal wrong-type-argument if it's not a list, or |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3969 circular-list if it's circular. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3970 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3971 static Lisp_Object |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3972 maplist (Lisp_Object function, int nlists, Lisp_Object *lists, int maplp, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3973 int nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3974 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3975 Lisp_Object result = maplp ? lists[0] : Fcons (Qnil, Qnil), funcalled; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3976 Lisp_Object nconcing[2], accum = result, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3977 struct gcpro gcpro1, gcpro2, gcpro3; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3978 int i, j, continuing = (nlists > 0), called_count = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3979 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3980 args = alloca_array (Lisp_Object, nlists + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3981 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3982 for (i = 1; i <= nlists; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3983 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3984 args[i] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3985 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3986 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3987 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3988 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3989 nconcing[0] = result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3990 nconcing[1] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3991 GCPRO3 (args[0], nconcing[0], result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3992 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3993 gcpro2.nvars = 2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3994 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3995 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3996 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3997 GCPRO2 (args[0], result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3998 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3999 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4000 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4001 while (continuing) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4002 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4003 for (j = 0; j < nlists; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4004 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4005 if (CONSP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4006 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4007 args[j + 1] = lists[j]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4008 lists[j] = XCDR (lists[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4009 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4010 else if (NILP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4011 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4012 continuing = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4013 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4014 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4015 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4016 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4017 dead_wrong_type_argument (Qlistp, lists[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4018 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4019 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4020 if (!continuing) break; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4021 funcalled = IGNORE_MULTIPLE_VALUES (Ffuncall (nlists + 1, args)); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4022 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4023 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4024 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4025 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4026 /* This order of calls means we check that each list is |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4027 well-formed once and once only. The last result does |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4028 not have to be a list. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4029 nconcing[1] = funcalled; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4030 nconcing[0] = bytecode_nconc2 (nconcing); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4031 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4032 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4033 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4034 /* Add to the end, avoiding the need to call nreverse |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4035 once we're done: */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4036 XSETCDR (accum, Fcons (funcalled, Qnil)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4037 accum = XCDR (accum); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4038 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4039 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4040 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4041 if (++called_count % CIRCULAR_LIST_SUSPICION_LENGTH) continue; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4042 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4043 for (j = 0; j < nlists; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4044 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4045 EXTERNAL_LIST_LOOP_1 (lists[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4046 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4047 /* Just check the lists aren't circular, using the |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4048 EXTERNAL_LIST_LOOP_1 macro. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4049 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4050 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4051 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4052 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4053 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4054 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4055 result = XCDR (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4056 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4057 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4058 RETURN_UNGCPRO (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4059 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4060 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4061 DEFUN ("maplist", Fmaplist, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4062 Call FUNCTION on each sublist of LIST and LISTS. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4063 Like `mapcar', except applies to lists and their cdr's rather than to |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4064 the elements themselves." |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4065 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4066 arguments: (FUNCTION LIST &rest LISTS) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4067 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4068 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4069 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4070 return maplist (args[0], nargs - 1, args + 1, 0, 0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4071 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4072 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4073 DEFUN ("mapl", Fmapl, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4074 Like `maplist', but do not accumulate values returned by the function. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4075 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4076 arguments: (FUNCTION LIST &rest LISTS) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4077 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4078 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4079 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4080 return maplist (args[0], nargs - 1, args + 1, 1, 0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4081 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4082 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4083 DEFUN ("mapcon", Fmapcon, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4084 Like `maplist', but chains together the values returned by FUNCTION. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4085 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4086 FUNCTION must return a list (unless it happens to be the last |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4087 iteration); the results will be concatenated together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4088 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4089 arguments: (FUNCTION LIST &rest LISTS) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4090 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4091 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4092 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4093 return maplist (args[0], nargs - 1, args + 1, 0, 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4094 } |
428 | 4095 |
771 | 4096 /* Extra random functions */ |
442 | 4097 |
4098 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /* | |
4099 Destructively replace the list OLD with NEW. | |
4100 This is like (copy-sequence NEW) except that it reuses the | |
4101 conses in OLD as much as possible. If OLD and NEW are the same | |
4102 length, no consing will take place. | |
4103 */ | |
3025 | 4104 (old, new_)) |
442 | 4105 { |
2367 | 4106 Lisp_Object oldtail = old, prevoldtail = Qnil; |
4107 | |
3025 | 4108 EXTERNAL_LIST_LOOP_2 (elt, new_) |
442 | 4109 { |
4110 if (!NILP (oldtail)) | |
4111 { | |
4112 CHECK_CONS (oldtail); | |
2367 | 4113 XCAR (oldtail) = elt; |
442 | 4114 } |
4115 else if (!NILP (prevoldtail)) | |
4116 { | |
2367 | 4117 XCDR (prevoldtail) = Fcons (elt, Qnil); |
442 | 4118 prevoldtail = XCDR (prevoldtail); |
4119 } | |
4120 else | |
2367 | 4121 old = oldtail = Fcons (elt, Qnil); |
442 | 4122 |
4123 if (!NILP (oldtail)) | |
4124 { | |
4125 prevoldtail = oldtail; | |
4126 oldtail = XCDR (oldtail); | |
4127 } | |
4128 } | |
4129 | |
4130 if (!NILP (prevoldtail)) | |
4131 XCDR (prevoldtail) = Qnil; | |
4132 else | |
4133 old = Qnil; | |
4134 | |
4135 return old; | |
4136 } | |
4137 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4138 |
771 | 4139 Lisp_Object |
2367 | 4140 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string) |
771 | 4141 { |
4142 return Fintern (concat2 (Fsymbol_name (symbol), | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4143 build_ascstring (ascii_string)), |
771 | 4144 Qnil); |
4145 } | |
4146 | |
4147 Lisp_Object | |
2367 | 4148 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol) |
771 | 4149 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4150 return Fintern (concat2 (build_ascstring (ascii_string), |
771 | 4151 Fsymbol_name (symbol)), |
4152 Qnil); | |
4153 } | |
4154 | |
442 | 4155 |
428 | 4156 /* #### this function doesn't belong in this file! */ |
4157 | |
442 | 4158 #ifdef HAVE_GETLOADAVG |
4159 #ifdef HAVE_SYS_LOADAVG_H | |
4160 #include <sys/loadavg.h> | |
4161 #endif | |
4162 #else | |
4163 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */ | |
4164 #endif | |
4165 | |
428 | 4166 DEFUN ("load-average", Fload_average, 0, 1, 0, /* |
4167 Return list of 1 minute, 5 minute and 15 minute load averages. | |
4168 Each of the three load averages is multiplied by 100, | |
4169 then converted to integer. | |
4170 | |
4171 When USE-FLOATS is non-nil, floats will be used instead of integers. | |
4172 These floats are not multiplied by 100. | |
4173 | |
4174 If the 5-minute or 15-minute load averages are not available, return a | |
4175 shortened list, containing only those averages which are available. | |
4176 | |
4177 On some systems, this won't work due to permissions on /dev/kmem, | |
4178 in which case you can't use this. | |
4179 */ | |
4180 (use_floats)) | |
4181 { | |
4182 double load_ave[3]; | |
4183 int loads = getloadavg (load_ave, countof (load_ave)); | |
4184 Lisp_Object ret = Qnil; | |
4185 | |
4186 if (loads == -2) | |
563 | 4187 signal_error (Qunimplemented, |
4188 "load-average not implemented for this operating system", | |
4189 Qunbound); | |
428 | 4190 else if (loads < 0) |
563 | 4191 invalid_operation ("Could not get load-average", lisp_strerror (errno)); |
428 | 4192 |
4193 while (loads-- > 0) | |
4194 { | |
4195 Lisp_Object load = (NILP (use_floats) ? | |
4196 make_int ((int) (100.0 * load_ave[loads])) | |
4197 : make_float (load_ave[loads])); | |
4198 ret = Fcons (load, ret); | |
4199 } | |
4200 return ret; | |
4201 } | |
4202 | |
4203 | |
4204 Lisp_Object Vfeatures; | |
4205 | |
4206 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /* | |
4207 Return non-nil if feature FEXP is present in this Emacs. | |
4208 Use this to conditionalize execution of lisp code based on the | |
4209 presence or absence of emacs or environment extensions. | |
4210 FEXP can be a symbol, a number, or a list. | |
4211 If it is a symbol, that symbol is looked up in the `features' variable, | |
4212 and non-nil will be returned if found. | |
4213 If it is a number, the function will return non-nil if this Emacs | |
4214 has an equal or greater version number than FEXP. | |
4215 If it is a list whose car is the symbol `and', it will return | |
4216 non-nil if all the features in its cdr are non-nil. | |
4217 If it is a list whose car is the symbol `or', it will return non-nil | |
4218 if any of the features in its cdr are non-nil. | |
4219 If it is a list whose car is the symbol `not', it will return | |
4220 non-nil if the feature is not present. | |
4221 | |
4222 Examples: | |
4223 | |
4224 (featurep 'xemacs) | |
4225 => ; Non-nil on XEmacs. | |
4226 | |
4227 (featurep '(and xemacs gnus)) | |
4228 => ; Non-nil on XEmacs with Gnus loaded. | |
4229 | |
4230 (featurep '(or tty-frames (and emacs 19.30))) | |
4231 => ; Non-nil if this Emacs supports TTY frames. | |
4232 | |
4233 (featurep '(or (and xemacs 19.15) (and emacs 19.34))) | |
4234 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later. | |
4235 | |
442 | 4236 (featurep '(and xemacs 21.02)) |
4237 => ; Non-nil on XEmacs 21.2 and later. | |
4238 | |
428 | 4239 NOTE: The advanced arguments of this function (anything other than a |
4240 symbol) are not yet supported by FSF Emacs. If you feel they are useful | |
4241 for supporting multiple Emacs variants, lobby Richard Stallman at | |
442 | 4242 <bug-gnu-emacs@gnu.org>. |
428 | 4243 */ |
4244 (fexp)) | |
4245 { | |
4246 #ifndef FEATUREP_SYNTAX | |
4247 CHECK_SYMBOL (fexp); | |
4248 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
4249 #else /* FEATUREP_SYNTAX */ | |
4250 static double featurep_emacs_version; | |
4251 | |
4252 /* Brute force translation from Erik Naggum's lisp function. */ | |
4253 if (SYMBOLP (fexp)) | |
4254 { | |
4255 /* Original definition */ | |
4256 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
4257 } | |
4258 else if (INTP (fexp) || FLOATP (fexp)) | |
4259 { | |
4260 double d = extract_float (fexp); | |
4261 | |
4262 if (featurep_emacs_version == 0.0) | |
4263 { | |
4264 featurep_emacs_version = XINT (Vemacs_major_version) + | |
4265 (XINT (Vemacs_minor_version) / 100.0); | |
4266 } | |
4267 return featurep_emacs_version >= d ? Qt : Qnil; | |
4268 } | |
4269 else if (CONSP (fexp)) | |
4270 { | |
4271 Lisp_Object tem = XCAR (fexp); | |
4272 if (EQ (tem, Qnot)) | |
4273 { | |
4274 Lisp_Object negate; | |
4275 | |
4276 tem = XCDR (fexp); | |
4277 negate = Fcar (tem); | |
4278 if (!NILP (tem)) | |
4279 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil; | |
4280 else | |
4281 return Fsignal (Qinvalid_read_syntax, list1 (tem)); | |
4282 } | |
4283 else if (EQ (tem, Qand)) | |
4284 { | |
4285 tem = XCDR (fexp); | |
4286 /* Use Fcar/Fcdr for error-checking. */ | |
4287 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem)))) | |
4288 { | |
4289 tem = Fcdr (tem); | |
4290 } | |
4291 return NILP (tem) ? Qt : Qnil; | |
4292 } | |
4293 else if (EQ (tem, Qor)) | |
4294 { | |
4295 tem = XCDR (fexp); | |
4296 /* Use Fcar/Fcdr for error-checking. */ | |
4297 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem)))) | |
4298 { | |
4299 tem = Fcdr (tem); | |
4300 } | |
4301 return NILP (tem) ? Qnil : Qt; | |
4302 } | |
4303 else | |
4304 { | |
4305 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp))); | |
4306 } | |
4307 } | |
4308 else | |
4309 { | |
4310 return Fsignal (Qinvalid_read_syntax, list1 (fexp)); | |
4311 } | |
4312 } | |
4313 #endif /* FEATUREP_SYNTAX */ | |
4314 | |
4315 DEFUN ("provide", Fprovide, 1, 1, 0, /* | |
4316 Announce that FEATURE is a feature of the current Emacs. | |
4317 This function updates the value of the variable `features'. | |
4318 */ | |
4319 (feature)) | |
4320 { | |
4321 Lisp_Object tem; | |
4322 CHECK_SYMBOL (feature); | |
4323 if (!NILP (Vautoload_queue)) | |
4324 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); | |
4325 tem = Fmemq (feature, Vfeatures); | |
4326 if (NILP (tem)) | |
4327 Vfeatures = Fcons (feature, Vfeatures); | |
4328 LOADHIST_ATTACH (Fcons (Qprovide, feature)); | |
4329 return feature; | |
4330 } | |
4331 | |
1067 | 4332 DEFUN ("require", Frequire, 1, 3, 0, /* |
3842 | 4333 Ensure that FEATURE is present in the Lisp environment. |
4334 FEATURE is a symbol naming a collection of resources (functions, etc). | |
4335 Optional FILENAME is a library from which to load resources; it defaults to | |
4336 the print name of FEATURE. | |
4337 Optional NOERROR, if non-nil, causes require to return nil rather than signal | |
4338 `file-error' if loading the library fails. | |
4339 | |
4340 If feature FEATURE is present in `features', update `load-history' to reflect | |
4341 the require and return FEATURE. Otherwise, try to load it from a library. | |
4342 The normal messages at start and end of loading are suppressed. | |
4343 If the library is successfully loaded and it calls `(provide FEATURE)', add | |
4344 FEATURE to `features', update `load-history' and return FEATURE. | |
4345 If the load succeeds but FEATURE is not provided by the library, signal | |
4346 `invalid-state'. | |
4347 | |
4348 The byte-compiler treats top-level calls to `require' specially, by evaluating | |
4349 them at compile time (and then compiling them normally). Thus a library may | |
4350 request that definitions that should be inlined such as macros and defsubsts | |
4351 be loaded into its compilation environment. Achieving this in other contexts | |
4352 requires an explicit \(eval-and-compile ...\) block. | |
428 | 4353 */ |
1067 | 4354 (feature, filename, noerror)) |
428 | 4355 { |
4356 Lisp_Object tem; | |
4357 CHECK_SYMBOL (feature); | |
4358 tem = Fmemq (feature, Vfeatures); | |
4359 LOADHIST_ATTACH (Fcons (Qrequire, feature)); | |
4360 if (!NILP (tem)) | |
4361 return feature; | |
4362 else | |
4363 { | |
4364 int speccount = specpdl_depth (); | |
4365 | |
4366 /* Value saved here is to be restored into Vautoload_queue */ | |
4367 record_unwind_protect (un_autoload, Vautoload_queue); | |
4368 Vautoload_queue = Qt; | |
4369 | |
1067 | 4370 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename, |
1261 | 4371 noerror, Qrequire, Qnil); |
1067 | 4372 /* If load failed entirely, return nil. */ |
4373 if (NILP (tem)) | |
4374 return unbind_to_1 (speccount, Qnil); | |
428 | 4375 |
4376 tem = Fmemq (feature, Vfeatures); | |
4377 if (NILP (tem)) | |
563 | 4378 invalid_state ("Required feature was not provided", feature); |
428 | 4379 |
4380 /* Once loading finishes, don't undo it. */ | |
4381 Vautoload_queue = Qt; | |
771 | 4382 return unbind_to_1 (speccount, feature); |
428 | 4383 } |
4384 } | |
4385 | |
4386 /* base64 encode/decode functions. | |
4387 | |
4388 Originally based on code from GNU recode. Ported to FSF Emacs by | |
4389 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and | |
4390 subsequently heavily hacked by Hrvoje Niksic. */ | |
4391 | |
4392 #define MIME_LINE_LENGTH 72 | |
4393 | |
4394 #define IS_ASCII(Character) \ | |
4395 ((Character) < 128) | |
4396 #define IS_BASE64(Character) \ | |
4397 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | |
4398 | |
4399 /* Table of characters coding the 64 values. */ | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
4400 static Ascbyte base64_value_to_char[64] = |
428 | 4401 { |
4402 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */ | |
4403 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */ | |
4404 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */ | |
4405 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */ | |
4406 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */ | |
4407 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */ | |
4408 '8', '9', '+', '/' /* 60-63 */ | |
4409 }; | |
4410 | |
4411 /* Table of base64 values for first 128 characters. */ | |
4412 static short base64_char_to_value[128] = | |
4413 { | |
4414 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */ | |
4415 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */ | |
4416 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */ | |
4417 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */ | |
4418 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */ | |
4419 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */ | |
4420 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */ | |
4421 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */ | |
4422 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */ | |
4423 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */ | |
4424 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */ | |
4425 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */ | |
4426 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */ | |
4427 }; | |
4428 | |
4429 /* The following diagram shows the logical steps by which three octets | |
4430 get transformed into four base64 characters. | |
4431 | |
4432 .--------. .--------. .--------. | |
4433 |aaaaaabb| |bbbbcccc| |ccdddddd| | |
4434 `--------' `--------' `--------' | |
4435 6 2 4 4 2 6 | |
4436 .--------+--------+--------+--------. | |
4437 |00aaaaaa|00bbbbbb|00cccccc|00dddddd| | |
4438 `--------+--------+--------+--------' | |
4439 | |
4440 .--------+--------+--------+--------. | |
4441 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD| | |
4442 `--------+--------+--------+--------' | |
4443 | |
4444 The octets are divided into 6 bit chunks, which are then encoded into | |
4445 base64 characters. */ | |
4446 | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
4447 static DECLARE_DOESNT_RETURN (base64_conversion_error (const Ascbyte *, |
2268 | 4448 Lisp_Object)); |
4449 | |
575 | 4450 static DOESNT_RETURN |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
4451 base64_conversion_error (const Ascbyte *reason, Lisp_Object frob) |
563 | 4452 { |
4453 signal_error (Qbase64_conversion_error, reason, frob); | |
4454 } | |
4455 | |
4456 #define ADVANCE_INPUT(c, stream) \ | |
867 | 4457 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \ |
563 | 4458 ((ec > 255) ? \ |
4459 (base64_conversion_error ("Non-ascii character in base64 input", \ | |
4460 make_char (ec)), 0) \ | |
867 | 4461 : (c = (Ibyte)ec), 1)) |
665 | 4462 |
4463 static Bytebpos | |
867 | 4464 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break) |
428 | 4465 { |
4466 EMACS_INT counter = 0; | |
867 | 4467 Ibyte *e = to; |
4468 Ichar ec; | |
428 | 4469 unsigned int value; |
4470 | |
4471 while (1) | |
4472 { | |
1204 | 4473 Ibyte c = 0; |
428 | 4474 if (!ADVANCE_INPUT (c, istream)) |
4475 break; | |
4476 | |
4477 /* Wrap line every 76 characters. */ | |
4478 if (line_break) | |
4479 { | |
4480 if (counter < MIME_LINE_LENGTH / 4) | |
4481 counter++; | |
4482 else | |
4483 { | |
4484 *e++ = '\n'; | |
4485 counter = 1; | |
4486 } | |
4487 } | |
4488 | |
4489 /* Process first byte of a triplet. */ | |
4490 *e++ = base64_value_to_char[0x3f & c >> 2]; | |
4491 value = (0x03 & c) << 4; | |
4492 | |
4493 /* Process second byte of a triplet. */ | |
4494 if (!ADVANCE_INPUT (c, istream)) | |
4495 { | |
4496 *e++ = base64_value_to_char[value]; | |
4497 *e++ = '='; | |
4498 *e++ = '='; | |
4499 break; | |
4500 } | |
4501 | |
4502 *e++ = base64_value_to_char[value | (0x0f & c >> 4)]; | |
4503 value = (0x0f & c) << 2; | |
4504 | |
4505 /* Process third byte of a triplet. */ | |
4506 if (!ADVANCE_INPUT (c, istream)) | |
4507 { | |
4508 *e++ = base64_value_to_char[value]; | |
4509 *e++ = '='; | |
4510 break; | |
4511 } | |
4512 | |
4513 *e++ = base64_value_to_char[value | (0x03 & c >> 6)]; | |
4514 *e++ = base64_value_to_char[0x3f & c]; | |
4515 } | |
4516 | |
4517 return e - to; | |
4518 } | |
4519 #undef ADVANCE_INPUT | |
4520 | |
4521 /* Get next character from the stream, except that non-base64 | |
4522 characters are ignored. This is in accordance with rfc2045. EC | |
867 | 4523 should be an Ichar, so that it can hold -1 as the value for EOF. */ |
428 | 4524 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \ |
867 | 4525 ec = Lstream_get_ichar (stream); \ |
428 | 4526 ++streampos; \ |
4527 /* IS_BASE64 may not be called with negative arguments so check for \ | |
4528 EOF first. */ \ | |
4529 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \ | |
4530 break; \ | |
4531 } while (1) | |
4532 | |
4533 #define STORE_BYTE(pos, val, ccnt) do { \ | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
4534 pos += set_itext_ichar (pos, (Ichar)((Binbyte)(val))); \ |
428 | 4535 ++ccnt; \ |
4536 } while (0) | |
4537 | |
665 | 4538 static Bytebpos |
867 | 4539 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr) |
428 | 4540 { |
4541 Charcount ccnt = 0; | |
867 | 4542 Ibyte *e = to; |
428 | 4543 EMACS_INT streampos = 0; |
4544 | |
4545 while (1) | |
4546 { | |
867 | 4547 Ichar ec; |
428 | 4548 unsigned long value; |
4549 | |
4550 /* Process first byte of a quadruplet. */ | |
4551 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4552 if (ec < 0) | |
4553 break; | |
4554 if (ec == '=') | |
563 | 4555 base64_conversion_error ("Illegal `=' character while decoding base64", |
4556 make_int (streampos)); | |
428 | 4557 value = base64_char_to_value[ec] << 18; |
4558 | |
4559 /* Process second byte of a quadruplet. */ | |
4560 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4561 if (ec < 0) | |
563 | 4562 base64_conversion_error ("Premature EOF while decoding base64", |
4563 Qunbound); | |
428 | 4564 if (ec == '=') |
563 | 4565 base64_conversion_error ("Illegal `=' character while decoding base64", |
4566 make_int (streampos)); | |
428 | 4567 value |= base64_char_to_value[ec] << 12; |
4568 STORE_BYTE (e, value >> 16, ccnt); | |
4569 | |
4570 /* Process third byte of a quadruplet. */ | |
4571 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4572 if (ec < 0) | |
563 | 4573 base64_conversion_error ("Premature EOF while decoding base64", |
4574 Qunbound); | |
428 | 4575 |
4576 if (ec == '=') | |
4577 { | |
4578 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4579 if (ec < 0) | |
563 | 4580 base64_conversion_error ("Premature EOF while decoding base64", |
4581 Qunbound); | |
428 | 4582 if (ec != '=') |
563 | 4583 base64_conversion_error |
4584 ("Padding `=' expected but not found while decoding base64", | |
4585 make_int (streampos)); | |
428 | 4586 continue; |
4587 } | |
4588 | |
4589 value |= base64_char_to_value[ec] << 6; | |
4590 STORE_BYTE (e, 0xff & value >> 8, ccnt); | |
4591 | |
4592 /* Process fourth byte of a quadruplet. */ | |
4593 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4594 if (ec < 0) | |
563 | 4595 base64_conversion_error ("Premature EOF while decoding base64", |
4596 Qunbound); | |
428 | 4597 if (ec == '=') |
4598 continue; | |
4599 | |
4600 value |= base64_char_to_value[ec]; | |
4601 STORE_BYTE (e, 0xff & value, ccnt); | |
4602 } | |
4603 | |
4604 *ccptr = ccnt; | |
4605 return e - to; | |
4606 } | |
4607 #undef ADVANCE_INPUT | |
4608 #undef ADVANCE_INPUT_IGNORE_NONBASE64 | |
4609 #undef STORE_BYTE | |
4610 | |
4611 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /* | |
444 | 4612 Base64-encode the region between START and END. |
428 | 4613 Return the length of the encoded text. |
4614 Optional third argument NO-LINE-BREAK means do not break long lines | |
4615 into shorter lines. | |
4616 */ | |
444 | 4617 (start, end, no_line_break)) |
428 | 4618 { |
867 | 4619 Ibyte *encoded; |
665 | 4620 Bytebpos encoded_length; |
428 | 4621 Charcount allength, length; |
4622 struct buffer *buf = current_buffer; | |
665 | 4623 Charbpos begv, zv, old_pt = BUF_PT (buf); |
428 | 4624 Lisp_Object input; |
851 | 4625 int speccount = specpdl_depth (); |
428 | 4626 |
444 | 4627 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 4628 barf_if_buffer_read_only (buf, begv, zv); |
4629 | |
4630 /* We need to allocate enough room for encoding the text. | |
4631 We need 33 1/3% more space, plus a newline every 76 | |
4632 characters, and then we round up. */ | |
4633 length = zv - begv; | |
4634 allength = length + length/3 + 1; | |
4635 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
4636 | |
4637 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
867 | 4638 /* We needn't multiply allength with MAX_ICHAR_LEN because all the |
428 | 4639 base64 characters will be single-byte. */ |
867 | 4640 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 4641 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
4642 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4643 assert (encoded_length <= allength); |
428 | 4644 Lstream_delete (XLSTREAM (input)); |
4645 | |
4646 /* Now we have encoded the region, so we insert the new contents | |
4647 and delete the old. (Insert first in order to preserve markers.) */ | |
4648 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0); | |
851 | 4649 unbind_to (speccount); |
428 | 4650 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0); |
4651 | |
4652 /* Simulate FSF Emacs implementation of this function: if point was | |
4653 in the region, place it at the beginning. */ | |
4654 if (old_pt >= begv && old_pt < zv) | |
4655 BUF_SET_PT (buf, begv); | |
4656 | |
4657 /* We return the length of the encoded text. */ | |
4658 return make_int (encoded_length); | |
4659 } | |
4660 | |
4661 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /* | |
4662 Base64 encode STRING and return the result. | |
444 | 4663 Optional argument NO-LINE-BREAK means do not break long lines |
4664 into shorter lines. | |
428 | 4665 */ |
4666 (string, no_line_break)) | |
4667 { | |
4668 Charcount allength, length; | |
665 | 4669 Bytebpos encoded_length; |
867 | 4670 Ibyte *encoded; |
428 | 4671 Lisp_Object input, result; |
4672 int speccount = specpdl_depth(); | |
4673 | |
4674 CHECK_STRING (string); | |
4675 | |
826 | 4676 length = string_char_length (string); |
428 | 4677 allength = length + length/3 + 1; |
4678 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
4679 | |
4680 input = make_lisp_string_input_stream (string, 0, -1); | |
867 | 4681 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 4682 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
4683 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4684 assert (encoded_length <= allength); |
428 | 4685 Lstream_delete (XLSTREAM (input)); |
4686 result = make_string (encoded, encoded_length); | |
851 | 4687 unbind_to (speccount); |
428 | 4688 return result; |
4689 } | |
4690 | |
4691 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /* | |
444 | 4692 Base64-decode the region between START and END. |
428 | 4693 Return the length of the decoded text. |
4694 If the region can't be decoded, return nil and don't modify the buffer. | |
4695 Characters out of the base64 alphabet are ignored. | |
4696 */ | |
444 | 4697 (start, end)) |
428 | 4698 { |
4699 struct buffer *buf = current_buffer; | |
665 | 4700 Charbpos begv, zv, old_pt = BUF_PT (buf); |
867 | 4701 Ibyte *decoded; |
665 | 4702 Bytebpos decoded_length; |
428 | 4703 Charcount length, cc_decoded_length; |
4704 Lisp_Object input; | |
4705 int speccount = specpdl_depth(); | |
4706 | |
444 | 4707 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 4708 barf_if_buffer_read_only (buf, begv, zv); |
4709 | |
4710 length = zv - begv; | |
4711 | |
4712 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
4713 /* We need to allocate enough room for decoding the text. */ | |
867 | 4714 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 4715 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, &cc_decoded_length); |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4716 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 4717 Lstream_delete (XLSTREAM (input)); |
4718 | |
4719 /* Now we have decoded the region, so we insert the new contents | |
4720 and delete the old. (Insert first in order to preserve markers.) */ | |
4721 BUF_SET_PT (buf, begv); | |
4722 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0); | |
851 | 4723 unbind_to (speccount); |
428 | 4724 buffer_delete_range (buf, begv + cc_decoded_length, |
4725 zv + cc_decoded_length, 0); | |
4726 | |
4727 /* Simulate FSF Emacs implementation of this function: if point was | |
4728 in the region, place it at the beginning. */ | |
4729 if (old_pt >= begv && old_pt < zv) | |
4730 BUF_SET_PT (buf, begv); | |
4731 | |
4732 return make_int (cc_decoded_length); | |
4733 } | |
4734 | |
4735 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /* | |
4736 Base64-decode STRING and return the result. | |
4737 Characters out of the base64 alphabet are ignored. | |
4738 */ | |
4739 (string)) | |
4740 { | |
867 | 4741 Ibyte *decoded; |
665 | 4742 Bytebpos decoded_length; |
428 | 4743 Charcount length, cc_decoded_length; |
4744 Lisp_Object input, result; | |
4745 int speccount = specpdl_depth(); | |
4746 | |
4747 CHECK_STRING (string); | |
4748 | |
826 | 4749 length = string_char_length (string); |
428 | 4750 /* We need to allocate enough room for decoding the text. */ |
867 | 4751 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 4752 |
4753 input = make_lisp_string_input_stream (string, 0, -1); | |
4754 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, | |
4755 &cc_decoded_length); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4756 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 4757 Lstream_delete (XLSTREAM (input)); |
4758 | |
4759 result = make_string (decoded, decoded_length); | |
851 | 4760 unbind_to (speccount); |
428 | 4761 return result; |
4762 } | |
4763 | |
4764 Lisp_Object Qyes_or_no_p; | |
4765 | |
4766 void | |
4767 syms_of_fns (void) | |
4768 { | |
442 | 4769 INIT_LRECORD_IMPLEMENTATION (bit_vector); |
4770 | |
563 | 4771 DEFSYMBOL (Qstring_lessp); |
4772 DEFSYMBOL (Qidentity); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4773 DEFSYMBOL (Qvector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4774 DEFSYMBOL (Qarray); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4775 DEFSYMBOL (Qstring); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4776 DEFSYMBOL (Qlist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4777 DEFSYMBOL (Qbit_vector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4778 |
563 | 4779 DEFSYMBOL (Qyes_or_no_p); |
4780 | |
4781 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error); | |
428 | 4782 |
4783 DEFSUBR (Fidentity); | |
4784 DEFSUBR (Frandom); | |
4785 DEFSUBR (Flength); | |
4786 DEFSUBR (Fsafe_length); | |
4787 DEFSUBR (Fstring_equal); | |
801 | 4788 DEFSUBR (Fcompare_strings); |
428 | 4789 DEFSUBR (Fstring_lessp); |
4790 DEFSUBR (Fstring_modified_tick); | |
4791 DEFSUBR (Fappend); | |
4792 DEFSUBR (Fconcat); | |
4793 DEFSUBR (Fvconcat); | |
4794 DEFSUBR (Fbvconcat); | |
4795 DEFSUBR (Fcopy_list); | |
4796 DEFSUBR (Fcopy_sequence); | |
4797 DEFSUBR (Fcopy_alist); | |
4798 DEFSUBR (Fcopy_tree); | |
4799 DEFSUBR (Fsubstring); | |
4800 DEFSUBR (Fsubseq); | |
4801 DEFSUBR (Fnthcdr); | |
4802 DEFSUBR (Fnth); | |
4803 DEFSUBR (Felt); | |
4804 DEFSUBR (Flast); | |
4805 DEFSUBR (Fbutlast); | |
4806 DEFSUBR (Fnbutlast); | |
4807 DEFSUBR (Fmember); | |
4808 DEFSUBR (Fold_member); | |
4809 DEFSUBR (Fmemq); | |
4810 DEFSUBR (Fold_memq); | |
4811 DEFSUBR (Fassoc); | |
4812 DEFSUBR (Fold_assoc); | |
4813 DEFSUBR (Fassq); | |
4814 DEFSUBR (Fold_assq); | |
4815 DEFSUBR (Frassoc); | |
4816 DEFSUBR (Fold_rassoc); | |
4817 DEFSUBR (Frassq); | |
4818 DEFSUBR (Fold_rassq); | |
4819 DEFSUBR (Fdelete); | |
4820 DEFSUBR (Fold_delete); | |
4821 DEFSUBR (Fdelq); | |
4822 DEFSUBR (Fold_delq); | |
4823 DEFSUBR (Fremassoc); | |
4824 DEFSUBR (Fremassq); | |
4825 DEFSUBR (Fremrassoc); | |
4826 DEFSUBR (Fremrassq); | |
4827 DEFSUBR (Fnreverse); | |
4828 DEFSUBR (Freverse); | |
4829 DEFSUBR (Fsort); | |
4830 DEFSUBR (Fplists_eq); | |
4831 DEFSUBR (Fplists_equal); | |
4832 DEFSUBR (Flax_plists_eq); | |
4833 DEFSUBR (Flax_plists_equal); | |
4834 DEFSUBR (Fplist_get); | |
4835 DEFSUBR (Fplist_put); | |
4836 DEFSUBR (Fplist_remprop); | |
4837 DEFSUBR (Fplist_member); | |
4838 DEFSUBR (Fcheck_valid_plist); | |
4839 DEFSUBR (Fvalid_plist_p); | |
4840 DEFSUBR (Fcanonicalize_plist); | |
4841 DEFSUBR (Flax_plist_get); | |
4842 DEFSUBR (Flax_plist_put); | |
4843 DEFSUBR (Flax_plist_remprop); | |
4844 DEFSUBR (Flax_plist_member); | |
4845 DEFSUBR (Fcanonicalize_lax_plist); | |
4846 DEFSUBR (Fdestructive_alist_to_plist); | |
4847 DEFSUBR (Fget); | |
4848 DEFSUBR (Fput); | |
4849 DEFSUBR (Fremprop); | |
4850 DEFSUBR (Fobject_plist); | |
4851 DEFSUBR (Fequal); | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4852 DEFSUBR (Fequalp); |
428 | 4853 DEFSUBR (Fold_equal); |
4854 DEFSUBR (Ffillarray); | |
4855 DEFSUBR (Fnconc); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4856 DEFSUBR (FmapcarX); |
428 | 4857 DEFSUBR (Fmapvector); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4858 DEFSUBR (Fmapcan); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4859 DEFSUBR (Fmapc); |
428 | 4860 DEFSUBR (Fmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4861 DEFSUBR (Fmap); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4862 DEFSUBR (Fmap_into); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4863 DEFSUBR (Fsome); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4864 DEFSUBR (Fevery); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4865 Ffset (intern ("mapc-internal"), Fsymbol_function (intern ("mapc"))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4866 Ffset (intern ("mapcar"), Fsymbol_function (intern ("mapcar*"))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4867 DEFSUBR (Fmaplist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4868 DEFSUBR (Fmapl); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4869 DEFSUBR (Fmapcon); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4870 |
442 | 4871 DEFSUBR (Freplace_list); |
428 | 4872 DEFSUBR (Fload_average); |
4873 DEFSUBR (Ffeaturep); | |
4874 DEFSUBR (Frequire); | |
4875 DEFSUBR (Fprovide); | |
4876 DEFSUBR (Fbase64_encode_region); | |
4877 DEFSUBR (Fbase64_encode_string); | |
4878 DEFSUBR (Fbase64_decode_region); | |
4879 DEFSUBR (Fbase64_decode_string); | |
771 | 4880 |
4881 DEFSUBR (Fsplit_string_by_char); | |
4882 DEFSUBR (Fsplit_path); /* #### */ | |
4883 } | |
4884 | |
4885 void | |
4886 vars_of_fns (void) | |
4887 { | |
4888 DEFVAR_LISP ("path-separator", &Vpath_separator /* | |
4889 The directory separator in search paths, as a string. | |
4890 */ ); | |
4891 { | |
5000
44d7bde26046
fix compile errors, fix revert-buffer bug on binary/Latin 1 files, Mule-ize some files
Ben Wing <ben@xemacs.org>
parents:
4966
diff
changeset
|
4892 Ascbyte c = SEPCHAR; |
867 | 4893 Vpath_separator = make_string ((Ibyte *) &c, 1); |
771 | 4894 } |
428 | 4895 } |
4896 | |
4897 void | |
4898 init_provide_once (void) | |
4899 { | |
4900 DEFVAR_LISP ("features", &Vfeatures /* | |
4901 A list of symbols which are the features of the executing emacs. | |
4902 Used by `featurep' and `require', and altered by `provide'. | |
4903 */ ); | |
4904 Vfeatures = Qnil; | |
4905 | |
4906 Fprovide (intern ("base64")); | |
4907 } |