Mercurial > hg > xemacs-beta
annotate src/fns.c @ 5089:99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
src/ChangeLog addition:
2010-03-03 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (Fsubstring): Removed.
* search.c (Freplace_match):
* minibuf.c (Ftry_completion):
* lisp.h:
* keymap.c (ensure_meta_prefix_char_keymapp):
* dired.c (user_name_completion, file_name_completion):
* console-x.c (x_canonicalize_console_connection):
* bytecode.c (Bsubseq):
* bytecode-ops.h (subseq):
Move #'substring to Lisp, as an alias for #'subseq; change all
C Fsubstring() calls to Fsubseq(), change the Bsubstring bytecode
to Bsubseq.
Motivation; not accepting vectors in #'substring is incompatible
with GNU, and Common Lisp prefers #'subseq, it has no #'substring.
lisp/ChangeLog addition:
2010-03-03 Aidan Kehoe <kehoea@parhasard.net>
Move byte code #o117 to #'subseq, not #'substring.
Make #'substring available as an alias for #'subseq in Lisp.
* bytecomp.el (79, subseq, substring):
* bytecomp.el (byte-compile-subseq): New.
* update-elc.el (update-elc-chop-extension): Use #'subseq, not
#'substring, the latter is not yet available.
* subr.el (substring): New alias, to #'subseq.
man/ChangeLog addition:
2010-03-03 Aidan Kehoe <kehoea@parhasard.net>
* lispref/tips.texi (Comment Tips):
* lispref/text.texi (Text Properties):
* lispref/strings.texi (Creating Strings):
* lispref/processes.texi (Input to Processes):
* lispref/functions.texi (Argument List):
* lispref/extents.texi (Duplicable Extents):
Move examples that used substring to using subseq; in
strings.texi, do not change the examples, but document that in
this XEmacs, it is an alias for subseq, and that there may be some
incompatibilities if you depend on that.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 03 Mar 2010 18:40:12 +0000 |
parents | c3d372419e09 |
children | 7be849cb8828 |
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 ("subseq", Fsubseq, 2, 3, 0, /* | |
442 | 951 Return the subsequence of SEQUENCE starting at START and ending before END. |
952 END may be omitted; then the subsequence runs to the end of SEQUENCE. | |
953 If START or END is negative, it counts from the end. | |
954 The returned subsequence is always of the same type as SEQUENCE. | |
955 If SEQUENCE is a string, relevant parts of the string-extent-data | |
956 are copied to the new string. | |
428 | 957 */ |
442 | 958 (sequence, start, end)) |
428 | 959 { |
442 | 960 EMACS_INT len, s, e; |
961 | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
962 if (STRINGP (sequence)) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
963 { |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
964 Charcount ccstart, ccend; |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
965 Bytecount bstart, blen; |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
966 Lisp_Object val; |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
967 |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
968 CHECK_INT (start); |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
969 get_string_range_char (sequence, start, end, &ccstart, &ccend, |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
970 GB_HISTORICAL_STRING_BEHAVIOR); |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
971 bstart = string_index_char_to_byte (sequence, ccstart); |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
972 blen = string_offset_char_to_byte_len (sequence, bstart, ccend - ccstart); |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
973 val = make_string (XSTRING_DATA (sequence) + bstart, blen); |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
974 /* Copy any applicable extent information into the new string. */ |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
975 copy_string_extents (val, sequence, 0, bstart, blen); |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
976 return val; |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
977 } |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
978 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
979 CHECK_SEQUENCE (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
980 |
442 | 981 len = XINT (Flength (sequence)); |
982 | |
983 CHECK_INT (start); | |
984 s = XINT (start); | |
985 if (s < 0) | |
986 s = len + s; | |
987 | |
988 if (NILP (end)) | |
989 e = len; | |
428 | 990 else |
991 { | |
442 | 992 CHECK_INT (end); |
993 e = XINT (end); | |
994 if (e < 0) | |
995 e = len + e; | |
428 | 996 } |
997 | |
442 | 998 if (!(0 <= s && s <= e && e <= len)) |
999 args_out_of_range_3 (sequence, make_int (s), make_int (e)); | |
1000 | |
1001 if (VECTORP (sequence)) | |
428 | 1002 { |
442 | 1003 Lisp_Object result = make_vector (e - s, Qnil); |
428 | 1004 EMACS_INT i; |
442 | 1005 Lisp_Object *in_elts = XVECTOR_DATA (sequence); |
428 | 1006 Lisp_Object *out_elts = XVECTOR_DATA (result); |
1007 | |
442 | 1008 for (i = s; i < e; i++) |
1009 out_elts[i - s] = in_elts[i]; | |
428 | 1010 return result; |
1011 } | |
442 | 1012 else if (LISTP (sequence)) |
428 | 1013 { |
1014 Lisp_Object result = Qnil; | |
1015 EMACS_INT i; | |
1016 | |
442 | 1017 sequence = Fnthcdr (make_int (s), sequence); |
1018 | |
1019 for (i = s; i < e; i++) | |
428 | 1020 { |
442 | 1021 result = Fcons (Fcar (sequence), result); |
1022 sequence = Fcdr (sequence); | |
428 | 1023 } |
1024 | |
1025 return Fnreverse (result); | |
1026 } | |
442 | 1027 else if (BIT_VECTORP (sequence)) |
1028 { | |
1029 Lisp_Object result = make_bit_vector (e - s, Qzero); | |
1030 EMACS_INT i; | |
1031 | |
1032 for (i = s; i < e; i++) | |
1033 set_bit_vector_bit (XBIT_VECTOR (result), i - s, | |
1034 bit_vector_bit (XBIT_VECTOR (sequence), i)); | |
1035 return result; | |
1036 } | |
1037 else | |
1038 { | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1039 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
|
1040 error */ |
442 | 1041 return Qnil; |
1042 } | |
428 | 1043 } |
1044 | |
771 | 1045 /* 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
|
1046 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
|
1047 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1048 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
|
1049 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
|
1050 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
|
1051 |
771 | 1052 static Lisp_Object |
867 | 1053 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
|
1054 Ichar sepchar, int unescape, Ichar escapechar) |
771 | 1055 { |
1056 Lisp_Object result = Qnil; | |
867 | 1057 const Ibyte *end = string + size; |
771 | 1058 |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1059 if (unescape) |
771 | 1060 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 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
|
1067 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1068 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1069 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1070 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
|
1071 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
|
1072 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
|
1073 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1074 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
|
1075 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1076 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
|
1077 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1078 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
|
1079 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1080 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
|
1081 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1082 break; |
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 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1085 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
|
1086 /* 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
|
1087 && !previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1088 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1089 ++deleting_escapes; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1090 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
|
1091 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1092 else |
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 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
|
1095 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1096 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1097 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
|
1098 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1099 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1100 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
|
1101 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1102 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
|
1103 > 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
|
1104 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1105 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
|
1106 ((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
|
1107 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
|
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 cursor = string; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1111 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
|
1112 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
|
1113 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1114 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
|
1115 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1116 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
|
1117 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1118 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
|
1119 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1120 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
|
1121 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
|
1122 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
|
1123 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1124 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1125 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
|
1126 && (pchar == escapechar); |
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 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
|
1129 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1130 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1131 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
|
1132 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 - 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
|
1134 result); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1135 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1136 else |
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 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
|
1139 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1140 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
|
1141 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1142 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1143 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
|
1144 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1145 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1146 break; |
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 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1149 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1150 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1151 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1152 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1153 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
|
1154 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
|
1155 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1156 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
|
1157 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1158 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
|
1159 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1160 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
|
1161 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
|
1162 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1163 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1164 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
|
1165 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1166 else |
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 } |
771 | 1169 } |
1170 return Fnreverse (result); | |
1171 } | |
1172 | |
1173 /* The same as the above, except PATH is an external C string (it is | |
1174 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR | |
1175 (':' or whatever). */ | |
1176 Lisp_Object | |
1177 split_external_path (const Extbyte *path) | |
1178 { | |
1179 Bytecount newlen; | |
867 | 1180 Ibyte *newpath; |
771 | 1181 if (!path) |
1182 return Qnil; | |
1183 | |
1184 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name); | |
1185 | |
1186 /* #### Does this make sense? It certainly does for | |
1187 split_env_path(), but it looks dubious here. Does any code | |
1188 depend on split_external_path("") returning nil instead of an empty | |
1189 string? */ | |
1190 if (!newlen) | |
1191 return Qnil; | |
1192 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1193 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR, 0, 0); |
771 | 1194 } |
1195 | |
1196 Lisp_Object | |
867 | 1197 split_env_path (const CIbyte *evarname, const Ibyte *default_) |
771 | 1198 { |
867 | 1199 const Ibyte *path = 0; |
771 | 1200 if (evarname) |
1201 path = egetenv (evarname); | |
1202 if (!path) | |
1203 path = default_; | |
1204 if (!path) | |
1205 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
|
1206 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR, 0, 0); |
771 | 1207 } |
1208 | |
1209 /* Ben thinks this function should not exist or be exported to Lisp. | |
1210 We use it to define split-path-string in subr.el (not!). */ | |
1211 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1212 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 3, 0, /* |
771 | 1213 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
|
1214 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1215 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
|
1216 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
|
1217 will be necessary for a single ESCAPE-CHAR to appear in the output string. |
771 | 1218 */ |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1219 (string, sepchar, escape_char)) |
771 | 1220 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1221 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
|
1222 |
771 | 1223 CHECK_STRING (string); |
1224 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
|
1225 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
|
1226 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1227 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
|
1228 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
|
1229 } |
867 | 1230 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
|
1231 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
|
1232 XCHAR (sepchar), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1233 !NILP (escape_char), escape_ichar); |
771 | 1234 } |
1235 | |
1236 /* #### This was supposed to be in subr.el, but is used VERY early in | |
1237 the bootstrap process, so it goes here. Damn. */ | |
1238 | |
1239 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /* | |
1240 Explode a search path into a list of strings. | |
1241 The path components are separated with the characters specified | |
1242 with `path-separator'. | |
1243 */ | |
1244 (path)) | |
1245 { | |
1246 CHECK_STRING (path); | |
1247 | |
1248 while (!STRINGP (Vpath_separator) | |
826 | 1249 || (string_char_length (Vpath_separator) != 1)) |
771 | 1250 Vpath_separator = signal_continuable_error |
1251 (Qinvalid_state, | |
1252 "`path-separator' should be set to a single-character string", | |
1253 Vpath_separator); | |
1254 | |
867 | 1255 return (split_string_by_ichar_1 |
771 | 1256 (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
|
1257 itext_ichar (XSTRING_DATA (Vpath_separator)), 0, 0)); |
771 | 1258 } |
1259 | |
428 | 1260 |
1261 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* | |
1262 Take cdr N times on LIST, and return the result. | |
1263 */ | |
1264 (n, list)) | |
1265 { | |
1920 | 1266 /* This function can GC */ |
647 | 1267 REGISTER EMACS_INT i; |
428 | 1268 REGISTER Lisp_Object tail = list; |
1269 CHECK_NATNUM (n); | |
1270 for (i = XINT (n); i; i--) | |
1271 { | |
1272 if (CONSP (tail)) | |
1273 tail = XCDR (tail); | |
1274 else if (NILP (tail)) | |
1275 return Qnil; | |
1276 else | |
1277 { | |
1278 tail = wrong_type_argument (Qlistp, tail); | |
1279 i++; | |
1280 } | |
1281 } | |
1282 return tail; | |
1283 } | |
1284 | |
1285 DEFUN ("nth", Fnth, 2, 2, 0, /* | |
1286 Return the Nth element of LIST. | |
1287 N counts from zero. If LIST is not that long, nil is returned. | |
1288 */ | |
1289 (n, list)) | |
1290 { | |
1920 | 1291 /* This function can GC */ |
428 | 1292 return Fcar (Fnthcdr (n, list)); |
1293 } | |
1294 | |
1295 DEFUN ("elt", Felt, 2, 2, 0, /* | |
1296 Return element of SEQUENCE at index N. | |
1297 */ | |
1298 (sequence, n)) | |
1299 { | |
1920 | 1300 /* This function can GC */ |
428 | 1301 retry: |
1302 CHECK_INT_COERCE_CHAR (n); /* yuck! */ | |
1303 if (LISTP (sequence)) | |
1304 { | |
1305 Lisp_Object tem = Fnthcdr (n, sequence); | |
1306 /* #### Utterly, completely, fucking disgusting. | |
1307 * #### The whole point of "elt" is that it operates on | |
1308 * #### sequences, and does error- (bounds-) checking. | |
1309 */ | |
1310 if (CONSP (tem)) | |
1311 return XCAR (tem); | |
1312 else | |
1313 #if 1 | |
1314 /* This is The Way It Has Always Been. */ | |
1315 return Qnil; | |
1316 #else | |
1317 /* This is The Way Mly and Cltl2 say It Should Be. */ | |
1318 args_out_of_range (sequence, n); | |
1319 #endif | |
1320 } | |
1321 else if (STRINGP (sequence) || | |
1322 VECTORP (sequence) || | |
1323 BIT_VECTORP (sequence)) | |
1324 return Faref (sequence, n); | |
1325 #ifdef LOSING_BYTECODE | |
1326 else if (COMPILED_FUNCTIONP (sequence)) | |
1327 { | |
1328 EMACS_INT idx = XINT (n); | |
1329 if (idx < 0) | |
1330 { | |
1331 lose: | |
1332 args_out_of_range (sequence, n); | |
1333 } | |
1334 /* Utter perversity */ | |
1335 { | |
1336 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence); | |
1337 switch (idx) | |
1338 { | |
1339 case COMPILED_ARGLIST: | |
1340 return compiled_function_arglist (f); | |
1341 case COMPILED_INSTRUCTIONS: | |
1342 return compiled_function_instructions (f); | |
1343 case COMPILED_CONSTANTS: | |
1344 return compiled_function_constants (f); | |
1345 case COMPILED_STACK_DEPTH: | |
1346 return compiled_function_stack_depth (f); | |
1347 case COMPILED_DOC_STRING: | |
1348 return compiled_function_documentation (f); | |
1349 case COMPILED_DOMAIN: | |
1350 return compiled_function_domain (f); | |
1351 case COMPILED_INTERACTIVE: | |
1352 if (f->flags.interactivep) | |
1353 return compiled_function_interactive (f); | |
1354 /* if we return nil, can't tell interactive with no args | |
1355 from noninteractive. */ | |
1356 goto lose; | |
1357 default: | |
1358 goto lose; | |
1359 } | |
1360 } | |
1361 } | |
1362 #endif /* LOSING_BYTECODE */ | |
1363 else | |
1364 { | |
1365 check_losing_bytecode ("elt", sequence); | |
1366 sequence = wrong_type_argument (Qsequencep, sequence); | |
1367 goto retry; | |
1368 } | |
1369 } | |
1370 | |
1371 DEFUN ("last", Flast, 1, 2, 0, /* | |
1372 Return the tail of list LIST, of length N (default 1). | |
1373 LIST may be a dotted list, but not a circular list. | |
1374 Optional argument N must be a non-negative integer. | |
1375 If N is zero, then the atom that terminates the list is returned. | |
1376 If N is greater than the length of LIST, then LIST itself is returned. | |
1377 */ | |
1378 (list, n)) | |
1379 { | |
1380 EMACS_INT int_n, count; | |
1381 Lisp_Object retval, tortoise, hare; | |
1382 | |
1383 CHECK_LIST (list); | |
1384 | |
1385 if (NILP (n)) | |
1386 int_n = 1; | |
1387 else | |
1388 { | |
1389 CHECK_NATNUM (n); | |
1390 int_n = XINT (n); | |
1391 } | |
1392 | |
1393 for (retval = tortoise = hare = list, count = 0; | |
1394 CONSP (hare); | |
1395 hare = XCDR (hare), | |
1396 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0), | |
1397 count++) | |
1398 { | |
1399 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
1400 | |
1401 if (count & 1) | |
1402 tortoise = XCDR (tortoise); | |
1403 if (EQ (hare, tortoise)) | |
1404 signal_circular_list_error (list); | |
1405 } | |
1406 | |
1407 return retval; | |
1408 } | |
1409 | |
1410 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /* | |
1411 Modify LIST to remove the last N (default 1) elements. | |
1412 If LIST has N or fewer elements, nil is returned and LIST is unmodified. | |
1413 */ | |
1414 (list, n)) | |
1415 { | |
1416 EMACS_INT int_n; | |
1417 | |
1418 CHECK_LIST (list); | |
1419 | |
1420 if (NILP (n)) | |
1421 int_n = 1; | |
1422 else | |
1423 { | |
1424 CHECK_NATNUM (n); | |
1425 int_n = XINT (n); | |
1426 } | |
1427 | |
1428 { | |
1429 Lisp_Object last_cons = list; | |
1430 | |
1431 EXTERNAL_LIST_LOOP_1 (list) | |
1432 { | |
1433 if (int_n-- < 0) | |
1434 last_cons = XCDR (last_cons); | |
1435 } | |
1436 | |
1437 if (int_n >= 0) | |
1438 return Qnil; | |
1439 | |
1440 XCDR (last_cons) = Qnil; | |
1441 return list; | |
1442 } | |
1443 } | |
1444 | |
1445 DEFUN ("butlast", Fbutlast, 1, 2, 0, /* | |
1446 Return a copy of LIST with the last N (default 1) elements removed. | |
1447 If LIST has N or fewer elements, nil is returned. | |
1448 */ | |
1449 (list, n)) | |
1450 { | |
444 | 1451 EMACS_INT int_n; |
428 | 1452 |
1453 CHECK_LIST (list); | |
1454 | |
1455 if (NILP (n)) | |
1456 int_n = 1; | |
1457 else | |
1458 { | |
1459 CHECK_NATNUM (n); | |
1460 int_n = XINT (n); | |
1461 } | |
1462 | |
1463 { | |
1464 Lisp_Object retval = Qnil; | |
1465 Lisp_Object tail = list; | |
1466 | |
1467 EXTERNAL_LIST_LOOP_1 (list) | |
1468 { | |
1469 if (--int_n < 0) | |
1470 { | |
1471 retval = Fcons (XCAR (tail), retval); | |
1472 tail = XCDR (tail); | |
1473 } | |
1474 } | |
1475 | |
1476 return Fnreverse (retval); | |
1477 } | |
1478 } | |
1479 | |
1480 DEFUN ("member", Fmember, 2, 2, 0, /* | |
1481 Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | |
1482 The value is actually the tail of LIST whose car is ELT. | |
1483 */ | |
1484 (elt, list)) | |
1485 { | |
1486 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1487 { | |
1488 if (internal_equal (elt, list_elt, 0)) | |
1489 return tail; | |
1490 } | |
1491 return Qnil; | |
1492 } | |
1493 | |
1494 DEFUN ("old-member", Fold_member, 2, 2, 0, /* | |
1495 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'. | |
1496 The value is actually the tail of LIST whose car is ELT. | |
1497 This function is provided only for byte-code compatibility with v19. | |
1498 Do not use it. | |
1499 */ | |
1500 (elt, list)) | |
1501 { | |
1502 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1503 { | |
1504 if (internal_old_equal (elt, list_elt, 0)) | |
1505 return tail; | |
1506 } | |
1507 return Qnil; | |
1508 } | |
1509 | |
1510 DEFUN ("memq", Fmemq, 2, 2, 0, /* | |
1511 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. | |
1512 The value is actually the tail of LIST whose car is ELT. | |
1513 */ | |
1514 (elt, list)) | |
1515 { | |
1516 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1517 { | |
1518 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1519 return tail; | |
1520 } | |
1521 return Qnil; | |
1522 } | |
1523 | |
1524 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /* | |
1525 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'. | |
1526 The value is actually the tail of LIST whose car is ELT. | |
1527 This function is provided only for byte-code compatibility with v19. | |
1528 Do not use it. | |
1529 */ | |
1530 (elt, list)) | |
1531 { | |
1532 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1533 { | |
1534 if (HACKEQ_UNSAFE (elt, list_elt)) | |
1535 return tail; | |
1536 } | |
1537 return Qnil; | |
1538 } | |
1539 | |
1540 Lisp_Object | |
1541 memq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1542 { | |
1543 LIST_LOOP_3 (list_elt, list, tail) | |
1544 { | |
1545 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1546 return tail; | |
1547 } | |
1548 return Qnil; | |
1549 } | |
1550 | |
1551 DEFUN ("assoc", Fassoc, 2, 2, 0, /* | |
444 | 1552 Return non-nil if KEY is `equal' to the car of an element of ALIST. |
1553 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1554 */ |
444 | 1555 (key, alist)) |
428 | 1556 { |
1557 /* This function can GC. */ | |
444 | 1558 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1559 { |
1560 if (internal_equal (key, elt_car, 0)) | |
1561 return elt; | |
1562 } | |
1563 return Qnil; | |
1564 } | |
1565 | |
1566 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /* | |
444 | 1567 Return non-nil if KEY is `old-equal' to the car of an element of ALIST. |
1568 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1569 */ |
444 | 1570 (key, alist)) |
428 | 1571 { |
1572 /* This function can GC. */ | |
444 | 1573 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1574 { |
1575 if (internal_old_equal (key, elt_car, 0)) | |
1576 return elt; | |
1577 } | |
1578 return Qnil; | |
1579 } | |
1580 | |
1581 Lisp_Object | |
444 | 1582 assoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1583 { |
1584 int speccount = specpdl_depth (); | |
1585 specbind (Qinhibit_quit, Qt); | |
771 | 1586 return unbind_to_1 (speccount, Fassoc (key, alist)); |
428 | 1587 } |
1588 | |
1589 DEFUN ("assq", Fassq, 2, 2, 0, /* | |
444 | 1590 Return non-nil if KEY is `eq' to the car of an element of ALIST. |
1591 The value is actually the element of ALIST whose car is KEY. | |
1592 Elements of ALIST that are not conses are ignored. | |
428 | 1593 */ |
444 | 1594 (key, alist)) |
428 | 1595 { |
444 | 1596 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1597 { |
1598 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1599 return elt; | |
1600 } | |
1601 return Qnil; | |
1602 } | |
1603 | |
1604 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /* | |
444 | 1605 Return non-nil if KEY is `old-eq' to the car of an element of ALIST. |
1606 The value is actually the element of ALIST whose car is KEY. | |
1607 Elements of ALIST that are not conses are ignored. | |
428 | 1608 This function is provided only for byte-code compatibility with v19. |
1609 Do not use it. | |
1610 */ | |
444 | 1611 (key, alist)) |
428 | 1612 { |
444 | 1613 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1614 { |
1615 if (HACKEQ_UNSAFE (key, elt_car)) | |
1616 return elt; | |
1617 } | |
1618 return Qnil; | |
1619 } | |
1620 | |
1621 /* Like Fassq but never report an error and do not allow quits. | |
1622 Use only on lists known never to be circular. */ | |
1623 | |
1624 Lisp_Object | |
444 | 1625 assq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1626 { |
1627 /* This cannot GC. */ | |
444 | 1628 LIST_LOOP_2 (elt, alist) |
428 | 1629 { |
1630 Lisp_Object elt_car = XCAR (elt); | |
1631 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1632 return elt; | |
1633 } | |
1634 return Qnil; | |
1635 } | |
1636 | |
1637 DEFUN ("rassoc", Frassoc, 2, 2, 0, /* | |
444 | 1638 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST. |
1639 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1640 */ |
444 | 1641 (value, alist)) |
428 | 1642 { |
444 | 1643 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1644 { |
444 | 1645 if (internal_equal (value, elt_cdr, 0)) |
428 | 1646 return elt; |
1647 } | |
1648 return Qnil; | |
1649 } | |
1650 | |
1651 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /* | |
444 | 1652 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST. |
1653 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1654 */ |
444 | 1655 (value, alist)) |
428 | 1656 { |
444 | 1657 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1658 { |
444 | 1659 if (internal_old_equal (value, elt_cdr, 0)) |
428 | 1660 return elt; |
1661 } | |
1662 return Qnil; | |
1663 } | |
1664 | |
1665 DEFUN ("rassq", Frassq, 2, 2, 0, /* | |
444 | 1666 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST. |
1667 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1668 */ |
444 | 1669 (value, alist)) |
428 | 1670 { |
444 | 1671 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1672 { |
444 | 1673 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1674 return elt; |
1675 } | |
1676 return Qnil; | |
1677 } | |
1678 | |
1679 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /* | |
444 | 1680 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST. |
1681 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1682 */ |
444 | 1683 (value, alist)) |
428 | 1684 { |
444 | 1685 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1686 { |
444 | 1687 if (HACKEQ_UNSAFE (value, elt_cdr)) |
428 | 1688 return elt; |
1689 } | |
1690 return Qnil; | |
1691 } | |
1692 | |
444 | 1693 /* Like Frassq, but caller must ensure that ALIST is properly |
428 | 1694 nil-terminated and ebola-free. */ |
1695 Lisp_Object | |
444 | 1696 rassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1697 { |
444 | 1698 LIST_LOOP_2 (elt, alist) |
428 | 1699 { |
1700 Lisp_Object elt_cdr = XCDR (elt); | |
444 | 1701 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1702 return elt; |
1703 } | |
1704 return Qnil; | |
1705 } | |
1706 | |
1707 | |
1708 DEFUN ("delete", Fdelete, 2, 2, 0, /* | |
1709 Delete by side effect any occurrences of ELT as a member of LIST. | |
1710 The modified LIST is returned. Comparison is done with `equal'. | |
1711 If the first member of LIST is ELT, there is no way to remove it by side | |
1712 effect; therefore, write `(setq foo (delete element foo))' to be sure | |
1713 of changing the value of `foo'. | |
1714 Also see: `remove'. | |
1715 */ | |
1716 (elt, list)) | |
1717 { | |
1718 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1719 (internal_equal (elt, list_elt, 0))); | |
1720 return list; | |
1721 } | |
1722 | |
1723 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /* | |
1724 Delete by side effect any occurrences of ELT as a member of LIST. | |
1725 The modified LIST is returned. Comparison is done with `old-equal'. | |
1726 If the first member of LIST is ELT, there is no way to remove it by side | |
1727 effect; therefore, write `(setq foo (old-delete element foo))' to be sure | |
1728 of changing the value of `foo'. | |
1729 */ | |
1730 (elt, list)) | |
1731 { | |
1732 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1733 (internal_old_equal (elt, list_elt, 0))); | |
1734 return list; | |
1735 } | |
1736 | |
1737 DEFUN ("delq", Fdelq, 2, 2, 0, /* | |
1738 Delete by side effect any occurrences of ELT as a member of LIST. | |
1739 The modified LIST is returned. Comparison is done with `eq'. | |
1740 If the first member of LIST is ELT, there is no way to remove it by side | |
1741 effect; therefore, write `(setq foo (delq element foo))' to be sure of | |
1742 changing the value of `foo'. | |
1743 */ | |
1744 (elt, list)) | |
1745 { | |
1746 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1747 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1748 return list; | |
1749 } | |
1750 | |
1751 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /* | |
1752 Delete by side effect any occurrences of ELT as a member of LIST. | |
1753 The modified LIST is returned. Comparison is done with `old-eq'. | |
1754 If the first member of LIST is ELT, there is no way to remove it by side | |
1755 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of | |
1756 changing the value of `foo'. | |
1757 */ | |
1758 (elt, list)) | |
1759 { | |
1760 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1761 (HACKEQ_UNSAFE (elt, list_elt))); | |
1762 return list; | |
1763 } | |
1764 | |
1765 /* Like Fdelq, but caller must ensure that LIST is properly | |
1766 nil-terminated and ebola-free. */ | |
1767 | |
1768 Lisp_Object | |
1769 delq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1770 { | |
1771 LIST_LOOP_DELETE_IF (list_elt, list, | |
1772 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1773 return list; | |
1774 } | |
1775 | |
1776 /* Be VERY careful with this. This is like delq_no_quit() but | |
1777 also calls free_cons() on the removed conses. You must be SURE | |
1778 that no pointers to the freed conses remain around (e.g. | |
1779 someone else is pointing to part of the list). This function | |
1780 is useful on internal lists that are used frequently and where | |
1781 the actual list doesn't escape beyond known code bounds. */ | |
1782 | |
1783 Lisp_Object | |
1784 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list) | |
1785 { | |
1786 REGISTER Lisp_Object tail = list; | |
1787 REGISTER Lisp_Object prev = Qnil; | |
1788 | |
1789 while (!NILP (tail)) | |
1790 { | |
1791 REGISTER Lisp_Object tem = XCAR (tail); | |
1792 if (EQ (elt, tem)) | |
1793 { | |
1794 Lisp_Object cons_to_free = tail; | |
1795 if (NILP (prev)) | |
1796 list = XCDR (tail); | |
1797 else | |
1798 XCDR (prev) = XCDR (tail); | |
1799 tail = XCDR (tail); | |
853 | 1800 free_cons (cons_to_free); |
428 | 1801 } |
1802 else | |
1803 { | |
1804 prev = tail; | |
1805 tail = XCDR (tail); | |
1806 } | |
1807 } | |
1808 return list; | |
1809 } | |
1810 | |
1811 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /* | |
444 | 1812 Delete by side effect any elements of ALIST whose car is `equal' to KEY. |
1813 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1814 that is `equal' to KEY, there is no way to remove it by side effect; |
1815 therefore, write `(setq foo (remassoc key foo))' to be sure of changing | |
1816 the value of `foo'. | |
1817 */ | |
444 | 1818 (key, alist)) |
428 | 1819 { |
444 | 1820 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1821 (CONSP (elt) && |
1822 internal_equal (key, XCAR (elt), 0))); | |
444 | 1823 return alist; |
428 | 1824 } |
1825 | |
1826 Lisp_Object | |
444 | 1827 remassoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1828 { |
1829 int speccount = specpdl_depth (); | |
1830 specbind (Qinhibit_quit, Qt); | |
771 | 1831 return unbind_to_1 (speccount, Fremassoc (key, alist)); |
428 | 1832 } |
1833 | |
1834 DEFUN ("remassq", Fremassq, 2, 2, 0, /* | |
444 | 1835 Delete by side effect any elements of ALIST whose car is `eq' to KEY. |
1836 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1837 that is `eq' to KEY, there is no way to remove it by side effect; |
1838 therefore, write `(setq foo (remassq key foo))' to be sure of changing | |
1839 the value of `foo'. | |
1840 */ | |
444 | 1841 (key, alist)) |
428 | 1842 { |
444 | 1843 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1844 (CONSP (elt) && |
1845 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1846 return alist; |
428 | 1847 } |
1848 | |
1849 /* no quit, no errors; be careful */ | |
1850 | |
1851 Lisp_Object | |
444 | 1852 remassq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1853 { |
444 | 1854 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1855 (CONSP (elt) && |
1856 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1857 return alist; |
428 | 1858 } |
1859 | |
1860 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /* | |
444 | 1861 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE. |
1862 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1863 that is `equal' to VALUE, there is no way to remove it by side effect; |
1864 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing | |
1865 the value of `foo'. | |
1866 */ | |
444 | 1867 (value, alist)) |
428 | 1868 { |
444 | 1869 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1870 (CONSP (elt) && |
1871 internal_equal (value, XCDR (elt), 0))); | |
444 | 1872 return alist; |
428 | 1873 } |
1874 | |
1875 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /* | |
444 | 1876 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE. |
1877 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1878 that is `eq' to VALUE, there is no way to remove it by side effect; |
1879 therefore, write `(setq foo (remrassq value foo))' to be sure of changing | |
1880 the value of `foo'. | |
1881 */ | |
444 | 1882 (value, alist)) |
428 | 1883 { |
444 | 1884 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1885 (CONSP (elt) && |
1886 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1887 return alist; |
428 | 1888 } |
1889 | |
1890 /* Like Fremrassq, fast and unsafe; be careful */ | |
1891 Lisp_Object | |
444 | 1892 remrassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1893 { |
444 | 1894 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 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /* | |
1901 Reverse LIST by destructively modifying cdr pointers. | |
1902 Return the beginning of the reversed list. | |
1903 Also see: `reverse'. | |
1904 */ | |
1905 (list)) | |
1906 { | |
1907 struct gcpro gcpro1, gcpro2; | |
1849 | 1908 Lisp_Object prev = Qnil; |
1909 Lisp_Object tail = list; | |
428 | 1910 |
1911 /* We gcpro our args; see `nconc' */ | |
1912 GCPRO2 (prev, tail); | |
1913 while (!NILP (tail)) | |
1914 { | |
1915 REGISTER Lisp_Object next; | |
1916 CONCHECK_CONS (tail); | |
1917 next = XCDR (tail); | |
1918 XCDR (tail) = prev; | |
1919 prev = tail; | |
1920 tail = next; | |
1921 } | |
1922 UNGCPRO; | |
1923 return prev; | |
1924 } | |
1925 | |
1926 DEFUN ("reverse", Freverse, 1, 1, 0, /* | |
1927 Reverse LIST, copying. Return the beginning of the reversed list. | |
1928 See also the function `nreverse', which is used more often. | |
1929 */ | |
1930 (list)) | |
1931 { | |
1932 Lisp_Object reversed_list = Qnil; | |
1933 EXTERNAL_LIST_LOOP_2 (elt, list) | |
1934 { | |
1935 reversed_list = Fcons (elt, reversed_list); | |
1936 } | |
1937 return reversed_list; | |
1938 } | |
1939 | |
1940 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
1941 Lisp_Object lisp_arg, | |
1942 int (*pred_fn) (Lisp_Object, Lisp_Object, | |
1943 Lisp_Object lisp_arg)); | |
1944 | |
872 | 1945 /* The sort function should return > 0 if OBJ1 < OBJ2, < 0 otherwise. |
1946 NOTE: This is backwards from the way qsort() works. */ | |
1947 | |
428 | 1948 Lisp_Object |
1949 list_sort (Lisp_Object list, | |
1950 Lisp_Object lisp_arg, | |
872 | 1951 int (*pred_fn) (Lisp_Object obj1, Lisp_Object obj2, |
428 | 1952 Lisp_Object lisp_arg)) |
1953 { | |
1954 struct gcpro gcpro1, gcpro2, gcpro3; | |
1955 Lisp_Object back, tem; | |
1956 Lisp_Object front = list; | |
1957 Lisp_Object len = Flength (list); | |
444 | 1958 |
1959 if (XINT (len) < 2) | |
428 | 1960 return list; |
1961 | |
444 | 1962 len = make_int (XINT (len) / 2 - 1); |
428 | 1963 tem = Fnthcdr (len, list); |
1964 back = Fcdr (tem); | |
1965 Fsetcdr (tem, Qnil); | |
1966 | |
1967 GCPRO3 (front, back, lisp_arg); | |
1968 front = list_sort (front, lisp_arg, pred_fn); | |
1969 back = list_sort (back, lisp_arg, pred_fn); | |
1970 UNGCPRO; | |
1971 return list_merge (front, back, lisp_arg, pred_fn); | |
1972 } | |
1973 | |
1974 | |
1975 static int | |
1976 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2, | |
1977 Lisp_Object pred) | |
1978 { | |
1979 Lisp_Object tmp; | |
1980 | |
1981 /* prevents the GC from happening in call2 */ | |
853 | 1982 /* Emacs' GC doesn't actually relocate pointers, so this probably |
1983 isn't strictly necessary */ | |
771 | 1984 int speccount = begin_gc_forbidden (); |
428 | 1985 tmp = call2 (pred, obj1, obj2); |
771 | 1986 unbind_to (speccount); |
428 | 1987 |
1988 if (NILP (tmp)) | |
1989 return -1; | |
1990 else | |
1991 return 1; | |
1992 } | |
1993 | |
1994 DEFUN ("sort", Fsort, 2, 2, 0, /* | |
1995 Sort LIST, stably, comparing elements using PREDICATE. | |
1996 Returns the sorted list. LIST is modified by side effects. | |
1997 PREDICATE is called with two elements of LIST, and should return T | |
1998 if the first element is "less" than the second. | |
1999 */ | |
444 | 2000 (list, predicate)) |
428 | 2001 { |
444 | 2002 return list_sort (list, predicate, merge_pred_function); |
428 | 2003 } |
2004 | |
2005 Lisp_Object | |
2006 merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
2007 Lisp_Object pred) | |
2008 { | |
2009 return list_merge (org_l1, org_l2, pred, merge_pred_function); | |
2010 } | |
2011 | |
2012 | |
2013 static Lisp_Object | |
2014 list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
2015 Lisp_Object lisp_arg, | |
2016 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg)) | |
2017 { | |
2018 Lisp_Object value; | |
2019 Lisp_Object tail; | |
2020 Lisp_Object tem; | |
2021 Lisp_Object l1, l2; | |
2022 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
2023 | |
2024 l1 = org_l1; | |
2025 l2 = org_l2; | |
2026 tail = Qnil; | |
2027 value = Qnil; | |
2028 | |
2029 /* It is sufficient to protect org_l1 and org_l2. | |
2030 When l1 and l2 are updated, we copy the new values | |
2031 back into the org_ vars. */ | |
2032 | |
2033 GCPRO4 (org_l1, org_l2, lisp_arg, value); | |
2034 | |
2035 while (1) | |
2036 { | |
2037 if (NILP (l1)) | |
2038 { | |
2039 UNGCPRO; | |
2040 if (NILP (tail)) | |
2041 return l2; | |
2042 Fsetcdr (tail, l2); | |
2043 return value; | |
2044 } | |
2045 if (NILP (l2)) | |
2046 { | |
2047 UNGCPRO; | |
2048 if (NILP (tail)) | |
2049 return l1; | |
2050 Fsetcdr (tail, l1); | |
2051 return value; | |
2052 } | |
2053 | |
2054 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0) | |
2055 { | |
2056 tem = l1; | |
2057 l1 = Fcdr (l1); | |
2058 org_l1 = l1; | |
2059 } | |
2060 else | |
2061 { | |
2062 tem = l2; | |
2063 l2 = Fcdr (l2); | |
2064 org_l2 = l2; | |
2065 } | |
2066 if (NILP (tail)) | |
2067 value = tem; | |
2068 else | |
2069 Fsetcdr (tail, tem); | |
2070 tail = tem; | |
2071 } | |
2072 } | |
2073 | |
2074 | |
2075 /************************************************************************/ | |
2076 /* property-list functions */ | |
2077 /************************************************************************/ | |
2078 | |
2079 /* For properties of text, we need to do order-insensitive comparison of | |
2080 plists. That is, we need to compare two plists such that they are the | |
2081 same if they have the same set of keys, and equivalent values. | |
2082 So (a 1 b 2) would be equal to (b 2 a 1). | |
2083 | |
2084 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc. | |
2085 LAXP means use `equal' for comparisons. | |
2086 */ | |
2087 int | |
2088 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
|
2089 int laxp, int depth, int foldcase) |
428 | 2090 { |
438 | 2091 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */ |
428 | 2092 int la, lb, m, i, fill; |
2093 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
|
2094 Boolbyte *flags; |
428 | 2095 Lisp_Object rest; |
2096 | |
2097 if (NILP (a) && NILP (b)) | |
2098 return 0; | |
2099 | |
2100 Fcheck_valid_plist (a); | |
2101 Fcheck_valid_plist (b); | |
2102 | |
2103 la = XINT (Flength (a)); | |
2104 lb = XINT (Flength (b)); | |
2105 m = (la > lb ? la : lb); | |
2106 fill = 0; | |
2107 keys = alloca_array (Lisp_Object, m); | |
2108 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
|
2109 flags = alloca_array (Boolbyte, m); |
428 | 2110 |
2111 /* First extract the pairs from A. */ | |
2112 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2113 { | |
2114 Lisp_Object k = XCAR (rest); | |
2115 Lisp_Object v = XCAR (XCDR (rest)); | |
2116 /* Maybe be Ebolified. */ | |
2117 if (nil_means_not_present && NILP (v)) continue; | |
2118 keys [fill] = k; | |
2119 vals [fill] = v; | |
2120 flags[fill] = 0; | |
2121 fill++; | |
2122 } | |
2123 /* Now iterate over B, and stop if we find something that's not in A, | |
2124 or that doesn't match. As we match, mark them. */ | |
2125 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2126 { | |
2127 Lisp_Object k = XCAR (rest); | |
2128 Lisp_Object v = XCAR (XCDR (rest)); | |
2129 /* Maybe be Ebolified. */ | |
2130 if (nil_means_not_present && NILP (v)) continue; | |
2131 for (i = 0; i < fill; i++) | |
2132 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2133 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
|
2134 internal_equal_0 (k, keys [i], depth, foldcase)) |
428 | 2135 { |
434 | 2136 if (eqp |
2137 /* We narrowly escaped being Ebolified here. */ | |
2138 ? !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
|
2139 : !internal_equal_0 (v, vals [i], depth, foldcase)) |
428 | 2140 /* a property in B has a different value than in A */ |
2141 goto MISMATCH; | |
2142 flags [i] = 1; | |
2143 break; | |
2144 } | |
2145 } | |
2146 if (i == fill) | |
2147 /* there are some properties in B that are not in A */ | |
2148 goto MISMATCH; | |
2149 } | |
2150 /* Now check to see that all the properties in A were also in B */ | |
2151 for (i = 0; i < fill; i++) | |
2152 if (flags [i] == 0) | |
2153 goto MISMATCH; | |
2154 | |
2155 /* Ok. */ | |
2156 return 0; | |
2157 | |
2158 MISMATCH: | |
2159 return 1; | |
2160 } | |
2161 | |
2162 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /* | |
2163 Return non-nil if property lists A and B are `eq'. | |
2164 A property list is an alternating list of keywords and values. | |
2165 This function does order-insensitive comparisons of the property lists: | |
2166 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2167 Comparison between values is done using `eq'. See also `plists-equal'. | |
2168 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2169 a nil value is ignored. This feature is a virus that has infected | |
2170 old Lisp implementations, but should not be used except for backward | |
2171 compatibility. | |
2172 */ | |
2173 (a, b, nil_means_not_present)) | |
2174 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2175 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1, 0) |
428 | 2176 ? Qnil : Qt); |
2177 } | |
2178 | |
2179 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /* | |
2180 Return non-nil if property lists A and B are `equal'. | |
2181 A property list is an alternating list of keywords and values. This | |
2182 function does order-insensitive comparisons of the property lists: For | |
2183 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2184 Comparison between values is done using `equal'. See also `plists-eq'. | |
2185 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2186 a nil value is ignored. This feature is a virus that has infected | |
2187 old Lisp implementations, but should not be used except for backward | |
2188 compatibility. | |
2189 */ | |
2190 (a, b, nil_means_not_present)) | |
2191 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2192 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1, 0) |
428 | 2193 ? Qnil : Qt); |
2194 } | |
2195 | |
2196 | |
2197 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /* | |
2198 Return non-nil if lax property lists A and B are `eq'. | |
2199 A property list is an alternating list of keywords and values. | |
2200 This function does order-insensitive comparisons of the property lists: | |
2201 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2202 Comparison between values is done using `eq'. See also `plists-equal'. | |
2203 A lax property list is like a regular one except that comparisons between | |
2204 keywords is done using `equal' instead of `eq'. | |
2205 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2206 a nil value is ignored. This feature is a virus that has infected | |
2207 old Lisp implementations, but should not be used except for backward | |
2208 compatibility. | |
2209 */ | |
2210 (a, b, nil_means_not_present)) | |
2211 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2212 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1, 0) |
428 | 2213 ? Qnil : Qt); |
2214 } | |
2215 | |
2216 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /* | |
2217 Return non-nil if lax property lists A and B are `equal'. | |
2218 A property list is an alternating list of keywords and values. This | |
2219 function does order-insensitive comparisons of the property lists: For | |
2220 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2221 Comparison between values is done using `equal'. See also `plists-eq'. | |
2222 A lax property list is like a regular one except that comparisons between | |
2223 keywords is done using `equal' instead of `eq'. | |
2224 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2225 a nil value is ignored. This feature is a virus that has infected | |
2226 old Lisp implementations, but should not be used except for backward | |
2227 compatibility. | |
2228 */ | |
2229 (a, b, nil_means_not_present)) | |
2230 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2231 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1, 0) |
428 | 2232 ? Qnil : Qt); |
2233 } | |
2234 | |
2235 /* Return the value associated with key PROPERTY in property list PLIST. | |
2236 Return nil if key not found. This function is used for internal | |
2237 property lists that cannot be directly manipulated by the user. | |
2238 */ | |
2239 | |
2240 Lisp_Object | |
2241 internal_plist_get (Lisp_Object plist, Lisp_Object property) | |
2242 { | |
2243 Lisp_Object tail; | |
2244 | |
2245 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2246 { | |
2247 if (EQ (XCAR (tail), property)) | |
2248 return XCAR (XCDR (tail)); | |
2249 } | |
2250 | |
2251 return Qunbound; | |
2252 } | |
2253 | |
2254 /* Set PLIST's value for PROPERTY to VALUE. Analogous to | |
2255 internal_plist_get(). */ | |
2256 | |
2257 void | |
2258 internal_plist_put (Lisp_Object *plist, Lisp_Object property, | |
2259 Lisp_Object value) | |
2260 { | |
2261 Lisp_Object tail; | |
2262 | |
2263 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2264 { | |
2265 if (EQ (XCAR (tail), property)) | |
2266 { | |
2267 XCAR (XCDR (tail)) = value; | |
2268 return; | |
2269 } | |
2270 } | |
2271 | |
2272 *plist = Fcons (property, Fcons (value, *plist)); | |
2273 } | |
2274 | |
2275 int | |
2276 internal_remprop (Lisp_Object *plist, Lisp_Object property) | |
2277 { | |
2278 Lisp_Object tail, prev; | |
2279 | |
2280 for (tail = *plist, prev = Qnil; | |
2281 !NILP (tail); | |
2282 tail = XCDR (XCDR (tail))) | |
2283 { | |
2284 if (EQ (XCAR (tail), property)) | |
2285 { | |
2286 if (NILP (prev)) | |
2287 *plist = XCDR (XCDR (tail)); | |
2288 else | |
2289 XCDR (XCDR (prev)) = XCDR (XCDR (tail)); | |
2290 return 1; | |
2291 } | |
2292 else | |
2293 prev = tail; | |
2294 } | |
2295 | |
2296 return 0; | |
2297 } | |
2298 | |
2299 /* Called on a malformed property list. BADPLACE should be some | |
2300 place where truncating will form a good list -- i.e. we shouldn't | |
2301 result in a list with an odd length. */ | |
2302 | |
2303 static Lisp_Object | |
578 | 2304 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2305 { |
2306 if (ERRB_EQ (errb, ERROR_ME)) | |
2307 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace)); | |
2308 else | |
2309 { | |
2310 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2311 { | |
2312 warn_when_safe_lispobj | |
2313 (Qlist, Qwarning, | |
771 | 2314 list2 (build_msg_string |
428 | 2315 ("Malformed property list -- list has been truncated"), |
2316 *plist)); | |
793 | 2317 /* #### WARNING: This is more dangerous than it seems; perhaps |
2318 not a good idea. It also violates the principle of least | |
2319 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2320 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2321 *badplace = Qnil; |
2322 } | |
2323 return Qunbound; | |
2324 } | |
2325 } | |
2326 | |
2327 /* Called on a circular property list. BADPLACE should be some place | |
2328 where truncating will result in an even-length list, as above. | |
2329 If doesn't particularly matter where we truncate -- anywhere we | |
2330 truncate along the entire list will break the circularity, because | |
2331 it will create a terminus and the list currently doesn't have one. | |
2332 */ | |
2333 | |
2334 static Lisp_Object | |
578 | 2335 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2336 { |
2337 if (ERRB_EQ (errb, ERROR_ME)) | |
2338 return Fsignal (Qcircular_property_list, list1 (*plist)); | |
2339 else | |
2340 { | |
2341 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2342 { | |
2343 warn_when_safe_lispobj | |
2344 (Qlist, Qwarning, | |
771 | 2345 list2 (build_msg_string |
428 | 2346 ("Circular property list -- list has been truncated"), |
2347 *plist)); | |
793 | 2348 /* #### WARNING: This is more dangerous than it seems; perhaps |
2349 not a good idea. It also violates the principle of least | |
2350 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2351 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2352 *badplace = Qnil; |
2353 } | |
2354 return Qunbound; | |
2355 } | |
2356 } | |
2357 | |
2358 /* Advance the tortoise pointer by two (one iteration of a property-list | |
2359 loop) and the hare pointer by four and verify that no malformations | |
2360 or circularities exist. If so, return zero and store a value into | |
2361 RETVAL that should be returned by the calling function. Otherwise, | |
2362 return 1. See external_plist_get(). | |
2363 */ | |
2364 | |
2365 static int | |
2366 advance_plist_pointers (Lisp_Object *plist, | |
2367 Lisp_Object **tortoise, Lisp_Object **hare, | |
578 | 2368 Error_Behavior errb, Lisp_Object *retval) |
428 | 2369 { |
2370 int i; | |
2371 Lisp_Object *tortsave = *tortoise; | |
2372 | |
2373 /* Note that our "fixing" may be more brutal than necessary, | |
2374 but it's the user's own problem, not ours, if they went in and | |
2375 manually fucked up a plist. */ | |
2376 | |
2377 for (i = 0; i < 2; i++) | |
2378 { | |
2379 /* This is a standard iteration of a defensive-loop-checking | |
2380 loop. We just do it twice because we want to advance past | |
2381 both the property and its value. | |
2382 | |
2383 If the pointer indirection is confusing you, remember that | |
2384 one level of indirection on the hare and tortoise pointers | |
2385 is only due to pass-by-reference for this function. The other | |
2386 level is so that the plist can be fixed in place. */ | |
2387 | |
2388 /* When we reach the end of a well-formed plist, **HARE is | |
2389 nil. In that case, we don't do anything at all except | |
2390 advance TORTOISE by one. Otherwise, we advance HARE | |
2391 by two (making sure it's OK to do so), then advance | |
2392 TORTOISE by one (it will always be OK to do so because | |
2393 the HARE is always ahead of the TORTOISE and will have | |
2394 already verified the path), then make sure TORTOISE and | |
2395 HARE don't contain the same non-nil object -- if the | |
2396 TORTOISE and the HARE ever meet, then obviously we're | |
2397 in a circularity, and if we're in a circularity, then | |
2398 the TORTOISE and the HARE can't cross paths without | |
2399 meeting, since the HARE only gains one step over the | |
2400 TORTOISE per iteration. */ | |
2401 | |
2402 if (!NILP (**hare)) | |
2403 { | |
2404 Lisp_Object *haresave = *hare; | |
2405 if (!CONSP (**hare)) | |
2406 { | |
2407 *retval = bad_bad_bunny (plist, haresave, errb); | |
2408 return 0; | |
2409 } | |
2410 *hare = &XCDR (**hare); | |
2411 /* In a non-plist, we'd check here for a nil value for | |
2412 **HARE, which is OK (it just means the list has an | |
2413 odd number of elements). In a plist, it's not OK | |
2414 for the list to have an odd number of elements. */ | |
2415 if (!CONSP (**hare)) | |
2416 { | |
2417 *retval = bad_bad_bunny (plist, haresave, errb); | |
2418 return 0; | |
2419 } | |
2420 *hare = &XCDR (**hare); | |
2421 } | |
2422 | |
2423 *tortoise = &XCDR (**tortoise); | |
2424 if (!NILP (**hare) && EQ (**tortoise, **hare)) | |
2425 { | |
2426 *retval = bad_bad_turtle (plist, tortsave, errb); | |
2427 return 0; | |
2428 } | |
2429 } | |
2430 | |
2431 return 1; | |
2432 } | |
2433 | |
2434 /* Return the value of PROPERTY from PLIST, or Qunbound if | |
2435 property is not on the list. | |
2436 | |
2437 PLIST is a Lisp-accessible property list, meaning that it | |
2438 has to be checked for malformations and circularities. | |
2439 | |
2440 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the | |
2441 function will never signal an error; and if ERRB is ERROR_ME_WARN, | |
2442 on finding a malformation or a circularity, it issues a warning and | |
2443 attempts to silently fix the problem. | |
2444 | |
2445 A pointer to PLIST is passed in so that PLIST can be successfully | |
2446 "fixed" even if the error is at the beginning of the plist. */ | |
2447 | |
2448 Lisp_Object | |
2449 external_plist_get (Lisp_Object *plist, Lisp_Object property, | |
578 | 2450 int laxp, Error_Behavior errb) |
428 | 2451 { |
2452 Lisp_Object *tortoise = plist; | |
2453 Lisp_Object *hare = plist; | |
2454 | |
2455 while (!NILP (*tortoise)) | |
2456 { | |
2457 Lisp_Object *tortsave = tortoise; | |
2458 Lisp_Object retval; | |
2459 | |
2460 /* We do the standard tortoise/hare march. We isolate the | |
2461 grungy stuff to do this in advance_plist_pointers(), though. | |
2462 To us, all this function does is advance the tortoise | |
2463 pointer by two and the hare pointer by four and make sure | |
2464 everything's OK. We first advance the pointers and then | |
2465 check if a property matched; this ensures that our | |
2466 check for a matching property is safe. */ | |
2467 | |
2468 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2469 return retval; | |
2470 | |
2471 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2472 : internal_equal (XCAR (*tortsave), property, 0)) | |
2473 return XCAR (XCDR (*tortsave)); | |
2474 } | |
2475 | |
2476 return Qunbound; | |
2477 } | |
2478 | |
2479 /* Set PLIST's value for PROPERTY to VALUE, given a possibly | |
2480 malformed or circular plist. Analogous to external_plist_get(). */ | |
2481 | |
2482 void | |
2483 external_plist_put (Lisp_Object *plist, Lisp_Object property, | |
578 | 2484 Lisp_Object value, int laxp, Error_Behavior errb) |
428 | 2485 { |
2486 Lisp_Object *tortoise = plist; | |
2487 Lisp_Object *hare = plist; | |
2488 | |
2489 while (!NILP (*tortoise)) | |
2490 { | |
2491 Lisp_Object *tortsave = tortoise; | |
2492 Lisp_Object retval; | |
2493 | |
2494 /* See above */ | |
2495 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2496 return; | |
2497 | |
2498 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2499 : internal_equal (XCAR (*tortsave), property, 0)) | |
2500 { | |
2501 XCAR (XCDR (*tortsave)) = value; | |
2502 return; | |
2503 } | |
2504 } | |
2505 | |
2506 *plist = Fcons (property, Fcons (value, *plist)); | |
2507 } | |
2508 | |
2509 int | |
2510 external_remprop (Lisp_Object *plist, Lisp_Object property, | |
578 | 2511 int laxp, Error_Behavior errb) |
428 | 2512 { |
2513 Lisp_Object *tortoise = plist; | |
2514 Lisp_Object *hare = plist; | |
2515 | |
2516 while (!NILP (*tortoise)) | |
2517 { | |
2518 Lisp_Object *tortsave = tortoise; | |
2519 Lisp_Object retval; | |
2520 | |
2521 /* See above */ | |
2522 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2523 return 0; | |
2524 | |
2525 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2526 : internal_equal (XCAR (*tortsave), property, 0)) | |
2527 { | |
2528 /* Now you see why it's so convenient to have that level | |
2529 of indirection. */ | |
2530 *tortsave = XCDR (XCDR (*tortsave)); | |
2531 return 1; | |
2532 } | |
2533 } | |
2534 | |
2535 return 0; | |
2536 } | |
2537 | |
2538 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /* | |
2539 Extract a value from a property list. | |
2540 PLIST is a property list, which is a list of the form | |
444 | 2541 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...). |
2542 PROPERTY is usually a symbol. | |
2543 This function returns the value corresponding to the PROPERTY, | |
2544 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 2545 */ |
444 | 2546 (plist, property, default_)) |
428 | 2547 { |
444 | 2548 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME); |
2549 return UNBOUNDP (value) ? default_ : value; | |
428 | 2550 } |
2551 | |
2552 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /* | |
444 | 2553 Change value in PLIST of PROPERTY to VALUE. |
2554 PLIST is a property list, which is a list of the form | |
2555 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
2556 PROPERTY is usually a symbol and VALUE is any object. | |
2557 If PROPERTY is already a property on the list, its value is set to VALUE, | |
2558 otherwise the new PROPERTY VALUE pair is added. | |
2559 The new plist is returned; use `(setq x (plist-put x property value))' | |
2560 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 2561 */ |
444 | 2562 (plist, property, value)) |
428 | 2563 { |
444 | 2564 external_plist_put (&plist, property, value, 0, ERROR_ME); |
428 | 2565 return plist; |
2566 } | |
2567 | |
2568 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /* | |
444 | 2569 Remove from PLIST the property PROPERTY and its value. |
2570 PLIST is a property list, which is a list of the form | |
2571 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
2572 PROPERTY is usually a symbol. | |
2573 The new plist is returned; use `(setq x (plist-remprop x property))' | |
2574 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 2575 */ |
444 | 2576 (plist, property)) |
428 | 2577 { |
444 | 2578 external_remprop (&plist, property, 0, ERROR_ME); |
428 | 2579 return plist; |
2580 } | |
2581 | |
2582 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /* | |
444 | 2583 Return t if PROPERTY has a value specified in PLIST. |
428 | 2584 */ |
444 | 2585 (plist, property)) |
428 | 2586 { |
444 | 2587 Lisp_Object value = Fplist_get (plist, property, Qunbound); |
2588 return UNBOUNDP (value) ? Qnil : Qt; | |
428 | 2589 } |
2590 | |
2591 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /* | |
2592 Given a plist, signal an error if there is anything wrong with it. | |
2593 This means that it's a malformed or circular plist. | |
2594 */ | |
2595 (plist)) | |
2596 { | |
2597 Lisp_Object *tortoise; | |
2598 Lisp_Object *hare; | |
2599 | |
2600 start_over: | |
2601 tortoise = &plist; | |
2602 hare = &plist; | |
2603 while (!NILP (*tortoise)) | |
2604 { | |
2605 Lisp_Object retval; | |
2606 | |
2607 /* See above */ | |
2608 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME, | |
2609 &retval)) | |
2610 goto start_over; | |
2611 } | |
2612 | |
2613 return Qnil; | |
2614 } | |
2615 | |
2616 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /* | |
2617 Given a plist, return non-nil if its format is correct. | |
2618 If it returns nil, `check-valid-plist' will signal an error when given | |
442 | 2619 the plist; that means it's a malformed or circular plist. |
428 | 2620 */ |
2621 (plist)) | |
2622 { | |
2623 Lisp_Object *tortoise; | |
2624 Lisp_Object *hare; | |
2625 | |
2626 tortoise = &plist; | |
2627 hare = &plist; | |
2628 while (!NILP (*tortoise)) | |
2629 { | |
2630 Lisp_Object retval; | |
2631 | |
2632 /* See above */ | |
2633 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT, | |
2634 &retval)) | |
2635 return Qnil; | |
2636 } | |
2637 | |
2638 return Qt; | |
2639 } | |
2640 | |
2641 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /* | |
2642 Destructively remove any duplicate entries from a plist. | |
2643 In such cases, the first entry applies. | |
2644 | |
2645 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2646 a nil value is removed. This feature is a virus that has infected | |
2647 old Lisp implementations, but should not be used except for backward | |
2648 compatibility. | |
2649 | |
2650 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
2651 return value may not be EQ to the passed-in value, so make sure to | |
2652 `setq' the value back into where it came from. | |
2653 */ | |
2654 (plist, nil_means_not_present)) | |
2655 { | |
2656 Lisp_Object head = plist; | |
2657 | |
2658 Fcheck_valid_plist (plist); | |
2659 | |
2660 while (!NILP (plist)) | |
2661 { | |
2662 Lisp_Object prop = Fcar (plist); | |
2663 Lisp_Object next = Fcdr (plist); | |
2664 | |
2665 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
2666 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
2667 { | |
2668 if (EQ (head, plist)) | |
2669 head = Fcdr (next); | |
2670 plist = Fcdr (next); | |
2671 continue; | |
2672 } | |
2673 /* external_remprop returns 1 if it removed any property. | |
2674 We have to loop till it didn't remove anything, in case | |
2675 the property occurs many times. */ | |
2676 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME)) | |
2677 DO_NOTHING; | |
2678 plist = Fcdr (next); | |
2679 } | |
2680 | |
2681 return head; | |
2682 } | |
2683 | |
2684 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /* | |
2685 Extract a value from a lax property list. | |
444 | 2686 LAX-PLIST is a lax property list, which is a list of the form |
2687 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2688 properties is done using `equal' instead of `eq'. | |
2689 PROPERTY is usually a symbol. | |
2690 This function returns the value corresponding to PROPERTY, | |
2691 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 2692 */ |
444 | 2693 (lax_plist, property, default_)) |
428 | 2694 { |
444 | 2695 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME); |
2696 return UNBOUNDP (value) ? default_ : value; | |
428 | 2697 } |
2698 | |
2699 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /* | |
444 | 2700 Change value in LAX-PLIST of PROPERTY to VALUE. |
2701 LAX-PLIST is a lax property list, which is a list of the form | |
2702 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2703 properties is done using `equal' instead of `eq'. | |
2704 PROPERTY is usually a symbol and VALUE is any object. | |
2705 If PROPERTY is already a property on the list, its value is set to | |
2706 VALUE, otherwise the new PROPERTY VALUE pair is added. | |
2707 The new plist is returned; use `(setq x (lax-plist-put x property value))' | |
2708 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 2709 */ |
444 | 2710 (lax_plist, property, value)) |
428 | 2711 { |
444 | 2712 external_plist_put (&lax_plist, property, value, 1, ERROR_ME); |
428 | 2713 return lax_plist; |
2714 } | |
2715 | |
2716 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /* | |
444 | 2717 Remove from LAX-PLIST the property PROPERTY and its value. |
2718 LAX-PLIST is a lax property list, which is a list of the form | |
2719 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2720 properties is done using `equal' instead of `eq'. | |
2721 PROPERTY is usually a symbol. | |
2722 The new plist is returned; use `(setq x (lax-plist-remprop x property))' | |
2723 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 2724 */ |
444 | 2725 (lax_plist, property)) |
428 | 2726 { |
444 | 2727 external_remprop (&lax_plist, property, 1, ERROR_ME); |
428 | 2728 return lax_plist; |
2729 } | |
2730 | |
2731 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /* | |
444 | 2732 Return t if PROPERTY has a value specified in LAX-PLIST. |
2733 LAX-PLIST is a lax property list, which is a list of the form | |
2734 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2735 properties is done using `equal' instead of `eq'. | |
428 | 2736 */ |
444 | 2737 (lax_plist, property)) |
428 | 2738 { |
444 | 2739 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt; |
428 | 2740 } |
2741 | |
2742 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /* | |
2743 Destructively remove any duplicate entries from a lax plist. | |
2744 In such cases, the first entry applies. | |
2745 | |
2746 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2747 a nil value is removed. This feature is a virus that has infected | |
2748 old Lisp implementations, but should not be used except for backward | |
2749 compatibility. | |
2750 | |
2751 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
2752 return value may not be EQ to the passed-in value, so make sure to | |
2753 `setq' the value back into where it came from. | |
2754 */ | |
2755 (lax_plist, nil_means_not_present)) | |
2756 { | |
2757 Lisp_Object head = lax_plist; | |
2758 | |
2759 Fcheck_valid_plist (lax_plist); | |
2760 | |
2761 while (!NILP (lax_plist)) | |
2762 { | |
2763 Lisp_Object prop = Fcar (lax_plist); | |
2764 Lisp_Object next = Fcdr (lax_plist); | |
2765 | |
2766 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
2767 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
2768 { | |
2769 if (EQ (head, lax_plist)) | |
2770 head = Fcdr (next); | |
2771 lax_plist = Fcdr (next); | |
2772 continue; | |
2773 } | |
2774 /* external_remprop returns 1 if it removed any property. | |
2775 We have to loop till it didn't remove anything, in case | |
2776 the property occurs many times. */ | |
2777 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME)) | |
2778 DO_NOTHING; | |
2779 lax_plist = Fcdr (next); | |
2780 } | |
2781 | |
2782 return head; | |
2783 } | |
2784 | |
2785 /* In C because the frame props stuff uses it */ | |
2786 | |
2787 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /* | |
2788 Convert association list ALIST into the equivalent property-list form. | |
2789 The plist is returned. This converts from | |
2790 | |
2791 \((a . 1) (b . 2) (c . 3)) | |
2792 | |
2793 into | |
2794 | |
2795 \(a 1 b 2 c 3) | |
2796 | |
2797 The original alist is destroyed in the process of constructing the plist. | |
2798 See also `alist-to-plist'. | |
2799 */ | |
2800 (alist)) | |
2801 { | |
2802 Lisp_Object head = alist; | |
2803 while (!NILP (alist)) | |
2804 { | |
2805 /* remember the alist element. */ | |
2806 Lisp_Object el = Fcar (alist); | |
2807 | |
2808 Fsetcar (alist, Fcar (el)); | |
2809 Fsetcar (el, Fcdr (el)); | |
2810 Fsetcdr (el, Fcdr (alist)); | |
2811 Fsetcdr (alist, el); | |
2812 alist = Fcdr (Fcdr (alist)); | |
2813 } | |
2814 | |
2815 return head; | |
2816 } | |
2817 | |
2818 DEFUN ("get", Fget, 2, 3, 0, /* | |
442 | 2819 Return the value of OBJECT's PROPERTY property. |
2820 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'. | |
428 | 2821 If there is no such property, return optional third arg DEFAULT |
442 | 2822 \(which defaults to `nil'). OBJECT can be a symbol, string, extent, |
2823 face, or glyph. See also `put', `remprop', and `object-plist'. | |
428 | 2824 */ |
442 | 2825 (object, property, default_)) |
428 | 2826 { |
2827 /* Various places in emacs call Fget() and expect it not to quit, | |
2828 so don't quit. */ | |
442 | 2829 Lisp_Object val; |
2830 | |
2831 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop) | |
2832 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property); | |
428 | 2833 else |
563 | 2834 invalid_operation ("Object type has no properties", object); |
442 | 2835 |
2836 return UNBOUNDP (val) ? default_ : val; | |
428 | 2837 } |
2838 | |
2839 DEFUN ("put", Fput, 3, 3, 0, /* | |
442 | 2840 Set OBJECT's PROPERTY to VALUE. |
2841 It can be subsequently retrieved with `(get OBJECT PROPERTY)'. | |
2842 OBJECT can be a symbol, face, extent, or string. | |
428 | 2843 For a string, no properties currently have predefined meanings. |
2844 For the predefined properties for extents, see `set-extent-property'. | |
2845 For the predefined properties for faces, see `set-face-property'. | |
2846 See also `get', `remprop', and `object-plist'. | |
2847 */ | |
442 | 2848 (object, property, value)) |
428 | 2849 { |
1920 | 2850 /* This function cannot GC */ |
428 | 2851 CHECK_LISP_WRITEABLE (object); |
2852 | |
442 | 2853 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop) |
428 | 2854 { |
442 | 2855 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop |
2856 (object, property, value)) | |
563 | 2857 invalid_change ("Can't set property on object", property); |
428 | 2858 } |
2859 else | |
563 | 2860 invalid_change ("Object type has no settable properties", object); |
428 | 2861 |
2862 return value; | |
2863 } | |
2864 | |
2865 DEFUN ("remprop", Fremprop, 2, 2, 0, /* | |
442 | 2866 Remove, from OBJECT's property list, PROPERTY and its corresponding value. |
2867 OBJECT can be a symbol, string, extent, face, or glyph. Return non-nil | |
2868 if the property list was actually modified (i.e. if PROPERTY was present | |
2869 in the property list). See also `get', `put', and `object-plist'. | |
428 | 2870 */ |
442 | 2871 (object, property)) |
428 | 2872 { |
442 | 2873 int ret = 0; |
2874 | |
428 | 2875 CHECK_LISP_WRITEABLE (object); |
2876 | |
442 | 2877 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop) |
428 | 2878 { |
442 | 2879 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property); |
2880 if (ret == -1) | |
563 | 2881 invalid_change ("Can't remove property from object", property); |
428 | 2882 } |
2883 else | |
563 | 2884 invalid_change ("Object type has no removable properties", object); |
442 | 2885 |
2886 return ret ? Qt : Qnil; | |
428 | 2887 } |
2888 | |
2889 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /* | |
442 | 2890 Return a property list of OBJECT's properties. |
2891 For a symbol, this is equivalent to `symbol-plist'. | |
2892 OBJECT can be a symbol, string, extent, face, or glyph. | |
2893 Do not modify the returned property list directly; | |
2894 this may or may not have the desired effects. Use `put' instead. | |
428 | 2895 */ |
2896 (object)) | |
2897 { | |
442 | 2898 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist) |
2899 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object); | |
428 | 2900 else |
563 | 2901 invalid_operation ("Object type has no properties", object); |
428 | 2902 |
2903 return Qnil; | |
2904 } | |
2905 | |
2906 | |
853 | 2907 static Lisp_Object |
2908 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2, | |
2909 Lisp_Object depth) | |
2910 { | |
2911 return make_int (internal_equal (obj1, obj2, XINT (depth))); | |
2912 } | |
2913 | |
2914 int | |
2915 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
|
2916 const Ascbyte *warning_string, |
853 | 2917 int flags, |
2918 struct call_trapping_problems_result *p, | |
2919 int retval, | |
2920 Lisp_Object obj1, Lisp_Object obj2, | |
2921 int depth) | |
2922 { | |
2923 Lisp_Object glorp = | |
2924 va_call_trapping_problems (warning_class, warning_string, | |
2925 flags, p, | |
2926 (lisp_fn_t) tweaked_internal_equal, | |
2927 3, obj1, obj2, make_int (depth)); | |
2928 if (UNBOUNDP (glorp)) | |
2929 return retval; | |
2930 else | |
2931 return XINT (glorp); | |
2932 } | |
2933 | |
428 | 2934 int |
2935 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2936 { | |
2937 if (depth > 200) | |
563 | 2938 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 2939 QUIT; |
2940 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
2941 return 1; | |
2942 /* Note that (equal 20 20.0) should be nil */ | |
2943 if (XTYPE (obj1) != XTYPE (obj2)) | |
2944 return 0; | |
2945 if (LRECORDP (obj1)) | |
2946 { | |
442 | 2947 const struct lrecord_implementation |
428 | 2948 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), |
2949 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
2950 | |
2951 return (imp1 == imp2) && | |
2952 /* 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
|
2953 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 0)); |
428 | 2954 } |
2955 | |
2956 return 0; | |
2957 } | |
2958 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2959 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
|
2960 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2961 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
|
2962 ARRAY_STRING, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2963 ARRAY_VECTOR, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2964 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
|
2965 }; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2966 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2967 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
|
2968 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
|
2969 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2970 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
|
2971 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
|
2972 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
|
2973 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
|
2974 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
|
2975 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
|
2976 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
|
2977 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2978 |
801 | 2979 int |
2980 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2981 { | |
2982 if (depth > 200) | |
2983 stack_overflow ("Stack overflow in equalp", Qunbound); | |
2984 QUIT; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2985 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2986 /* 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
|
2987 of two equal fixnums or the same object seen twice. */ |
801 | 2988 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) |
2989 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
|
2990 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2991 /* 2. If both numbers, compare with `='. */ |
1983 | 2992 if (NUMBERP (obj1) && NUMBERP (obj2)) |
2993 { | |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
2994 return (0 == bytecode_arithcompare (obj1, obj2)); |
1983 | 2995 } |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2996 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2997 /* 3. If characters, compare case-insensitively. */ |
801 | 2998 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
|
2999 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
|
3000 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3001 /* 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
|
3002 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
|
3003 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3004 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
|
3005 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
|
3006 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
|
3007 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
|
3008 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3009 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
|
3010 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
|
3011 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
|
3012 /* 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
|
3013 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
|
3014 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3015 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
|
3016 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
|
3017 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
|
3018 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3019 return 1; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3020 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3021 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3022 /* 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
|
3023 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
|
3024 their contents, the equal() method will call internal_equal_0(). */ |
801 | 3025 if (XTYPE (obj1) != XTYPE (obj2)) |
3026 return 0; | |
3027 if (LRECORDP (obj1)) | |
3028 { | |
3029 const struct lrecord_implementation | |
3030 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), | |
3031 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3032 | |
3033 return (imp1 == imp2) && | |
3034 /* 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
|
3035 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 1)); |
801 | 3036 } |
3037 | |
3038 return 0; | |
3039 } | |
3040 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3041 int |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3042 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
|
3043 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3044 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3045 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
|
3046 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3047 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
|
3048 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3049 |
428 | 3050 /* Note that we may be calling sub-objects that will use |
3051 internal_equal() (instead of internal_old_equal()). Oh well. | |
3052 We will get an Ebola note if there's any possibility of confusion, | |
3053 but that seems unlikely. */ | |
3054 | |
3055 static int | |
3056 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3057 { | |
3058 if (depth > 200) | |
563 | 3059 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3060 QUIT; |
3061 if (HACKEQ_UNSAFE (obj1, obj2)) | |
3062 return 1; | |
3063 /* Note that (equal 20 20.0) should be nil */ | |
3064 if (XTYPE (obj1) != XTYPE (obj2)) | |
3065 return 0; | |
3066 | |
3067 return internal_equal (obj1, obj2, depth); | |
3068 } | |
3069 | |
3070 DEFUN ("equal", Fequal, 2, 2, 0, /* | |
3071 Return t if two Lisp objects have similar structure and contents. | |
3072 They must have the same data type. | |
3073 Conses are compared by comparing the cars and the cdrs. | |
3074 Vectors and strings are compared element by element. | |
3075 Numbers are compared by value. Symbols must match exactly. | |
3076 */ | |
444 | 3077 (object1, object2)) |
428 | 3078 { |
444 | 3079 return internal_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3080 } |
3081 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3082 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
|
3083 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
|
3084 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3085 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
|
3086 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
|
3087 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
|
3088 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3089 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
|
3090 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
|
3091 `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
|
3092 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3093 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
|
3094 `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
|
3095 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
|
3096 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
|
3097 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
|
3098 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
|
3099 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
|
3100 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
|
3101 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3102 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
|
3103 (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
|
3104 `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
|
3105 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
|
3106 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
|
3107 */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3108 (object1, object2)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3109 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3110 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
|
3111 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3112 |
428 | 3113 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* |
3114 Return t if two Lisp objects have similar structure and contents. | |
3115 They must have the same data type. | |
3116 \(Note, however, that an exception is made for characters and integers; | |
3117 this is known as the "char-int confoundance disease." See `eq' and | |
3118 `old-eq'.) | |
3119 This function is provided only for byte-code compatibility with v19. | |
3120 Do not use it. | |
3121 */ | |
444 | 3122 (object1, object2)) |
428 | 3123 { |
444 | 3124 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3125 } |
3126 | |
3127 | |
3128 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /* | |
434 | 3129 Destructively modify ARRAY by replacing each element with ITEM. |
428 | 3130 ARRAY is a vector, bit vector, or string. |
3131 */ | |
3132 (array, item)) | |
3133 { | |
3134 retry: | |
3135 if (STRINGP (array)) | |
3136 { | |
793 | 3137 Bytecount old_bytecount = XSTRING_LENGTH (array); |
434 | 3138 Bytecount new_bytecount; |
3139 Bytecount item_bytecount; | |
867 | 3140 Ibyte item_buf[MAX_ICHAR_LEN]; |
3141 Ibyte *p; | |
3142 Ibyte *end; | |
434 | 3143 |
428 | 3144 CHECK_CHAR_COERCE_INT (item); |
2720 | 3145 |
428 | 3146 CHECK_LISP_WRITEABLE (array); |
771 | 3147 sledgehammer_check_ascii_begin (array); |
867 | 3148 item_bytecount = set_itext_ichar (item_buf, XCHAR (item)); |
826 | 3149 new_bytecount = item_bytecount * (Bytecount) string_char_length (array); |
793 | 3150 |
3151 resize_string (array, -1, new_bytecount - old_bytecount); | |
3152 | |
3153 for (p = XSTRING_DATA (array), end = p + new_bytecount; | |
434 | 3154 p < end; |
3155 p += item_bytecount) | |
3156 memcpy (p, item_buf, item_bytecount); | |
3157 *p = '\0'; | |
3158 | |
793 | 3159 XSET_STRING_ASCII_BEGIN (array, |
3160 item_bytecount == 1 ? | |
3161 min (new_bytecount, MAX_STRING_ASCII_BEGIN) : | |
3162 0); | |
428 | 3163 bump_string_modiff (array); |
771 | 3164 sledgehammer_check_ascii_begin (array); |
428 | 3165 } |
3166 else if (VECTORP (array)) | |
3167 { | |
3168 Lisp_Object *p = XVECTOR_DATA (array); | |
665 | 3169 Elemcount len = XVECTOR_LENGTH (array); |
428 | 3170 CHECK_LISP_WRITEABLE (array); |
3171 while (len--) | |
3172 *p++ = item; | |
3173 } | |
3174 else if (BIT_VECTORP (array)) | |
3175 { | |
440 | 3176 Lisp_Bit_Vector *v = XBIT_VECTOR (array); |
665 | 3177 Elemcount len = bit_vector_length (v); |
428 | 3178 int bit; |
3179 CHECK_BIT (item); | |
444 | 3180 bit = XINT (item); |
428 | 3181 CHECK_LISP_WRITEABLE (array); |
3182 while (len--) | |
3183 set_bit_vector_bit (v, len, bit); | |
3184 } | |
3185 else | |
3186 { | |
3187 array = wrong_type_argument (Qarrayp, array); | |
3188 goto retry; | |
3189 } | |
3190 return array; | |
3191 } | |
3192 | |
3193 Lisp_Object | |
3194 nconc2 (Lisp_Object arg1, Lisp_Object arg2) | |
3195 { | |
3196 Lisp_Object args[2]; | |
3197 struct gcpro gcpro1; | |
3198 args[0] = arg1; | |
3199 args[1] = arg2; | |
3200 | |
3201 GCPRO1 (args[0]); | |
3202 gcpro1.nvars = 2; | |
3203 | |
3204 RETURN_UNGCPRO (bytecode_nconc2 (args)); | |
3205 } | |
3206 | |
3207 Lisp_Object | |
3208 bytecode_nconc2 (Lisp_Object *args) | |
3209 { | |
3210 retry: | |
3211 | |
3212 if (CONSP (args[0])) | |
3213 { | |
3214 /* (setcdr (last args[0]) args[1]) */ | |
3215 Lisp_Object tortoise, hare; | |
665 | 3216 Elemcount count; |
428 | 3217 |
3218 for (hare = tortoise = args[0], count = 0; | |
3219 CONSP (XCDR (hare)); | |
3220 hare = XCDR (hare), count++) | |
3221 { | |
3222 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3223 | |
3224 if (count & 1) | |
3225 tortoise = XCDR (tortoise); | |
3226 if (EQ (hare, tortoise)) | |
3227 signal_circular_list_error (args[0]); | |
3228 } | |
3229 XCDR (hare) = args[1]; | |
3230 return args[0]; | |
3231 } | |
3232 else if (NILP (args[0])) | |
3233 { | |
3234 return args[1]; | |
3235 } | |
3236 else | |
3237 { | |
3238 args[0] = wrong_type_argument (args[0], Qlistp); | |
3239 goto retry; | |
3240 } | |
3241 } | |
3242 | |
3243 DEFUN ("nconc", Fnconc, 0, MANY, 0, /* | |
3244 Concatenate any number of lists by altering them. | |
3245 Only the last argument is not altered, and need not be a list. | |
3246 Also see: `append'. | |
3247 If the first argument is nil, there is no way to modify it by side | |
3248 effect; therefore, write `(setq foo (nconc foo list))' to be sure of | |
3249 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
|
3250 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
3251 arguments: (&rest ARGS) |
428 | 3252 */ |
3253 (int nargs, Lisp_Object *args)) | |
3254 { | |
3255 int argnum = 0; | |
3256 struct gcpro gcpro1; | |
3257 | |
3258 /* The modus operandi in Emacs is "caller gc-protects args". | |
3259 However, nconc (particularly nconc2 ()) is called many times | |
3260 in Emacs on freshly created stuff (e.g. you see the idiom | |
3261 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those | |
3262 callers out by protecting the args ourselves to save them | |
3263 a lot of temporary-variable grief. */ | |
3264 | |
3265 GCPRO1 (args[0]); | |
3266 gcpro1.nvars = nargs; | |
3267 | |
3268 while (argnum < nargs) | |
3269 { | |
3270 Lisp_Object val; | |
3271 retry: | |
3272 val = args[argnum]; | |
3273 if (CONSP (val)) | |
3274 { | |
3275 /* `val' is the first cons, which will be our return value. */ | |
3276 /* `last_cons' will be the cons cell to mutate. */ | |
3277 Lisp_Object last_cons = val; | |
3278 Lisp_Object tortoise = val; | |
3279 | |
3280 for (argnum++; argnum < nargs; argnum++) | |
3281 { | |
3282 Lisp_Object next = args[argnum]; | |
3283 retry_next: | |
3284 if (CONSP (next) || argnum == nargs -1) | |
3285 { | |
3286 /* (setcdr (last val) next) */ | |
665 | 3287 Elemcount count; |
428 | 3288 |
3289 for (count = 0; | |
3290 CONSP (XCDR (last_cons)); | |
3291 last_cons = XCDR (last_cons), count++) | |
3292 { | |
3293 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3294 | |
3295 if (count & 1) | |
3296 tortoise = XCDR (tortoise); | |
3297 if (EQ (last_cons, tortoise)) | |
3298 signal_circular_list_error (args[argnum-1]); | |
3299 } | |
3300 XCDR (last_cons) = next; | |
3301 } | |
3302 else if (NILP (next)) | |
3303 { | |
3304 continue; | |
3305 } | |
3306 else | |
3307 { | |
3308 next = wrong_type_argument (Qlistp, next); | |
3309 goto retry_next; | |
3310 } | |
3311 } | |
3312 RETURN_UNGCPRO (val); | |
3313 } | |
3314 else if (NILP (val)) | |
3315 argnum++; | |
3316 else if (argnum == nargs - 1) /* last arg? */ | |
3317 RETURN_UNGCPRO (val); | |
3318 else | |
3319 { | |
3320 args[argnum] = wrong_type_argument (Qlistp, val); | |
3321 goto retry; | |
3322 } | |
3323 } | |
3324 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */ | |
3325 } | |
3326 | |
3327 | |
434 | 3328 /* 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
|
3329 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3330 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
|
3331 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
|
3332 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
|
3333 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
|
3334 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
|
3335 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
|
3336 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3337 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
|
3338 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
|
3339 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
|
3340 mapcarX. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3341 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3342 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
|
3343 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
|
3344 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
|
3345 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
|
3346 traversal operation. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3347 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3348 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
|
3349 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
|
3350 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
|
3351 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
|
3352 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
|
3353 alone. */ |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3354 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3355 #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
|
3356 #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
|
3357 #define SOME_OR_EVERY_EVERY 2 |
428 | 3358 |
3359 static void | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3360 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
|
3361 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
|
3362 int some_or_every) |
428 | 3363 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3364 Lisp_Object called, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3365 struct gcpro gcpro1, gcpro2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3366 int i, j; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3367 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
|
3368 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3369 assert (LRECORDP (lisp_vals)); |
4999 | 3370 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
|
3371 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3372 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
|
3373 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3374 for (i = 1; i <= nsequences; ++i) |
428 | 3375 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3376 args[i] = Qnil; |
428 | 3377 } |
3378 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3379 if (vals != NULL) |
428 | 3380 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3381 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
|
3382 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3383 gcpro2.nvars = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3384 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3385 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3386 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3387 GCPRO1 (args[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3388 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3389 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3390 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3391 /* 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
|
3392 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
|
3393 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
|
3394 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
|
3395 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
|
3396 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3397 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
|
3398 Lisp_Object *val = vals; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3399 for (i = 0; i < call_count; ++i) |
434 | 3400 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3401 *val++ = XCAR (lst); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3402 lst = XCDR (lst); |
428 | 3403 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3404 gcpro2.nvars = call_count; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3405 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3406 for (i = 0; i < call_count; ++i) |
428 | 3407 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3408 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
|
3409 vals[i] = IGNORE_MULTIPLE_VALUES (Ffuncall (nsequences + 1, args)); |
428 | 3410 } |
3411 } | |
3412 else | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3413 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3414 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
|
3415 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
|
3416 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3417 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
|
3418 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3419 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3420 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
|
3421 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3422 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
|
3423 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3424 switch (sequence_types[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3425 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3426 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3427 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3428 if (!CONSP (sequences[j])) |
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 /* 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
|
3431 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
|
3432 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
|
3433 (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
|
3434 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
|
3435 callers. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3436 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
|
3437 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3438 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
|
3439 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
|
3440 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3441 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3442 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3443 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3444 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
|
3445 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3446 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3447 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3448 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3449 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
|
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_bit_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] |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3455 = 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
|
3456 i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3457 break; |
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 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3460 ABORT(); |
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 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3463 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
|
3464 if (vals != NULL) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3465 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3466 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
|
3467 gcpro2.nvars += 1; |
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 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3470 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3471 switch (lisp_vals_type) |
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 case lrecord_type_symbol: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3474 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3475 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3476 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3477 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
|
3478 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3479 called = IGNORE_MULTIPLE_VALUES (called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3480 if (!CONSP (lisp_vals)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3481 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3482 /* 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
|
3483 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
|
3484 relevant part, error. */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3485 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
|
3486 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3487 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3488 XSETCAR (lisp_vals, called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3489 lisp_vals = XCDR (lisp_vals); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3490 break; |
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 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3493 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
|
3494 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3495 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
|
3496 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3497 XCAR (lisp_vals) = called; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3498 UNGCPRO; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3499 return; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3500 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3501 break; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3502 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3503 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3504 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
|
3505 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3506 called = IGNORE_MULTIPLE_VALUES (called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3507 if (NILP (called)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3508 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3509 XCAR (lisp_vals) = Qnil; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3510 UNGCPRO; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3511 return; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3512 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3513 break; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3514 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3515 |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3516 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
|
3517 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3518 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3519 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3520 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
|
3521 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
|
3522 (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
|
3523 /* Let #'aset error. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3524 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
|
3525 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3526 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3527 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3528 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3529 /* 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
|
3530 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
|
3531 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
|
3532 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
|
3533 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
|
3534 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3535 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3536 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
|
3537 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3538 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
|
3539 (BITP (called) && |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3540 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
|
3541 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
|
3542 XINT (called)) : |
5002
0cd784a6ec44
fix some compile bugs of Aidan's
Ben Wing <ben@xemacs.org>
parents:
5001
diff
changeset
|
3543 (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
|
3544 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3545 } |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
3546 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
|
3547 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3548 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3549 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3550 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3551 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3552 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3553 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3554 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3555 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3556 UNGCPRO; |
428 | 3557 } |
3558 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3559 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
|
3560 Call FUNCTION on each element of SEQUENCE, and concat results to a string. |
751 | 3561 Between each pair of results, insert SEPARATOR. |
3562 | |
3563 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR | |
3564 results in spaces between the values returned by FUNCTION. SEQUENCE itself | |
3565 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
|
3566 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3567 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
|
3568 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
|
3569 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
|
3570 `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
|
3571 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3572 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES) |
428 | 3573 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3574 (int nargs, Lisp_Object *args)) |
428 | 3575 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3576 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
|
3577 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
|
3578 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
|
3579 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
|
3580 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3581 EMACS_INT i, nargs0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3582 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3583 args[2] = sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3584 args[1] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3585 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3586 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
|
3587 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3588 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3589 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
|
3590 } |
428 | 3591 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3592 if (len == 0) return build_ascstring (""); |
428 | 3593 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3594 nargs0 = len + len - 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3595 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
|
3596 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3597 /* 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
|
3598 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
|
3599 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
|
3600 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
|
3601 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3602 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
|
3603 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3604 args0[i] = XCAR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3605 sequence = XCDR (sequence); |
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 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3608 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3609 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3610 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
|
3611 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
|
3612 } |
428 | 3613 |
3614 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
|
3615 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
|
3616 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3617 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
|
3618 args0[i] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3619 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3620 return Fconcat (nargs0, args0); |
428 | 3621 } |
3622 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3623 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
|
3624 Call FUNCTION on each element of SEQUENCE; return a list of the results. |
434 | 3625 The result is a list of the same length as SEQUENCE. |
428 | 3626 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
|
3627 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3628 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
|
3629 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
|
3630 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
|
3631 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
|
3632 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3633 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3634 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3635 (int nargs, Lisp_Object *args)) |
428 | 3636 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3637 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
|
3638 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
|
3639 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3640 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3641 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3642 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
|
3643 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3644 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3645 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
|
3646 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3647 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3648 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
|
3649 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
|
3650 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
|
3651 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3652 return Flist ((int) len, args0); |
428 | 3653 } |
3654 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3655 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
|
3656 Call FUNCTION on each element of SEQUENCE; return a vector of the results. |
428 | 3657 The result is a vector of the same length as SEQUENCE. |
434 | 3658 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
|
3659 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3660 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
|
3661 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
|
3662 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
|
3663 `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
|
3664 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3665 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3666 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3667 (int nargs, Lisp_Object *args)) |
428 | 3668 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3669 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
|
3670 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
|
3671 Lisp_Object result; |
428 | 3672 struct gcpro gcpro1; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3673 int i; |
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 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
|
3676 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3677 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3678 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
|
3679 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3680 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3681 result = make_vector (len, Qnil); |
428 | 3682 GCPRO1 (result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3683 /* 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
|
3684 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
|
3685 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
|
3686 SOME_OR_EVERY_NEITHER); |
428 | 3687 UNGCPRO; |
3688 | |
3689 return result; | |
3690 } | |
3691 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3692 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
|
3693 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
|
3694 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3695 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
|
3696 together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3697 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3698 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
|
3699 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
|
3700 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
|
3701 `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
|
3702 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3703 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
|
3704 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3705 (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
|
3706 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3707 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
|
3708 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
|
3709 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3710 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3711 int i; |
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 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
|
3714 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3715 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3716 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
|
3717 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3718 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3719 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
|
3720 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
|
3721 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
|
3722 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3723 if (len < 2) |
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 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
|
3726 } |
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 /* 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
|
3729 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
|
3730 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
|
3731 GCPRO1 (args0[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3732 gcpro1.nvars = len + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3733 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3734 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
|
3735 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3736 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
|
3737 args0[i + 1] = nconcing; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3738 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3739 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3740 RETURN_UNGCPRO (XCDR (nconcing)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3741 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3742 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3743 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
|
3744 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
|
3745 |
428 | 3746 SEQUENCE may be a list, a vector, a bit vector, or a string. |
3747 This function is like `mapcar' but does not accumulate the results, | |
3748 which is more efficient if you do not use the results. | |
3749 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3750 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
|
3751 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
|
3752 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
|
3753 `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
|
3754 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3755 Return SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3756 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3757 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
|
3758 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3759 (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
|
3760 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3761 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
|
3762 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
|
3763 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3764 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3765 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3766 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
|
3767 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3768 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3769 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
|
3770 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3771 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3772 /* 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
|
3773 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
|
3774 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
|
3775 GCPRO1 (sequence); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3776 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
|
3777 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
|
3778 RETURN_UNGCPRO (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3779 } |
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 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
|
3782 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
|
3783 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3784 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
|
3785 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
|
3786 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3787 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
|
3788 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
|
3789 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3790 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
|
3791 `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
|
3792 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
|
3793 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3794 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3795 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3796 (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
|
3797 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3798 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
|
3799 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
|
3800 Lisp_Object result = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3801 Lisp_Object *args0 = NULL; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3802 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
|
3803 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3804 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3805 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3806 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
|
3807 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3808 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3809 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
|
3810 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3811 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3812 if (!NILP (type)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3813 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3814 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
|
3815 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3816 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3817 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
|
3818 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
|
3819 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3820 if (EQ (type, Qnil)) |
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 return result; |
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 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3825 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
|
3826 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3827 result = Fvector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3828 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3829 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
|
3830 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3831 result = Fstring (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3832 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3833 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
|
3834 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3835 result = Flist (len, args0); |
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 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
|
3838 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3839 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
|
3840 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3841 else |
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 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3844 GCPRO1 (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3845 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
|
3846 UNGCPRO; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3847 } |
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 return result; |
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 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3852 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
|
3853 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
|
3854 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3855 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
|
3856 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3857 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
|
3858 \(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
|
3859 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
|
3860 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
|
3861 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3862 Return RESULT-SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3863 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3864 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
|
3865 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3866 (int nargs, Lisp_Object *args)) |
428 | 3867 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3868 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
|
3869 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
|
3870 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
|
3871 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3872 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3873 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3874 args[1] = result_sequence; |
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 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
|
3877 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3878 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3879 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
|
3880 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3881 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3882 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
|
3883 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
|
3884 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3885 return result_sequence; |
428 | 3886 } |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3887 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3888 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
|
3889 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
|
3890 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3891 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
|
3892 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3893 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
|
3894 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
|
3895 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3896 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
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 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3899 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3900 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
|
3901 struct gcpro gcpro1; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3902 Elemcount len = EMACS_INT_MAX; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3903 int i; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3904 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3905 GCPRO1 (result_box); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3906 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3907 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
|
3908 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3909 CHECK_SEQUENCE (args[i]); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3910 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
|
3911 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3912 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3913 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
|
3914 SOME_OR_EVERY_SOME); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3915 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3916 RETURN_UNGCPRO (XCAR (result_box)); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3917 } |
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 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
|
3920 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
|
3921 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3922 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
|
3923 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
|
3924 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3925 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
|
3926 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3927 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
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 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3930 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3931 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
|
3932 struct gcpro gcpro1; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3933 Elemcount len = EMACS_INT_MAX; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3934 int i; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3935 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3936 GCPRO1 (result_box); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3937 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3938 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
|
3939 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3940 CHECK_SEQUENCE (args[i]); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3941 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
|
3942 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3943 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3944 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
|
3945 SOME_OR_EVERY_EVERY); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3946 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3947 RETURN_UNGCPRO (XCAR (result_box)); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3948 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3949 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3950 /* 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
|
3951 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
|
3952 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
|
3953 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3954 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
|
3955 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
|
3956 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3957 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
|
3958 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
|
3959 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
|
3960 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3961 static Lisp_Object |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3962 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
|
3963 int nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3964 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3965 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
|
3966 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
|
3967 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
|
3968 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
|
3969 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3970 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
|
3971 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3972 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
|
3973 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3974 args[i] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3975 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3976 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3977 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3978 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3979 nconcing[0] = result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3980 nconcing[1] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3981 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
|
3982 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3983 gcpro2.nvars = 2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3984 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3985 else |
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 GCPRO2 (args[0], result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3988 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3989 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3990 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3991 while (continuing) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3992 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3993 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
|
3994 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3995 if (CONSP (lists[j])) |
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 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
|
3998 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
|
3999 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4000 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
|
4001 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4002 continuing = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4003 break; |
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 else |
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 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
|
4008 } |
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 if (!continuing) break; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4011 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
|
4012 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4013 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4014 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4015 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4016 /* 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
|
4017 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
|
4018 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
|
4019 nconcing[1] = funcalled; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4020 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
|
4021 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4022 else |
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 /* 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
|
4025 once we're done: */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4026 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
|
4027 accum = XCDR (accum); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4028 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4029 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4030 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4031 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
|
4032 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4033 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
|
4034 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4035 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
|
4036 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4037 /* 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
|
4038 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
|
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 } |
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 if (!maplp) |
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 result = XCDR (result); |
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 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4048 RETURN_UNGCPRO (result); |
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 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
|
4052 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
|
4053 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
|
4054 the elements themselves." |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4055 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4056 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
|
4057 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4058 (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
|
4059 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4060 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
|
4061 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4062 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4063 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
|
4064 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
|
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, 1, 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 ("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
|
4074 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
|
4075 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4076 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
|
4077 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
|
4078 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4079 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
|
4080 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4081 (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
|
4082 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4083 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
|
4084 } |
428 | 4085 |
771 | 4086 /* Extra random functions */ |
442 | 4087 |
4088 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /* | |
4089 Destructively replace the list OLD with NEW. | |
4090 This is like (copy-sequence NEW) except that it reuses the | |
4091 conses in OLD as much as possible. If OLD and NEW are the same | |
4092 length, no consing will take place. | |
4093 */ | |
3025 | 4094 (old, new_)) |
442 | 4095 { |
2367 | 4096 Lisp_Object oldtail = old, prevoldtail = Qnil; |
4097 | |
3025 | 4098 EXTERNAL_LIST_LOOP_2 (elt, new_) |
442 | 4099 { |
4100 if (!NILP (oldtail)) | |
4101 { | |
4102 CHECK_CONS (oldtail); | |
2367 | 4103 XCAR (oldtail) = elt; |
442 | 4104 } |
4105 else if (!NILP (prevoldtail)) | |
4106 { | |
2367 | 4107 XCDR (prevoldtail) = Fcons (elt, Qnil); |
442 | 4108 prevoldtail = XCDR (prevoldtail); |
4109 } | |
4110 else | |
2367 | 4111 old = oldtail = Fcons (elt, Qnil); |
442 | 4112 |
4113 if (!NILP (oldtail)) | |
4114 { | |
4115 prevoldtail = oldtail; | |
4116 oldtail = XCDR (oldtail); | |
4117 } | |
4118 } | |
4119 | |
4120 if (!NILP (prevoldtail)) | |
4121 XCDR (prevoldtail) = Qnil; | |
4122 else | |
4123 old = Qnil; | |
4124 | |
4125 return old; | |
4126 } | |
4127 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4128 |
771 | 4129 Lisp_Object |
2367 | 4130 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string) |
771 | 4131 { |
4132 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
|
4133 build_ascstring (ascii_string)), |
771 | 4134 Qnil); |
4135 } | |
4136 | |
4137 Lisp_Object | |
2367 | 4138 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol) |
771 | 4139 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4140 return Fintern (concat2 (build_ascstring (ascii_string), |
771 | 4141 Fsymbol_name (symbol)), |
4142 Qnil); | |
4143 } | |
4144 | |
442 | 4145 |
428 | 4146 /* #### this function doesn't belong in this file! */ |
4147 | |
442 | 4148 #ifdef HAVE_GETLOADAVG |
4149 #ifdef HAVE_SYS_LOADAVG_H | |
4150 #include <sys/loadavg.h> | |
4151 #endif | |
4152 #else | |
4153 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */ | |
4154 #endif | |
4155 | |
428 | 4156 DEFUN ("load-average", Fload_average, 0, 1, 0, /* |
4157 Return list of 1 minute, 5 minute and 15 minute load averages. | |
4158 Each of the three load averages is multiplied by 100, | |
4159 then converted to integer. | |
4160 | |
4161 When USE-FLOATS is non-nil, floats will be used instead of integers. | |
4162 These floats are not multiplied by 100. | |
4163 | |
4164 If the 5-minute or 15-minute load averages are not available, return a | |
4165 shortened list, containing only those averages which are available. | |
4166 | |
4167 On some systems, this won't work due to permissions on /dev/kmem, | |
4168 in which case you can't use this. | |
4169 */ | |
4170 (use_floats)) | |
4171 { | |
4172 double load_ave[3]; | |
4173 int loads = getloadavg (load_ave, countof (load_ave)); | |
4174 Lisp_Object ret = Qnil; | |
4175 | |
4176 if (loads == -2) | |
563 | 4177 signal_error (Qunimplemented, |
4178 "load-average not implemented for this operating system", | |
4179 Qunbound); | |
428 | 4180 else if (loads < 0) |
563 | 4181 invalid_operation ("Could not get load-average", lisp_strerror (errno)); |
428 | 4182 |
4183 while (loads-- > 0) | |
4184 { | |
4185 Lisp_Object load = (NILP (use_floats) ? | |
4186 make_int ((int) (100.0 * load_ave[loads])) | |
4187 : make_float (load_ave[loads])); | |
4188 ret = Fcons (load, ret); | |
4189 } | |
4190 return ret; | |
4191 } | |
4192 | |
4193 | |
4194 Lisp_Object Vfeatures; | |
4195 | |
4196 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /* | |
4197 Return non-nil if feature FEXP is present in this Emacs. | |
4198 Use this to conditionalize execution of lisp code based on the | |
4199 presence or absence of emacs or environment extensions. | |
4200 FEXP can be a symbol, a number, or a list. | |
4201 If it is a symbol, that symbol is looked up in the `features' variable, | |
4202 and non-nil will be returned if found. | |
4203 If it is a number, the function will return non-nil if this Emacs | |
4204 has an equal or greater version number than FEXP. | |
4205 If it is a list whose car is the symbol `and', it will return | |
4206 non-nil if all the features in its cdr are non-nil. | |
4207 If it is a list whose car is the symbol `or', it will return non-nil | |
4208 if any of the features in its cdr are non-nil. | |
4209 If it is a list whose car is the symbol `not', it will return | |
4210 non-nil if the feature is not present. | |
4211 | |
4212 Examples: | |
4213 | |
4214 (featurep 'xemacs) | |
4215 => ; Non-nil on XEmacs. | |
4216 | |
4217 (featurep '(and xemacs gnus)) | |
4218 => ; Non-nil on XEmacs with Gnus loaded. | |
4219 | |
4220 (featurep '(or tty-frames (and emacs 19.30))) | |
4221 => ; Non-nil if this Emacs supports TTY frames. | |
4222 | |
4223 (featurep '(or (and xemacs 19.15) (and emacs 19.34))) | |
4224 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later. | |
4225 | |
442 | 4226 (featurep '(and xemacs 21.02)) |
4227 => ; Non-nil on XEmacs 21.2 and later. | |
4228 | |
428 | 4229 NOTE: The advanced arguments of this function (anything other than a |
4230 symbol) are not yet supported by FSF Emacs. If you feel they are useful | |
4231 for supporting multiple Emacs variants, lobby Richard Stallman at | |
442 | 4232 <bug-gnu-emacs@gnu.org>. |
428 | 4233 */ |
4234 (fexp)) | |
4235 { | |
4236 #ifndef FEATUREP_SYNTAX | |
4237 CHECK_SYMBOL (fexp); | |
4238 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
4239 #else /* FEATUREP_SYNTAX */ | |
4240 static double featurep_emacs_version; | |
4241 | |
4242 /* Brute force translation from Erik Naggum's lisp function. */ | |
4243 if (SYMBOLP (fexp)) | |
4244 { | |
4245 /* Original definition */ | |
4246 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
4247 } | |
4248 else if (INTP (fexp) || FLOATP (fexp)) | |
4249 { | |
4250 double d = extract_float (fexp); | |
4251 | |
4252 if (featurep_emacs_version == 0.0) | |
4253 { | |
4254 featurep_emacs_version = XINT (Vemacs_major_version) + | |
4255 (XINT (Vemacs_minor_version) / 100.0); | |
4256 } | |
4257 return featurep_emacs_version >= d ? Qt : Qnil; | |
4258 } | |
4259 else if (CONSP (fexp)) | |
4260 { | |
4261 Lisp_Object tem = XCAR (fexp); | |
4262 if (EQ (tem, Qnot)) | |
4263 { | |
4264 Lisp_Object negate; | |
4265 | |
4266 tem = XCDR (fexp); | |
4267 negate = Fcar (tem); | |
4268 if (!NILP (tem)) | |
4269 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil; | |
4270 else | |
4271 return Fsignal (Qinvalid_read_syntax, list1 (tem)); | |
4272 } | |
4273 else if (EQ (tem, Qand)) | |
4274 { | |
4275 tem = XCDR (fexp); | |
4276 /* Use Fcar/Fcdr for error-checking. */ | |
4277 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem)))) | |
4278 { | |
4279 tem = Fcdr (tem); | |
4280 } | |
4281 return NILP (tem) ? Qt : Qnil; | |
4282 } | |
4283 else if (EQ (tem, Qor)) | |
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) ? Qnil : Qt; | |
4292 } | |
4293 else | |
4294 { | |
4295 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp))); | |
4296 } | |
4297 } | |
4298 else | |
4299 { | |
4300 return Fsignal (Qinvalid_read_syntax, list1 (fexp)); | |
4301 } | |
4302 } | |
4303 #endif /* FEATUREP_SYNTAX */ | |
4304 | |
4305 DEFUN ("provide", Fprovide, 1, 1, 0, /* | |
4306 Announce that FEATURE is a feature of the current Emacs. | |
4307 This function updates the value of the variable `features'. | |
4308 */ | |
4309 (feature)) | |
4310 { | |
4311 Lisp_Object tem; | |
4312 CHECK_SYMBOL (feature); | |
4313 if (!NILP (Vautoload_queue)) | |
4314 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); | |
4315 tem = Fmemq (feature, Vfeatures); | |
4316 if (NILP (tem)) | |
4317 Vfeatures = Fcons (feature, Vfeatures); | |
4318 LOADHIST_ATTACH (Fcons (Qprovide, feature)); | |
4319 return feature; | |
4320 } | |
4321 | |
1067 | 4322 DEFUN ("require", Frequire, 1, 3, 0, /* |
3842 | 4323 Ensure that FEATURE is present in the Lisp environment. |
4324 FEATURE is a symbol naming a collection of resources (functions, etc). | |
4325 Optional FILENAME is a library from which to load resources; it defaults to | |
4326 the print name of FEATURE. | |
4327 Optional NOERROR, if non-nil, causes require to return nil rather than signal | |
4328 `file-error' if loading the library fails. | |
4329 | |
4330 If feature FEATURE is present in `features', update `load-history' to reflect | |
4331 the require and return FEATURE. Otherwise, try to load it from a library. | |
4332 The normal messages at start and end of loading are suppressed. | |
4333 If the library is successfully loaded and it calls `(provide FEATURE)', add | |
4334 FEATURE to `features', update `load-history' and return FEATURE. | |
4335 If the load succeeds but FEATURE is not provided by the library, signal | |
4336 `invalid-state'. | |
4337 | |
4338 The byte-compiler treats top-level calls to `require' specially, by evaluating | |
4339 them at compile time (and then compiling them normally). Thus a library may | |
4340 request that definitions that should be inlined such as macros and defsubsts | |
4341 be loaded into its compilation environment. Achieving this in other contexts | |
4342 requires an explicit \(eval-and-compile ...\) block. | |
428 | 4343 */ |
1067 | 4344 (feature, filename, noerror)) |
428 | 4345 { |
4346 Lisp_Object tem; | |
4347 CHECK_SYMBOL (feature); | |
4348 tem = Fmemq (feature, Vfeatures); | |
4349 LOADHIST_ATTACH (Fcons (Qrequire, feature)); | |
4350 if (!NILP (tem)) | |
4351 return feature; | |
4352 else | |
4353 { | |
4354 int speccount = specpdl_depth (); | |
4355 | |
4356 /* Value saved here is to be restored into Vautoload_queue */ | |
4357 record_unwind_protect (un_autoload, Vautoload_queue); | |
4358 Vautoload_queue = Qt; | |
4359 | |
1067 | 4360 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename, |
1261 | 4361 noerror, Qrequire, Qnil); |
1067 | 4362 /* If load failed entirely, return nil. */ |
4363 if (NILP (tem)) | |
4364 return unbind_to_1 (speccount, Qnil); | |
428 | 4365 |
4366 tem = Fmemq (feature, Vfeatures); | |
4367 if (NILP (tem)) | |
563 | 4368 invalid_state ("Required feature was not provided", feature); |
428 | 4369 |
4370 /* Once loading finishes, don't undo it. */ | |
4371 Vautoload_queue = Qt; | |
771 | 4372 return unbind_to_1 (speccount, feature); |
428 | 4373 } |
4374 } | |
4375 | |
4376 /* base64 encode/decode functions. | |
4377 | |
4378 Originally based on code from GNU recode. Ported to FSF Emacs by | |
4379 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and | |
4380 subsequently heavily hacked by Hrvoje Niksic. */ | |
4381 | |
4382 #define MIME_LINE_LENGTH 72 | |
4383 | |
4384 #define IS_ASCII(Character) \ | |
4385 ((Character) < 128) | |
4386 #define IS_BASE64(Character) \ | |
4387 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | |
4388 | |
4389 /* 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
|
4390 static Ascbyte base64_value_to_char[64] = |
428 | 4391 { |
4392 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */ | |
4393 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */ | |
4394 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */ | |
4395 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */ | |
4396 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */ | |
4397 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */ | |
4398 '8', '9', '+', '/' /* 60-63 */ | |
4399 }; | |
4400 | |
4401 /* Table of base64 values for first 128 characters. */ | |
4402 static short base64_char_to_value[128] = | |
4403 { | |
4404 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */ | |
4405 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */ | |
4406 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */ | |
4407 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */ | |
4408 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */ | |
4409 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */ | |
4410 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */ | |
4411 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */ | |
4412 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */ | |
4413 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */ | |
4414 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */ | |
4415 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */ | |
4416 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */ | |
4417 }; | |
4418 | |
4419 /* The following diagram shows the logical steps by which three octets | |
4420 get transformed into four base64 characters. | |
4421 | |
4422 .--------. .--------. .--------. | |
4423 |aaaaaabb| |bbbbcccc| |ccdddddd| | |
4424 `--------' `--------' `--------' | |
4425 6 2 4 4 2 6 | |
4426 .--------+--------+--------+--------. | |
4427 |00aaaaaa|00bbbbbb|00cccccc|00dddddd| | |
4428 `--------+--------+--------+--------' | |
4429 | |
4430 .--------+--------+--------+--------. | |
4431 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD| | |
4432 `--------+--------+--------+--------' | |
4433 | |
4434 The octets are divided into 6 bit chunks, which are then encoded into | |
4435 base64 characters. */ | |
4436 | |
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
|
4437 static DECLARE_DOESNT_RETURN (base64_conversion_error (const Ascbyte *, |
2268 | 4438 Lisp_Object)); |
4439 | |
575 | 4440 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
|
4441 base64_conversion_error (const Ascbyte *reason, Lisp_Object frob) |
563 | 4442 { |
4443 signal_error (Qbase64_conversion_error, reason, frob); | |
4444 } | |
4445 | |
4446 #define ADVANCE_INPUT(c, stream) \ | |
867 | 4447 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \ |
563 | 4448 ((ec > 255) ? \ |
4449 (base64_conversion_error ("Non-ascii character in base64 input", \ | |
4450 make_char (ec)), 0) \ | |
867 | 4451 : (c = (Ibyte)ec), 1)) |
665 | 4452 |
4453 static Bytebpos | |
867 | 4454 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break) |
428 | 4455 { |
4456 EMACS_INT counter = 0; | |
867 | 4457 Ibyte *e = to; |
4458 Ichar ec; | |
428 | 4459 unsigned int value; |
4460 | |
4461 while (1) | |
4462 { | |
1204 | 4463 Ibyte c = 0; |
428 | 4464 if (!ADVANCE_INPUT (c, istream)) |
4465 break; | |
4466 | |
4467 /* Wrap line every 76 characters. */ | |
4468 if (line_break) | |
4469 { | |
4470 if (counter < MIME_LINE_LENGTH / 4) | |
4471 counter++; | |
4472 else | |
4473 { | |
4474 *e++ = '\n'; | |
4475 counter = 1; | |
4476 } | |
4477 } | |
4478 | |
4479 /* Process first byte of a triplet. */ | |
4480 *e++ = base64_value_to_char[0x3f & c >> 2]; | |
4481 value = (0x03 & c) << 4; | |
4482 | |
4483 /* Process second byte of a triplet. */ | |
4484 if (!ADVANCE_INPUT (c, istream)) | |
4485 { | |
4486 *e++ = base64_value_to_char[value]; | |
4487 *e++ = '='; | |
4488 *e++ = '='; | |
4489 break; | |
4490 } | |
4491 | |
4492 *e++ = base64_value_to_char[value | (0x0f & c >> 4)]; | |
4493 value = (0x0f & c) << 2; | |
4494 | |
4495 /* Process third byte of a triplet. */ | |
4496 if (!ADVANCE_INPUT (c, istream)) | |
4497 { | |
4498 *e++ = base64_value_to_char[value]; | |
4499 *e++ = '='; | |
4500 break; | |
4501 } | |
4502 | |
4503 *e++ = base64_value_to_char[value | (0x03 & c >> 6)]; | |
4504 *e++ = base64_value_to_char[0x3f & c]; | |
4505 } | |
4506 | |
4507 return e - to; | |
4508 } | |
4509 #undef ADVANCE_INPUT | |
4510 | |
4511 /* Get next character from the stream, except that non-base64 | |
4512 characters are ignored. This is in accordance with rfc2045. EC | |
867 | 4513 should be an Ichar, so that it can hold -1 as the value for EOF. */ |
428 | 4514 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \ |
867 | 4515 ec = Lstream_get_ichar (stream); \ |
428 | 4516 ++streampos; \ |
4517 /* IS_BASE64 may not be called with negative arguments so check for \ | |
4518 EOF first. */ \ | |
4519 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \ | |
4520 break; \ | |
4521 } while (1) | |
4522 | |
4523 #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
|
4524 pos += set_itext_ichar (pos, (Ichar)((Binbyte)(val))); \ |
428 | 4525 ++ccnt; \ |
4526 } while (0) | |
4527 | |
665 | 4528 static Bytebpos |
867 | 4529 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr) |
428 | 4530 { |
4531 Charcount ccnt = 0; | |
867 | 4532 Ibyte *e = to; |
428 | 4533 EMACS_INT streampos = 0; |
4534 | |
4535 while (1) | |
4536 { | |
867 | 4537 Ichar ec; |
428 | 4538 unsigned long value; |
4539 | |
4540 /* Process first byte of a quadruplet. */ | |
4541 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4542 if (ec < 0) | |
4543 break; | |
4544 if (ec == '=') | |
563 | 4545 base64_conversion_error ("Illegal `=' character while decoding base64", |
4546 make_int (streampos)); | |
428 | 4547 value = base64_char_to_value[ec] << 18; |
4548 | |
4549 /* Process second byte of a quadruplet. */ | |
4550 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4551 if (ec < 0) | |
563 | 4552 base64_conversion_error ("Premature EOF while decoding base64", |
4553 Qunbound); | |
428 | 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] << 12; |
4558 STORE_BYTE (e, value >> 16, ccnt); | |
4559 | |
4560 /* Process third byte of a quadruplet. */ | |
4561 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4562 if (ec < 0) | |
563 | 4563 base64_conversion_error ("Premature EOF while decoding base64", |
4564 Qunbound); | |
428 | 4565 |
4566 if (ec == '=') | |
4567 { | |
4568 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4569 if (ec < 0) | |
563 | 4570 base64_conversion_error ("Premature EOF while decoding base64", |
4571 Qunbound); | |
428 | 4572 if (ec != '=') |
563 | 4573 base64_conversion_error |
4574 ("Padding `=' expected but not found while decoding base64", | |
4575 make_int (streampos)); | |
428 | 4576 continue; |
4577 } | |
4578 | |
4579 value |= base64_char_to_value[ec] << 6; | |
4580 STORE_BYTE (e, 0xff & value >> 8, ccnt); | |
4581 | |
4582 /* Process fourth byte of a quadruplet. */ | |
4583 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4584 if (ec < 0) | |
563 | 4585 base64_conversion_error ("Premature EOF while decoding base64", |
4586 Qunbound); | |
428 | 4587 if (ec == '=') |
4588 continue; | |
4589 | |
4590 value |= base64_char_to_value[ec]; | |
4591 STORE_BYTE (e, 0xff & value, ccnt); | |
4592 } | |
4593 | |
4594 *ccptr = ccnt; | |
4595 return e - to; | |
4596 } | |
4597 #undef ADVANCE_INPUT | |
4598 #undef ADVANCE_INPUT_IGNORE_NONBASE64 | |
4599 #undef STORE_BYTE | |
4600 | |
4601 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /* | |
444 | 4602 Base64-encode the region between START and END. |
428 | 4603 Return the length of the encoded text. |
4604 Optional third argument NO-LINE-BREAK means do not break long lines | |
4605 into shorter lines. | |
4606 */ | |
444 | 4607 (start, end, no_line_break)) |
428 | 4608 { |
867 | 4609 Ibyte *encoded; |
665 | 4610 Bytebpos encoded_length; |
428 | 4611 Charcount allength, length; |
4612 struct buffer *buf = current_buffer; | |
665 | 4613 Charbpos begv, zv, old_pt = BUF_PT (buf); |
428 | 4614 Lisp_Object input; |
851 | 4615 int speccount = specpdl_depth (); |
428 | 4616 |
444 | 4617 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 4618 barf_if_buffer_read_only (buf, begv, zv); |
4619 | |
4620 /* We need to allocate enough room for encoding the text. | |
4621 We need 33 1/3% more space, plus a newline every 76 | |
4622 characters, and then we round up. */ | |
4623 length = zv - begv; | |
4624 allength = length + length/3 + 1; | |
4625 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
4626 | |
4627 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
867 | 4628 /* We needn't multiply allength with MAX_ICHAR_LEN because all the |
428 | 4629 base64 characters will be single-byte. */ |
867 | 4630 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 4631 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
4632 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4633 assert (encoded_length <= allength); |
428 | 4634 Lstream_delete (XLSTREAM (input)); |
4635 | |
4636 /* Now we have encoded the region, so we insert the new contents | |
4637 and delete the old. (Insert first in order to preserve markers.) */ | |
4638 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0); | |
851 | 4639 unbind_to (speccount); |
428 | 4640 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0); |
4641 | |
4642 /* Simulate FSF Emacs implementation of this function: if point was | |
4643 in the region, place it at the beginning. */ | |
4644 if (old_pt >= begv && old_pt < zv) | |
4645 BUF_SET_PT (buf, begv); | |
4646 | |
4647 /* We return the length of the encoded text. */ | |
4648 return make_int (encoded_length); | |
4649 } | |
4650 | |
4651 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /* | |
4652 Base64 encode STRING and return the result. | |
444 | 4653 Optional argument NO-LINE-BREAK means do not break long lines |
4654 into shorter lines. | |
428 | 4655 */ |
4656 (string, no_line_break)) | |
4657 { | |
4658 Charcount allength, length; | |
665 | 4659 Bytebpos encoded_length; |
867 | 4660 Ibyte *encoded; |
428 | 4661 Lisp_Object input, result; |
4662 int speccount = specpdl_depth(); | |
4663 | |
4664 CHECK_STRING (string); | |
4665 | |
826 | 4666 length = string_char_length (string); |
428 | 4667 allength = length + length/3 + 1; |
4668 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
4669 | |
4670 input = make_lisp_string_input_stream (string, 0, -1); | |
867 | 4671 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 4672 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
4673 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4674 assert (encoded_length <= allength); |
428 | 4675 Lstream_delete (XLSTREAM (input)); |
4676 result = make_string (encoded, encoded_length); | |
851 | 4677 unbind_to (speccount); |
428 | 4678 return result; |
4679 } | |
4680 | |
4681 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /* | |
444 | 4682 Base64-decode the region between START and END. |
428 | 4683 Return the length of the decoded text. |
4684 If the region can't be decoded, return nil and don't modify the buffer. | |
4685 Characters out of the base64 alphabet are ignored. | |
4686 */ | |
444 | 4687 (start, end)) |
428 | 4688 { |
4689 struct buffer *buf = current_buffer; | |
665 | 4690 Charbpos begv, zv, old_pt = BUF_PT (buf); |
867 | 4691 Ibyte *decoded; |
665 | 4692 Bytebpos decoded_length; |
428 | 4693 Charcount length, cc_decoded_length; |
4694 Lisp_Object input; | |
4695 int speccount = specpdl_depth(); | |
4696 | |
444 | 4697 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 4698 barf_if_buffer_read_only (buf, begv, zv); |
4699 | |
4700 length = zv - begv; | |
4701 | |
4702 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
4703 /* We need to allocate enough room for decoding the text. */ | |
867 | 4704 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 4705 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
|
4706 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 4707 Lstream_delete (XLSTREAM (input)); |
4708 | |
4709 /* Now we have decoded the region, so we insert the new contents | |
4710 and delete the old. (Insert first in order to preserve markers.) */ | |
4711 BUF_SET_PT (buf, begv); | |
4712 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0); | |
851 | 4713 unbind_to (speccount); |
428 | 4714 buffer_delete_range (buf, begv + cc_decoded_length, |
4715 zv + cc_decoded_length, 0); | |
4716 | |
4717 /* Simulate FSF Emacs implementation of this function: if point was | |
4718 in the region, place it at the beginning. */ | |
4719 if (old_pt >= begv && old_pt < zv) | |
4720 BUF_SET_PT (buf, begv); | |
4721 | |
4722 return make_int (cc_decoded_length); | |
4723 } | |
4724 | |
4725 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /* | |
4726 Base64-decode STRING and return the result. | |
4727 Characters out of the base64 alphabet are ignored. | |
4728 */ | |
4729 (string)) | |
4730 { | |
867 | 4731 Ibyte *decoded; |
665 | 4732 Bytebpos decoded_length; |
428 | 4733 Charcount length, cc_decoded_length; |
4734 Lisp_Object input, result; | |
4735 int speccount = specpdl_depth(); | |
4736 | |
4737 CHECK_STRING (string); | |
4738 | |
826 | 4739 length = string_char_length (string); |
428 | 4740 /* We need to allocate enough room for decoding the text. */ |
867 | 4741 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 4742 |
4743 input = make_lisp_string_input_stream (string, 0, -1); | |
4744 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, | |
4745 &cc_decoded_length); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
4746 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 4747 Lstream_delete (XLSTREAM (input)); |
4748 | |
4749 result = make_string (decoded, decoded_length); | |
851 | 4750 unbind_to (speccount); |
428 | 4751 return result; |
4752 } | |
4753 | |
4754 Lisp_Object Qyes_or_no_p; | |
4755 | |
4756 void | |
4757 syms_of_fns (void) | |
4758 { | |
442 | 4759 INIT_LRECORD_IMPLEMENTATION (bit_vector); |
4760 | |
563 | 4761 DEFSYMBOL (Qstring_lessp); |
4762 DEFSYMBOL (Qidentity); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4763 DEFSYMBOL (Qvector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4764 DEFSYMBOL (Qarray); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4765 DEFSYMBOL (Qstring); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4766 DEFSYMBOL (Qlist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4767 DEFSYMBOL (Qbit_vector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4768 |
563 | 4769 DEFSYMBOL (Qyes_or_no_p); |
4770 | |
4771 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error); | |
428 | 4772 |
4773 DEFSUBR (Fidentity); | |
4774 DEFSUBR (Frandom); | |
4775 DEFSUBR (Flength); | |
4776 DEFSUBR (Fsafe_length); | |
4777 DEFSUBR (Fstring_equal); | |
801 | 4778 DEFSUBR (Fcompare_strings); |
428 | 4779 DEFSUBR (Fstring_lessp); |
4780 DEFSUBR (Fstring_modified_tick); | |
4781 DEFSUBR (Fappend); | |
4782 DEFSUBR (Fconcat); | |
4783 DEFSUBR (Fvconcat); | |
4784 DEFSUBR (Fbvconcat); | |
4785 DEFSUBR (Fcopy_list); | |
4786 DEFSUBR (Fcopy_sequence); | |
4787 DEFSUBR (Fcopy_alist); | |
4788 DEFSUBR (Fcopy_tree); | |
4789 DEFSUBR (Fsubseq); | |
4790 DEFSUBR (Fnthcdr); | |
4791 DEFSUBR (Fnth); | |
4792 DEFSUBR (Felt); | |
4793 DEFSUBR (Flast); | |
4794 DEFSUBR (Fbutlast); | |
4795 DEFSUBR (Fnbutlast); | |
4796 DEFSUBR (Fmember); | |
4797 DEFSUBR (Fold_member); | |
4798 DEFSUBR (Fmemq); | |
4799 DEFSUBR (Fold_memq); | |
4800 DEFSUBR (Fassoc); | |
4801 DEFSUBR (Fold_assoc); | |
4802 DEFSUBR (Fassq); | |
4803 DEFSUBR (Fold_assq); | |
4804 DEFSUBR (Frassoc); | |
4805 DEFSUBR (Fold_rassoc); | |
4806 DEFSUBR (Frassq); | |
4807 DEFSUBR (Fold_rassq); | |
4808 DEFSUBR (Fdelete); | |
4809 DEFSUBR (Fold_delete); | |
4810 DEFSUBR (Fdelq); | |
4811 DEFSUBR (Fold_delq); | |
4812 DEFSUBR (Fremassoc); | |
4813 DEFSUBR (Fremassq); | |
4814 DEFSUBR (Fremrassoc); | |
4815 DEFSUBR (Fremrassq); | |
4816 DEFSUBR (Fnreverse); | |
4817 DEFSUBR (Freverse); | |
4818 DEFSUBR (Fsort); | |
4819 DEFSUBR (Fplists_eq); | |
4820 DEFSUBR (Fplists_equal); | |
4821 DEFSUBR (Flax_plists_eq); | |
4822 DEFSUBR (Flax_plists_equal); | |
4823 DEFSUBR (Fplist_get); | |
4824 DEFSUBR (Fplist_put); | |
4825 DEFSUBR (Fplist_remprop); | |
4826 DEFSUBR (Fplist_member); | |
4827 DEFSUBR (Fcheck_valid_plist); | |
4828 DEFSUBR (Fvalid_plist_p); | |
4829 DEFSUBR (Fcanonicalize_plist); | |
4830 DEFSUBR (Flax_plist_get); | |
4831 DEFSUBR (Flax_plist_put); | |
4832 DEFSUBR (Flax_plist_remprop); | |
4833 DEFSUBR (Flax_plist_member); | |
4834 DEFSUBR (Fcanonicalize_lax_plist); | |
4835 DEFSUBR (Fdestructive_alist_to_plist); | |
4836 DEFSUBR (Fget); | |
4837 DEFSUBR (Fput); | |
4838 DEFSUBR (Fremprop); | |
4839 DEFSUBR (Fobject_plist); | |
4840 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
|
4841 DEFSUBR (Fequalp); |
428 | 4842 DEFSUBR (Fold_equal); |
4843 DEFSUBR (Ffillarray); | |
4844 DEFSUBR (Fnconc); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4845 DEFSUBR (FmapcarX); |
428 | 4846 DEFSUBR (Fmapvector); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4847 DEFSUBR (Fmapcan); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4848 DEFSUBR (Fmapc); |
428 | 4849 DEFSUBR (Fmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4850 DEFSUBR (Fmap); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4851 DEFSUBR (Fmap_into); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4852 DEFSUBR (Fsome); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4853 DEFSUBR (Fevery); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4854 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
|
4855 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
|
4856 DEFSUBR (Fmaplist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4857 DEFSUBR (Fmapl); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4858 DEFSUBR (Fmapcon); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4859 |
442 | 4860 DEFSUBR (Freplace_list); |
428 | 4861 DEFSUBR (Fload_average); |
4862 DEFSUBR (Ffeaturep); | |
4863 DEFSUBR (Frequire); | |
4864 DEFSUBR (Fprovide); | |
4865 DEFSUBR (Fbase64_encode_region); | |
4866 DEFSUBR (Fbase64_encode_string); | |
4867 DEFSUBR (Fbase64_decode_region); | |
4868 DEFSUBR (Fbase64_decode_string); | |
771 | 4869 |
4870 DEFSUBR (Fsplit_string_by_char); | |
4871 DEFSUBR (Fsplit_path); /* #### */ | |
4872 } | |
4873 | |
4874 void | |
4875 vars_of_fns (void) | |
4876 { | |
4877 DEFVAR_LISP ("path-separator", &Vpath_separator /* | |
4878 The directory separator in search paths, as a string. | |
4879 */ ); | |
4880 { | |
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
|
4881 Ascbyte c = SEPCHAR; |
867 | 4882 Vpath_separator = make_string ((Ibyte *) &c, 1); |
771 | 4883 } |
428 | 4884 } |
4885 | |
4886 void | |
4887 init_provide_once (void) | |
4888 { | |
4889 DEFVAR_LISP ("features", &Vfeatures /* | |
4890 A list of symbols which are the features of the executing emacs. | |
4891 Used by `featurep' and `require', and altered by `provide'. | |
4892 */ ); | |
4893 Vfeatures = Qnil; | |
4894 | |
4895 Fprovide (intern ("base64")); | |
4896 } |