Mercurial > hg > xemacs-beta
annotate src/fns.c @ 5187:b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
2010-04-03 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (Ffill):
Be much more careful about resizing a string argument, update
pointers to within the string data that may have been relocated
with the string resize. Fixes a test hang reported by Vin Shelton;
thanks, Vin.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 03 Apr 2010 15:27:32 +0100 |
parents | 039d9a7f2e6d |
children | 71ee43b8a74d |
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 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
57 Lisp_Object Qstring_lessp, Qsort, Qmerge, Qfill; |
428 | 58 Lisp_Object Qidentity; |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
59 Lisp_Object Qvector, Qarray, Qbit_vector, QsortX; |
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 |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
122 size_bit_vector (Lisp_Object obj) |
442 | 123 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
124 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
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 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
134 DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT ("bit-vector", bit_vector, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
135 mark_bit_vector, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
136 print_bit_vector, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
137 bit_vector_equal, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
138 bit_vector_hash, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
139 bit_vector_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
140 size_bit_vector, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
141 Lisp_Bit_Vector); |
934 | 142 |
428 | 143 |
144 DEFUN ("identity", Fidentity, 1, 1, 0, /* | |
145 Return the argument unchanged. | |
146 */ | |
147 (arg)) | |
148 { | |
149 return arg; | |
150 } | |
151 | |
152 DEFUN ("random", Frandom, 0, 1, 0, /* | |
153 Return a pseudo-random number. | |
1983 | 154 All fixnums are equally likely. On most systems, this is 31 bits' worth. |
428 | 155 With positive integer argument N, return random number in interval [0,N). |
1983 | 156 N can be a bignum, in which case the range of possible values is extended. |
428 | 157 With argument t, set the random number seed from the current time and pid. |
158 */ | |
159 (limit)) | |
160 { | |
161 EMACS_INT val; | |
162 unsigned long denominator; | |
163 | |
164 if (EQ (limit, Qt)) | |
771 | 165 seed_random (qxe_getpid () + time (NULL)); |
428 | 166 if (NATNUMP (limit) && !ZEROP (limit)) |
167 { | |
168 /* Try to take our random number from the higher bits of VAL, | |
169 not the lower, since (says Gentzel) the low bits of `random' | |
170 are less random than the higher ones. We do this by using the | |
171 quotient rather than the remainder. At the high end of the RNG | |
172 it's possible to get a quotient larger than limit; discarding | |
173 these values eliminates the bias that would otherwise appear | |
174 when using a large limit. */ | |
2039 | 175 denominator = ((unsigned long)1 << INT_VALBITS) / XINT (limit); |
428 | 176 do |
177 val = get_random () / denominator; | |
178 while (val >= XINT (limit)); | |
179 } | |
1983 | 180 #ifdef HAVE_BIGNUM |
181 else if (BIGNUMP (limit)) | |
182 { | |
183 bignum_random (scratch_bignum, XBIGNUM_DATA (limit)); | |
184 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
185 } | |
186 #endif | |
428 | 187 else |
188 val = get_random (); | |
189 | |
190 return make_int (val); | |
191 } | |
192 | |
193 /* Random data-structure functions */ | |
194 | |
195 #ifdef LOSING_BYTECODE | |
196 | |
197 /* #### Delete this shit */ | |
198 | |
199 /* Charcount is a misnomer here as we might be dealing with the | |
200 length of a vector or list, but emphasizes that we're not dealing | |
201 with Bytecounts in strings */ | |
202 static Charcount | |
203 length_with_bytecode_hack (Lisp_Object seq) | |
204 { | |
205 if (!COMPILED_FUNCTIONP (seq)) | |
206 return XINT (Flength (seq)); | |
207 else | |
208 { | |
440 | 209 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (seq); |
428 | 210 |
211 return (f->flags.interactivep ? COMPILED_INTERACTIVE : | |
212 f->flags.domainp ? COMPILED_DOMAIN : | |
213 COMPILED_DOC_STRING) | |
214 + 1; | |
215 } | |
216 } | |
217 | |
218 #endif /* LOSING_BYTECODE */ | |
219 | |
220 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
|
221 check_losing_bytecode (const Ascbyte *function, Lisp_Object seq) |
428 | 222 { |
223 if (COMPILED_FUNCTIONP (seq)) | |
563 | 224 signal_ferror_with_frob |
225 (Qinvalid_argument, seq, | |
428 | 226 "As of 20.3, `%s' no longer works with compiled-function objects", |
227 function); | |
228 } | |
229 | |
230 DEFUN ("length", Flength, 1, 1, 0, /* | |
231 Return the length of vector, bit vector, list or string SEQUENCE. | |
232 */ | |
233 (sequence)) | |
234 { | |
235 retry: | |
236 if (STRINGP (sequence)) | |
826 | 237 return make_int (string_char_length (sequence)); |
428 | 238 else if (CONSP (sequence)) |
239 { | |
665 | 240 Elemcount len; |
428 | 241 GET_EXTERNAL_LIST_LENGTH (sequence, len); |
242 return make_int (len); | |
243 } | |
244 else if (VECTORP (sequence)) | |
245 return make_int (XVECTOR_LENGTH (sequence)); | |
246 else if (NILP (sequence)) | |
247 return Qzero; | |
248 else if (BIT_VECTORP (sequence)) | |
249 return make_int (bit_vector_length (XBIT_VECTOR (sequence))); | |
250 else | |
251 { | |
252 check_losing_bytecode ("length", sequence); | |
253 sequence = wrong_type_argument (Qsequencep, sequence); | |
254 goto retry; | |
255 } | |
256 } | |
257 | |
258 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /* | |
259 Return the length of a list, but avoid error or infinite loop. | |
260 This function never gets an error. If LIST is not really a list, | |
261 it returns 0. If LIST is circular, it returns a finite value | |
262 which is at least the number of distinct elements. | |
263 */ | |
264 (list)) | |
265 { | |
266 Lisp_Object hare, tortoise; | |
665 | 267 Elemcount len; |
428 | 268 |
269 for (hare = tortoise = list, len = 0; | |
270 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); | |
271 hare = XCDR (hare), len++) | |
272 { | |
273 if (len & 1) | |
274 tortoise = XCDR (tortoise); | |
275 } | |
276 | |
277 return make_int (len); | |
278 } | |
279 | |
280 /*** string functions. ***/ | |
281 | |
282 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /* | |
283 Return t if two strings have identical contents. | |
284 Case is significant. Text properties are ignored. | |
285 \(Under XEmacs, `equal' also ignores text properties and extents in | |
286 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20 | |
287 `equal' is the same as in XEmacs, in that respect.) | |
288 Symbols are also allowed; their print names are used instead. | |
289 */ | |
444 | 290 (string1, string2)) |
428 | 291 { |
292 Bytecount len; | |
793 | 293 Lisp_Object p1, p2; |
428 | 294 |
444 | 295 if (SYMBOLP (string1)) |
296 p1 = XSYMBOL (string1)->name; | |
428 | 297 else |
298 { | |
444 | 299 CHECK_STRING (string1); |
793 | 300 p1 = string1; |
428 | 301 } |
302 | |
444 | 303 if (SYMBOLP (string2)) |
304 p2 = XSYMBOL (string2)->name; | |
428 | 305 else |
306 { | |
444 | 307 CHECK_STRING (string2); |
793 | 308 p2 = string2; |
428 | 309 } |
310 | |
793 | 311 return (((len = XSTRING_LENGTH (p1)) == XSTRING_LENGTH (p2)) && |
312 !memcmp (XSTRING_DATA (p1), XSTRING_DATA (p2), len)) ? Qt : Qnil; | |
428 | 313 } |
314 | |
801 | 315 DEFUN ("compare-strings", Fcompare_strings, 6, 7, 0, /* |
316 Compare the contents of two strings, maybe ignoring case. | |
317 In string STR1, skip the first START1 characters and stop at END1. | |
318 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
|
319 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
|
320 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
|
321 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
|
322 |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
323 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
|
324 Case is significant by default. |
801 | 325 |
326 The value is t if the strings (or specified portions) match. | |
327 If string STR1 is less, the value is a negative number N; | |
328 - 1 - N is the number of characters that match at the beginning. | |
329 If string STR1 is greater, the value is a positive number N; | |
330 N - 1 is the number of characters that match at the beginning. | |
331 */ | |
332 (str1, start1, end1, str2, start2, end2, ignore_case)) | |
333 { | |
334 Charcount ccstart1, ccend1, ccstart2, ccend2; | |
335 Bytecount bstart1, blen1, bstart2, blen2; | |
336 Charcount matching; | |
337 int res; | |
338 | |
339 CHECK_STRING (str1); | |
340 CHECK_STRING (str2); | |
341 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
|
342 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 343 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
|
344 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 345 |
346 bstart1 = string_index_char_to_byte (str1, ccstart1); | |
347 blen1 = string_offset_char_to_byte_len (str1, bstart1, ccend1 - ccstart1); | |
348 bstart2 = string_index_char_to_byte (str2, ccstart2); | |
349 blen2 = string_offset_char_to_byte_len (str2, bstart2, ccend2 - ccstart2); | |
350 | |
351 res = ((NILP (ignore_case) ? qxetextcmp_matching : qxetextcasecmp_matching) | |
352 (XSTRING_DATA (str1) + bstart1, blen1, | |
353 XSTRING_DATA (str2) + bstart2, blen2, | |
354 &matching)); | |
355 | |
356 if (!res) | |
357 return Qt; | |
358 else if (res > 0) | |
359 return make_int (1 + matching); | |
360 else | |
361 return make_int (-1 - matching); | |
362 } | |
363 | |
428 | 364 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /* |
365 Return t if first arg string is less than second in lexicographic order. | |
771 | 366 Comparison is simply done on a character-by-character basis using the |
367 numeric value of a character. (Note that this may not produce | |
368 particularly meaningful results under Mule if characters from | |
369 different charsets are being compared.) | |
428 | 370 |
371 Symbols are also allowed; their print names are used instead. | |
372 | |
771 | 373 Currently we don't do proper language-specific collation or handle |
374 multiple character sets. This may be changed when Unicode support | |
375 is implemented. | |
428 | 376 */ |
444 | 377 (string1, string2)) |
428 | 378 { |
793 | 379 Lisp_Object p1, p2; |
428 | 380 Charcount end, len2; |
381 int i; | |
382 | |
444 | 383 if (SYMBOLP (string1)) |
384 p1 = XSYMBOL (string1)->name; | |
793 | 385 else |
386 { | |
444 | 387 CHECK_STRING (string1); |
793 | 388 p1 = string1; |
428 | 389 } |
390 | |
444 | 391 if (SYMBOLP (string2)) |
392 p2 = XSYMBOL (string2)->name; | |
428 | 393 else |
394 { | |
444 | 395 CHECK_STRING (string2); |
793 | 396 p2 = string2; |
428 | 397 } |
398 | |
826 | 399 end = string_char_length (p1); |
400 len2 = string_char_length (p2); | |
428 | 401 if (end > len2) |
402 end = len2; | |
403 | |
404 { | |
867 | 405 Ibyte *ptr1 = XSTRING_DATA (p1); |
406 Ibyte *ptr2 = XSTRING_DATA (p2); | |
428 | 407 |
408 /* #### It is not really necessary to do this: We could compare | |
409 byte-by-byte and still get a reasonable comparison, since this | |
410 would compare characters with a charset in the same way. With | |
411 a little rearrangement of the leading bytes, we could make most | |
412 inter-charset comparisons work out the same, too; even if some | |
413 don't, this is not a big deal because inter-charset comparisons | |
414 aren't really well-defined anyway. */ | |
415 for (i = 0; i < end; i++) | |
416 { | |
867 | 417 if (itext_ichar (ptr1) != itext_ichar (ptr2)) |
418 return itext_ichar (ptr1) < itext_ichar (ptr2) ? Qt : Qnil; | |
419 INC_IBYTEPTR (ptr1); | |
420 INC_IBYTEPTR (ptr2); | |
428 | 421 } |
422 } | |
423 /* Can't do i < len2 because then comparison between "foo" and "foo^@" | |
424 won't work right in I18N2 case */ | |
425 return end < len2 ? Qt : Qnil; | |
426 } | |
427 | |
428 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /* | |
429 Return STRING's tick counter, incremented for each change to the string. | |
430 Each string has a tick counter which is incremented each time the contents | |
431 of the string are changed (e.g. with `aset'). It wraps around occasionally. | |
432 */ | |
433 (string)) | |
434 { | |
435 CHECK_STRING (string); | |
793 | 436 if (CONSP (XSTRING_PLIST (string)) && INTP (XCAR (XSTRING_PLIST (string)))) |
437 return XCAR (XSTRING_PLIST (string)); | |
428 | 438 else |
439 return Qzero; | |
440 } | |
441 | |
442 void | |
443 bump_string_modiff (Lisp_Object str) | |
444 { | |
793 | 445 Lisp_Object *ptr = &XSTRING_PLIST (str); |
428 | 446 |
447 #ifdef I18N3 | |
448 /* #### remove the `string-translatable' property from the string, | |
449 if there is one. */ | |
450 #endif | |
451 /* skip over extent info if it's there */ | |
452 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
453 ptr = &XCDR (*ptr); | |
454 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
793 | 455 XCAR (*ptr) = make_int (1+XINT (XCAR (*ptr))); |
428 | 456 else |
457 *ptr = Fcons (make_int (1), *ptr); | |
458 } | |
459 | |
460 | |
461 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector }; | |
462 static Lisp_Object concat (int nargs, Lisp_Object *args, | |
463 enum concat_target_type target_type, | |
464 int last_special); | |
465 | |
466 Lisp_Object | |
444 | 467 concat2 (Lisp_Object string1, Lisp_Object string2) |
428 | 468 { |
469 Lisp_Object args[2]; | |
444 | 470 args[0] = string1; |
471 args[1] = string2; | |
428 | 472 return concat (2, args, c_string, 0); |
473 } | |
474 | |
475 Lisp_Object | |
444 | 476 concat3 (Lisp_Object string1, Lisp_Object string2, Lisp_Object string3) |
428 | 477 { |
478 Lisp_Object args[3]; | |
444 | 479 args[0] = string1; |
480 args[1] = string2; | |
481 args[2] = string3; | |
428 | 482 return concat (3, args, c_string, 0); |
483 } | |
484 | |
485 Lisp_Object | |
444 | 486 vconcat2 (Lisp_Object vec1, Lisp_Object vec2) |
428 | 487 { |
488 Lisp_Object args[2]; | |
444 | 489 args[0] = vec1; |
490 args[1] = vec2; | |
428 | 491 return concat (2, args, c_vector, 0); |
492 } | |
493 | |
494 Lisp_Object | |
444 | 495 vconcat3 (Lisp_Object vec1, Lisp_Object vec2, Lisp_Object vec3) |
428 | 496 { |
497 Lisp_Object args[3]; | |
444 | 498 args[0] = vec1; |
499 args[1] = vec2; | |
500 args[2] = vec3; | |
428 | 501 return concat (3, args, c_vector, 0); |
502 } | |
503 | |
504 DEFUN ("append", Fappend, 0, MANY, 0, /* | |
505 Concatenate all the arguments and make the result a list. | |
506 The result is a list whose elements are the elements of all the arguments. | |
507 Each argument may be a list, vector, bit vector, or string. | |
508 The last argument is not copied, just used as the tail of the new list. | |
509 Also see: `nconc'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
510 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
511 arguments: (&rest ARGS) |
428 | 512 */ |
513 (int nargs, Lisp_Object *args)) | |
514 { | |
515 return concat (nargs, args, c_cons, 1); | |
516 } | |
517 | |
518 DEFUN ("concat", Fconcat, 0, MANY, 0, /* | |
519 Concatenate all the arguments and make the result a string. | |
520 The result is a string whose elements are the elements of all the arguments. | |
521 Each argument may be a string or a list or vector of characters. | |
522 | |
523 As of XEmacs 21.0, this function does NOT accept individual integers | |
524 as arguments. Old code that relies on, for example, (concat "foo" 50) | |
525 returning "foo50" will fail. To fix such code, either apply | |
526 `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
|
527 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
528 arguments: (&rest ARGS) |
428 | 529 */ |
530 (int nargs, Lisp_Object *args)) | |
531 { | |
532 return concat (nargs, args, c_string, 0); | |
533 } | |
534 | |
535 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /* | |
536 Concatenate all the arguments and make the result a vector. | |
537 The result is a vector whose elements are the elements of all the arguments. | |
538 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
|
539 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
540 arguments: (&rest ARGS) |
428 | 541 */ |
542 (int nargs, Lisp_Object *args)) | |
543 { | |
544 return concat (nargs, args, c_vector, 0); | |
545 } | |
546 | |
547 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /* | |
548 Concatenate all the arguments and make the result a bit vector. | |
549 The result is a bit vector whose elements are the elements of all the | |
550 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
|
551 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
552 arguments: (&rest ARGS) |
428 | 553 */ |
554 (int nargs, Lisp_Object *args)) | |
555 { | |
556 return concat (nargs, args, c_bit_vector, 0); | |
557 } | |
558 | |
559 /* Copy a (possibly dotted) list. LIST must be a cons. | |
560 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */ | |
561 static Lisp_Object | |
562 copy_list (Lisp_Object list) | |
563 { | |
564 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list)); | |
565 Lisp_Object last = list_copy; | |
566 Lisp_Object hare, tortoise; | |
665 | 567 Elemcount len; |
428 | 568 |
569 for (tortoise = hare = XCDR (list), len = 1; | |
570 CONSP (hare); | |
571 hare = XCDR (hare), len++) | |
572 { | |
573 XCDR (last) = Fcons (XCAR (hare), XCDR (hare)); | |
574 last = XCDR (last); | |
575 | |
576 if (len < CIRCULAR_LIST_SUSPICION_LENGTH) | |
577 continue; | |
578 if (len & 1) | |
579 tortoise = XCDR (tortoise); | |
580 if (EQ (tortoise, hare)) | |
581 signal_circular_list_error (list); | |
582 } | |
583 | |
584 return list_copy; | |
585 } | |
586 | |
587 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /* | |
588 Return a copy of list LIST, which may be a dotted list. | |
589 The elements of LIST are not copied; they are shared | |
590 with the original. | |
591 */ | |
592 (list)) | |
593 { | |
594 again: | |
595 if (NILP (list)) return list; | |
596 if (CONSP (list)) return copy_list (list); | |
597 | |
598 list = wrong_type_argument (Qlistp, list); | |
599 goto again; | |
600 } | |
601 | |
602 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /* | |
603 Return a copy of list, vector, bit vector or string SEQUENCE. | |
604 The elements of a list or vector are not copied; they are shared | |
605 with the original. SEQUENCE may be a dotted list. | |
606 */ | |
607 (sequence)) | |
608 { | |
609 again: | |
610 if (NILP (sequence)) return sequence; | |
611 if (CONSP (sequence)) return copy_list (sequence); | |
612 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0); | |
613 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0); | |
614 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0); | |
615 | |
616 check_losing_bytecode ("copy-sequence", sequence); | |
617 sequence = wrong_type_argument (Qsequencep, sequence); | |
618 goto again; | |
619 } | |
620 | |
621 struct merge_string_extents_struct | |
622 { | |
623 Lisp_Object string; | |
624 Bytecount entry_offset; | |
625 Bytecount entry_length; | |
626 }; | |
627 | |
628 static Lisp_Object | |
629 concat (int nargs, Lisp_Object *args, | |
630 enum concat_target_type target_type, | |
631 int last_special) | |
632 { | |
633 Lisp_Object val; | |
634 Lisp_Object tail = Qnil; | |
635 int toindex; | |
636 int argnum; | |
637 Lisp_Object last_tail; | |
638 Lisp_Object prev; | |
639 struct merge_string_extents_struct *args_mse = 0; | |
867 | 640 Ibyte *string_result = 0; |
641 Ibyte *string_result_ptr = 0; | |
428 | 642 struct gcpro gcpro1; |
851 | 643 int sdep = specpdl_depth (); |
428 | 644 |
645 /* The modus operandi in Emacs is "caller gc-protects args". | |
646 However, concat is called many times in Emacs on freshly | |
647 created stuff. So we help those callers out by protecting | |
648 the args ourselves to save them a lot of temporary-variable | |
649 grief. */ | |
650 | |
651 GCPRO1 (args[0]); | |
652 gcpro1.nvars = nargs; | |
653 | |
654 #ifdef I18N3 | |
655 /* #### if the result is a string and any of the strings have a string | |
656 for the `string-translatable' property, then concat should also | |
657 concat the args but use the `string-translatable' strings, and store | |
658 the result in the returned string's `string-translatable' property. */ | |
659 #endif | |
660 if (target_type == c_string) | |
661 args_mse = alloca_array (struct merge_string_extents_struct, nargs); | |
662 | |
663 /* In append, the last arg isn't treated like the others */ | |
664 if (last_special && nargs > 0) | |
665 { | |
666 nargs--; | |
667 last_tail = args[nargs]; | |
668 } | |
669 else | |
670 last_tail = Qnil; | |
671 | |
672 /* Check and coerce the arguments. */ | |
673 for (argnum = 0; argnum < nargs; argnum++) | |
674 { | |
675 Lisp_Object seq = args[argnum]; | |
676 if (LISTP (seq)) | |
677 ; | |
678 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq)) | |
679 ; | |
680 #ifdef LOSING_BYTECODE | |
681 else if (COMPILED_FUNCTIONP (seq)) | |
682 /* Urk! We allow this, for "compatibility"... */ | |
683 ; | |
684 #endif | |
685 #if 0 /* removed for XEmacs 21 */ | |
686 else if (INTP (seq)) | |
687 /* This is too revolting to think about but maintains | |
688 compatibility with FSF (and lots and lots of old code). */ | |
689 args[argnum] = Fnumber_to_string (seq); | |
690 #endif | |
691 else | |
692 { | |
693 check_losing_bytecode ("concat", seq); | |
694 args[argnum] = wrong_type_argument (Qsequencep, seq); | |
695 } | |
696 | |
697 if (args_mse) | |
698 { | |
699 if (STRINGP (seq)) | |
700 args_mse[argnum].string = seq; | |
701 else | |
702 args_mse[argnum].string = Qnil; | |
703 } | |
704 } | |
705 | |
706 { | |
707 /* Charcount is a misnomer here as we might be dealing with the | |
708 length of a vector or list, but emphasizes that we're not dealing | |
709 with Bytecounts in strings */ | |
710 Charcount total_length; | |
711 | |
712 for (argnum = 0, total_length = 0; argnum < nargs; argnum++) | |
713 { | |
714 #ifdef LOSING_BYTECODE | |
715 Charcount thislen = length_with_bytecode_hack (args[argnum]); | |
716 #else | |
717 Charcount thislen = XINT (Flength (args[argnum])); | |
718 #endif | |
719 total_length += thislen; | |
720 } | |
721 | |
722 switch (target_type) | |
723 { | |
724 case c_cons: | |
725 if (total_length == 0) | |
851 | 726 { |
727 unbind_to (sdep); | |
728 /* In append, if all but last arg are nil, return last arg */ | |
729 RETURN_UNGCPRO (last_tail); | |
730 } | |
428 | 731 val = Fmake_list (make_int (total_length), Qnil); |
732 break; | |
733 case c_vector: | |
734 val = make_vector (total_length, Qnil); | |
735 break; | |
736 case c_bit_vector: | |
737 val = make_bit_vector (total_length, Qzero); | |
738 break; | |
739 case c_string: | |
740 /* We don't make the string yet because we don't know the | |
741 actual number of bytes. This loop was formerly written | |
742 to call Fmake_string() here and then call set_string_char() | |
743 for each char. This seems logical enough but is waaaaaaaay | |
744 slow -- set_string_char() has to scan the whole string up | |
745 to the place where the substitution is called for in order | |
746 to find the place to change, and may have to do some | |
747 realloc()ing in order to make the char fit properly. | |
748 O(N^2) yuckage. */ | |
749 val = Qnil; | |
851 | 750 string_result = |
867 | 751 (Ibyte *) MALLOC_OR_ALLOCA (total_length * MAX_ICHAR_LEN); |
428 | 752 string_result_ptr = string_result; |
753 break; | |
754 default: | |
442 | 755 val = Qnil; |
2500 | 756 ABORT (); |
428 | 757 } |
758 } | |
759 | |
760 | |
761 if (CONSP (val)) | |
762 tail = val, toindex = -1; /* -1 in toindex is flag we are | |
763 making a list */ | |
764 else | |
765 toindex = 0; | |
766 | |
767 prev = Qnil; | |
768 | |
769 for (argnum = 0; argnum < nargs; argnum++) | |
770 { | |
771 Charcount thisleni = 0; | |
772 Charcount thisindex = 0; | |
773 Lisp_Object seq = args[argnum]; | |
867 | 774 Ibyte *string_source_ptr = 0; |
775 Ibyte *string_prev_result_ptr = string_result_ptr; | |
428 | 776 |
777 if (!CONSP (seq)) | |
778 { | |
779 #ifdef LOSING_BYTECODE | |
780 thisleni = length_with_bytecode_hack (seq); | |
781 #else | |
782 thisleni = XINT (Flength (seq)); | |
783 #endif | |
784 } | |
785 if (STRINGP (seq)) | |
786 string_source_ptr = XSTRING_DATA (seq); | |
787 | |
788 while (1) | |
789 { | |
790 Lisp_Object elt; | |
791 | |
792 /* We've come to the end of this arg, so exit. */ | |
793 if (NILP (seq)) | |
794 break; | |
795 | |
796 /* Fetch next element of `seq' arg into `elt' */ | |
797 if (CONSP (seq)) | |
798 { | |
799 elt = XCAR (seq); | |
800 seq = XCDR (seq); | |
801 } | |
802 else | |
803 { | |
804 if (thisindex >= thisleni) | |
805 break; | |
806 | |
807 if (STRINGP (seq)) | |
808 { | |
867 | 809 elt = make_char (itext_ichar (string_source_ptr)); |
810 INC_IBYTEPTR (string_source_ptr); | |
428 | 811 } |
812 else if (VECTORP (seq)) | |
813 elt = XVECTOR_DATA (seq)[thisindex]; | |
814 else if (BIT_VECTORP (seq)) | |
815 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq), | |
816 thisindex)); | |
817 else | |
818 elt = Felt (seq, make_int (thisindex)); | |
819 thisindex++; | |
820 } | |
821 | |
822 /* Store into result */ | |
823 if (toindex < 0) | |
824 { | |
825 /* toindex negative means we are making a list */ | |
826 XCAR (tail) = elt; | |
827 prev = tail; | |
828 tail = XCDR (tail); | |
829 } | |
830 else if (VECTORP (val)) | |
831 XVECTOR_DATA (val)[toindex++] = elt; | |
832 else if (BIT_VECTORP (val)) | |
833 { | |
834 CHECK_BIT (elt); | |
835 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt)); | |
836 } | |
837 else | |
838 { | |
839 CHECK_CHAR_COERCE_INT (elt); | |
867 | 840 string_result_ptr += set_itext_ichar (string_result_ptr, |
428 | 841 XCHAR (elt)); |
842 } | |
843 } | |
844 if (args_mse) | |
845 { | |
846 args_mse[argnum].entry_offset = | |
847 string_prev_result_ptr - string_result; | |
848 args_mse[argnum].entry_length = | |
849 string_result_ptr - string_prev_result_ptr; | |
850 } | |
851 } | |
852 | |
853 /* Now we finally make the string. */ | |
854 if (target_type == c_string) | |
855 { | |
856 val = make_string (string_result, string_result_ptr - string_result); | |
857 for (argnum = 0; argnum < nargs; argnum++) | |
858 { | |
859 if (STRINGP (args_mse[argnum].string)) | |
860 copy_string_extents (val, args_mse[argnum].string, | |
861 args_mse[argnum].entry_offset, 0, | |
862 args_mse[argnum].entry_length); | |
863 } | |
864 } | |
865 | |
866 if (!NILP (prev)) | |
867 XCDR (prev) = last_tail; | |
868 | |
851 | 869 unbind_to (sdep); |
428 | 870 RETURN_UNGCPRO (val); |
871 } | |
872 | |
873 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /* | |
874 Return a copy of ALIST. | |
875 This is an alist which represents the same mapping from objects to objects, | |
876 but does not share the alist structure with ALIST. | |
877 The objects mapped (cars and cdrs of elements of the alist) | |
878 are shared, however. | |
879 Elements of ALIST that are not conses are also shared. | |
880 */ | |
881 (alist)) | |
882 { | |
883 Lisp_Object tail; | |
884 | |
885 if (NILP (alist)) | |
886 return alist; | |
887 CHECK_CONS (alist); | |
888 | |
889 alist = concat (1, &alist, c_cons, 0); | |
890 for (tail = alist; CONSP (tail); tail = XCDR (tail)) | |
891 { | |
892 Lisp_Object car = XCAR (tail); | |
893 | |
894 if (CONSP (car)) | |
895 XCAR (tail) = Fcons (XCAR (car), XCDR (car)); | |
896 } | |
897 return alist; | |
898 } | |
899 | |
900 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /* | |
901 Return a copy of a list and substructures. | |
902 The argument is copied, and any lists contained within it are copied | |
903 recursively. Circularities and shared substructures are not preserved. | |
904 Second arg VECP causes vectors to be copied, too. Strings and bit vectors | |
905 are not copied. | |
906 */ | |
907 (arg, vecp)) | |
908 { | |
454 | 909 return safe_copy_tree (arg, vecp, 0); |
910 } | |
911 | |
912 Lisp_Object | |
913 safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth) | |
914 { | |
915 if (depth > 200) | |
563 | 916 stack_overflow ("Stack overflow in copy-tree", arg); |
454 | 917 |
428 | 918 if (CONSP (arg)) |
919 { | |
920 Lisp_Object rest; | |
921 rest = arg = Fcopy_sequence (arg); | |
922 while (CONSP (rest)) | |
923 { | |
924 Lisp_Object elt = XCAR (rest); | |
925 QUIT; | |
926 if (CONSP (elt) || VECTORP (elt)) | |
454 | 927 XCAR (rest) = safe_copy_tree (elt, vecp, depth + 1); |
428 | 928 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */ |
454 | 929 XCDR (rest) = safe_copy_tree (XCDR (rest), vecp, depth +1); |
428 | 930 rest = XCDR (rest); |
931 } | |
932 } | |
933 else if (VECTORP (arg) && ! NILP (vecp)) | |
934 { | |
935 int i = XVECTOR_LENGTH (arg); | |
936 int j; | |
937 arg = Fcopy_sequence (arg); | |
938 for (j = 0; j < i; j++) | |
939 { | |
940 Lisp_Object elt = XVECTOR_DATA (arg) [j]; | |
941 QUIT; | |
942 if (CONSP (elt) || VECTORP (elt)) | |
454 | 943 XVECTOR_DATA (arg) [j] = safe_copy_tree (elt, vecp, depth + 1); |
428 | 944 } |
945 } | |
946 return arg; | |
947 } | |
948 | |
949 DEFUN ("subseq", Fsubseq, 2, 3, 0, /* | |
442 | 950 Return the subsequence of SEQUENCE starting at START and ending before END. |
951 END may be omitted; then the subsequence runs to the end of SEQUENCE. | |
952 If START or END is negative, it counts from the end. | |
953 The returned subsequence is always of the same type as SEQUENCE. | |
954 If SEQUENCE is a string, relevant parts of the string-extent-data | |
955 are copied to the new string. | |
428 | 956 */ |
442 | 957 (sequence, start, end)) |
428 | 958 { |
442 | 959 EMACS_INT len, s, e; |
960 | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
961 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
|
962 { |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
963 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
|
964 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
|
965 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
|
966 |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 /* 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
|
974 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
|
975 return val; |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
976 } |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
977 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
978 CHECK_SEQUENCE (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
979 |
442 | 980 len = XINT (Flength (sequence)); |
981 | |
982 CHECK_INT (start); | |
983 s = XINT (start); | |
984 if (s < 0) | |
985 s = len + s; | |
986 | |
987 if (NILP (end)) | |
988 e = len; | |
428 | 989 else |
990 { | |
442 | 991 CHECK_INT (end); |
992 e = XINT (end); | |
993 if (e < 0) | |
994 e = len + e; | |
428 | 995 } |
996 | |
442 | 997 if (!(0 <= s && s <= e && e <= len)) |
998 args_out_of_range_3 (sequence, make_int (s), make_int (e)); | |
999 | |
1000 if (VECTORP (sequence)) | |
428 | 1001 { |
442 | 1002 Lisp_Object result = make_vector (e - s, Qnil); |
428 | 1003 EMACS_INT i; |
442 | 1004 Lisp_Object *in_elts = XVECTOR_DATA (sequence); |
428 | 1005 Lisp_Object *out_elts = XVECTOR_DATA (result); |
1006 | |
442 | 1007 for (i = s; i < e; i++) |
1008 out_elts[i - s] = in_elts[i]; | |
428 | 1009 return result; |
1010 } | |
442 | 1011 else if (LISTP (sequence)) |
428 | 1012 { |
1013 Lisp_Object result = Qnil; | |
1014 EMACS_INT i; | |
1015 | |
442 | 1016 sequence = Fnthcdr (make_int (s), sequence); |
1017 | |
1018 for (i = s; i < e; i++) | |
428 | 1019 { |
442 | 1020 result = Fcons (Fcar (sequence), result); |
1021 sequence = Fcdr (sequence); | |
428 | 1022 } |
1023 | |
1024 return Fnreverse (result); | |
1025 } | |
442 | 1026 else if (BIT_VECTORP (sequence)) |
1027 { | |
1028 Lisp_Object result = make_bit_vector (e - s, Qzero); | |
1029 EMACS_INT i; | |
1030 | |
1031 for (i = s; i < e; i++) | |
1032 set_bit_vector_bit (XBIT_VECTOR (result), i - s, | |
1033 bit_vector_bit (XBIT_VECTOR (sequence), i)); | |
1034 return result; | |
1035 } | |
1036 else | |
1037 { | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1038 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
|
1039 error */ |
442 | 1040 return Qnil; |
1041 } | |
428 | 1042 } |
1043 | |
771 | 1044 /* 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
|
1045 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
|
1046 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1047 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
|
1048 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
|
1049 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
|
1050 |
771 | 1051 static Lisp_Object |
867 | 1052 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
|
1053 Ichar sepchar, int unescape, Ichar escapechar) |
771 | 1054 { |
1055 Lisp_Object result = Qnil; | |
867 | 1056 const Ibyte *end = string + size; |
771 | 1057 |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1058 if (unescape) |
771 | 1059 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1060 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
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1067 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1068 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1069 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
|
1070 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
|
1071 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
|
1072 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1073 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
|
1074 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1075 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
|
1076 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1077 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
|
1078 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1079 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
|
1080 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1081 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1082 } |
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 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
|
1085 /* 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
|
1086 && !previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1087 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1088 ++deleting_escapes; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1089 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
|
1090 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1091 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1092 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1093 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
|
1094 } |
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 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
|
1097 } |
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 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
|
1100 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1101 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
|
1102 > 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
|
1103 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1104 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
|
1105 ((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
|
1106 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
|
1107 } |
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 cursor = string; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1110 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
|
1111 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
|
1112 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1113 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
|
1114 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1115 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
|
1116 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1117 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
|
1118 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1119 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
|
1120 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
|
1121 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
|
1122 } |
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 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
|
1125 && (pchar == escapechar); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1126 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1127 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
|
1128 } |
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 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
|
1131 unescape_cursor |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1132 - 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
|
1133 result); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1134 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1135 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1136 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1137 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
|
1138 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1139 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
|
1140 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1141 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1142 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
|
1143 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1144 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1145 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1146 } |
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 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1149 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1150 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1151 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1152 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
|
1153 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
|
1154 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1155 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
|
1156 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1157 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
|
1158 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1159 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
|
1160 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
|
1161 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1162 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1163 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
|
1164 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1165 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1166 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1167 } |
771 | 1168 } |
1169 return Fnreverse (result); | |
1170 } | |
1171 | |
1172 /* The same as the above, except PATH is an external C string (it is | |
1173 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR | |
1174 (':' or whatever). */ | |
1175 Lisp_Object | |
1176 split_external_path (const Extbyte *path) | |
1177 { | |
1178 Bytecount newlen; | |
867 | 1179 Ibyte *newpath; |
771 | 1180 if (!path) |
1181 return Qnil; | |
1182 | |
1183 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name); | |
1184 | |
1185 /* #### Does this make sense? It certainly does for | |
1186 split_env_path(), but it looks dubious here. Does any code | |
1187 depend on split_external_path("") returning nil instead of an empty | |
1188 string? */ | |
1189 if (!newlen) | |
1190 return Qnil; | |
1191 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1192 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR, 0, 0); |
771 | 1193 } |
1194 | |
1195 Lisp_Object | |
867 | 1196 split_env_path (const CIbyte *evarname, const Ibyte *default_) |
771 | 1197 { |
867 | 1198 const Ibyte *path = 0; |
771 | 1199 if (evarname) |
1200 path = egetenv (evarname); | |
1201 if (!path) | |
1202 path = default_; | |
1203 if (!path) | |
1204 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
|
1205 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR, 0, 0); |
771 | 1206 } |
1207 | |
1208 /* Ben thinks this function should not exist or be exported to Lisp. | |
1209 We use it to define split-path-string in subr.el (not!). */ | |
1210 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1211 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 3, 0, /* |
771 | 1212 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
|
1213 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1214 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
|
1215 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
|
1216 will be necessary for a single ESCAPE-CHAR to appear in the output string. |
771 | 1217 */ |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1218 (string, sepchar, escape_char)) |
771 | 1219 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1220 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
|
1221 |
771 | 1222 CHECK_STRING (string); |
1223 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
|
1224 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
|
1225 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1226 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
|
1227 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
|
1228 } |
867 | 1229 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
|
1230 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
|
1231 XCHAR (sepchar), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1232 !NILP (escape_char), escape_ichar); |
771 | 1233 } |
1234 | |
1235 /* #### This was supposed to be in subr.el, but is used VERY early in | |
1236 the bootstrap process, so it goes here. Damn. */ | |
1237 | |
1238 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /* | |
1239 Explode a search path into a list of strings. | |
1240 The path components are separated with the characters specified | |
1241 with `path-separator'. | |
1242 */ | |
1243 (path)) | |
1244 { | |
1245 CHECK_STRING (path); | |
1246 | |
1247 while (!STRINGP (Vpath_separator) | |
826 | 1248 || (string_char_length (Vpath_separator) != 1)) |
771 | 1249 Vpath_separator = signal_continuable_error |
1250 (Qinvalid_state, | |
1251 "`path-separator' should be set to a single-character string", | |
1252 Vpath_separator); | |
1253 | |
867 | 1254 return (split_string_by_ichar_1 |
771 | 1255 (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
|
1256 itext_ichar (XSTRING_DATA (Vpath_separator)), 0, 0)); |
771 | 1257 } |
1258 | |
428 | 1259 |
1260 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* | |
1261 Take cdr N times on LIST, and return the result. | |
1262 */ | |
1263 (n, list)) | |
1264 { | |
1920 | 1265 /* This function can GC */ |
647 | 1266 REGISTER EMACS_INT i; |
428 | 1267 REGISTER Lisp_Object tail = list; |
1268 CHECK_NATNUM (n); | |
1269 for (i = XINT (n); i; i--) | |
1270 { | |
1271 if (CONSP (tail)) | |
1272 tail = XCDR (tail); | |
1273 else if (NILP (tail)) | |
1274 return Qnil; | |
1275 else | |
1276 { | |
1277 tail = wrong_type_argument (Qlistp, tail); | |
1278 i++; | |
1279 } | |
1280 } | |
1281 return tail; | |
1282 } | |
1283 | |
1284 DEFUN ("nth", Fnth, 2, 2, 0, /* | |
1285 Return the Nth element of LIST. | |
1286 N counts from zero. If LIST is not that long, nil is returned. | |
1287 */ | |
1288 (n, list)) | |
1289 { | |
1920 | 1290 /* This function can GC */ |
428 | 1291 return Fcar (Fnthcdr (n, list)); |
1292 } | |
1293 | |
1294 DEFUN ("elt", Felt, 2, 2, 0, /* | |
1295 Return element of SEQUENCE at index N. | |
1296 */ | |
1297 (sequence, n)) | |
1298 { | |
1920 | 1299 /* This function can GC */ |
428 | 1300 retry: |
1301 CHECK_INT_COERCE_CHAR (n); /* yuck! */ | |
1302 if (LISTP (sequence)) | |
1303 { | |
1304 Lisp_Object tem = Fnthcdr (n, sequence); | |
1305 /* #### Utterly, completely, fucking disgusting. | |
1306 * #### The whole point of "elt" is that it operates on | |
1307 * #### sequences, and does error- (bounds-) checking. | |
1308 */ | |
1309 if (CONSP (tem)) | |
1310 return XCAR (tem); | |
1311 else | |
1312 #if 1 | |
1313 /* This is The Way It Has Always Been. */ | |
1314 return Qnil; | |
1315 #else | |
1316 /* This is The Way Mly and Cltl2 say It Should Be. */ | |
1317 args_out_of_range (sequence, n); | |
1318 #endif | |
1319 } | |
1320 else if (STRINGP (sequence) || | |
1321 VECTORP (sequence) || | |
1322 BIT_VECTORP (sequence)) | |
1323 return Faref (sequence, n); | |
1324 #ifdef LOSING_BYTECODE | |
1325 else if (COMPILED_FUNCTIONP (sequence)) | |
1326 { | |
1327 EMACS_INT idx = XINT (n); | |
1328 if (idx < 0) | |
1329 { | |
1330 lose: | |
1331 args_out_of_range (sequence, n); | |
1332 } | |
1333 /* Utter perversity */ | |
1334 { | |
1335 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence); | |
1336 switch (idx) | |
1337 { | |
1338 case COMPILED_ARGLIST: | |
1339 return compiled_function_arglist (f); | |
1340 case COMPILED_INSTRUCTIONS: | |
1341 return compiled_function_instructions (f); | |
1342 case COMPILED_CONSTANTS: | |
1343 return compiled_function_constants (f); | |
1344 case COMPILED_STACK_DEPTH: | |
1345 return compiled_function_stack_depth (f); | |
1346 case COMPILED_DOC_STRING: | |
1347 return compiled_function_documentation (f); | |
1348 case COMPILED_DOMAIN: | |
1349 return compiled_function_domain (f); | |
1350 case COMPILED_INTERACTIVE: | |
1351 if (f->flags.interactivep) | |
1352 return compiled_function_interactive (f); | |
1353 /* if we return nil, can't tell interactive with no args | |
1354 from noninteractive. */ | |
1355 goto lose; | |
1356 default: | |
1357 goto lose; | |
1358 } | |
1359 } | |
1360 } | |
1361 #endif /* LOSING_BYTECODE */ | |
1362 else | |
1363 { | |
1364 check_losing_bytecode ("elt", sequence); | |
1365 sequence = wrong_type_argument (Qsequencep, sequence); | |
1366 goto retry; | |
1367 } | |
1368 } | |
1369 | |
1370 DEFUN ("last", Flast, 1, 2, 0, /* | |
1371 Return the tail of list LIST, of length N (default 1). | |
1372 LIST may be a dotted list, but not a circular list. | |
1373 Optional argument N must be a non-negative integer. | |
1374 If N is zero, then the atom that terminates the list is returned. | |
1375 If N is greater than the length of LIST, then LIST itself is returned. | |
1376 */ | |
1377 (list, n)) | |
1378 { | |
1379 EMACS_INT int_n, count; | |
1380 Lisp_Object retval, tortoise, hare; | |
1381 | |
1382 CHECK_LIST (list); | |
1383 | |
1384 if (NILP (n)) | |
1385 int_n = 1; | |
1386 else | |
1387 { | |
1388 CHECK_NATNUM (n); | |
1389 int_n = XINT (n); | |
1390 } | |
1391 | |
1392 for (retval = tortoise = hare = list, count = 0; | |
1393 CONSP (hare); | |
1394 hare = XCDR (hare), | |
1395 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0), | |
1396 count++) | |
1397 { | |
1398 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
1399 | |
1400 if (count & 1) | |
1401 tortoise = XCDR (tortoise); | |
1402 if (EQ (hare, tortoise)) | |
1403 signal_circular_list_error (list); | |
1404 } | |
1405 | |
1406 return retval; | |
1407 } | |
1408 | |
1409 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /* | |
1410 Modify LIST to remove the last N (default 1) elements. | |
1411 If LIST has N or fewer elements, nil is returned and LIST is unmodified. | |
1412 */ | |
1413 (list, n)) | |
1414 { | |
1415 EMACS_INT int_n; | |
1416 | |
1417 CHECK_LIST (list); | |
1418 | |
1419 if (NILP (n)) | |
1420 int_n = 1; | |
1421 else | |
1422 { | |
1423 CHECK_NATNUM (n); | |
1424 int_n = XINT (n); | |
1425 } | |
1426 | |
1427 { | |
1428 Lisp_Object last_cons = list; | |
1429 | |
1430 EXTERNAL_LIST_LOOP_1 (list) | |
1431 { | |
1432 if (int_n-- < 0) | |
1433 last_cons = XCDR (last_cons); | |
1434 } | |
1435 | |
1436 if (int_n >= 0) | |
1437 return Qnil; | |
1438 | |
1439 XCDR (last_cons) = Qnil; | |
1440 return list; | |
1441 } | |
1442 } | |
1443 | |
1444 DEFUN ("butlast", Fbutlast, 1, 2, 0, /* | |
1445 Return a copy of LIST with the last N (default 1) elements removed. | |
1446 If LIST has N or fewer elements, nil is returned. | |
1447 */ | |
1448 (list, n)) | |
1449 { | |
444 | 1450 EMACS_INT int_n; |
428 | 1451 |
1452 CHECK_LIST (list); | |
1453 | |
1454 if (NILP (n)) | |
1455 int_n = 1; | |
1456 else | |
1457 { | |
1458 CHECK_NATNUM (n); | |
1459 int_n = XINT (n); | |
1460 } | |
1461 | |
1462 { | |
1463 Lisp_Object retval = Qnil; | |
1464 Lisp_Object tail = list; | |
1465 | |
1466 EXTERNAL_LIST_LOOP_1 (list) | |
1467 { | |
1468 if (--int_n < 0) | |
1469 { | |
1470 retval = Fcons (XCAR (tail), retval); | |
1471 tail = XCDR (tail); | |
1472 } | |
1473 } | |
1474 | |
1475 return Fnreverse (retval); | |
1476 } | |
1477 } | |
1478 | |
1479 DEFUN ("member", Fmember, 2, 2, 0, /* | |
1480 Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | |
1481 The value is actually the tail of LIST whose car is ELT. | |
1482 */ | |
1483 (elt, list)) | |
1484 { | |
1485 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1486 { | |
1487 if (internal_equal (elt, list_elt, 0)) | |
1488 return tail; | |
1489 } | |
1490 return Qnil; | |
1491 } | |
1492 | |
1493 DEFUN ("old-member", Fold_member, 2, 2, 0, /* | |
1494 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'. | |
1495 The value is actually the tail of LIST whose car is ELT. | |
1496 This function is provided only for byte-code compatibility with v19. | |
1497 Do not use it. | |
1498 */ | |
1499 (elt, list)) | |
1500 { | |
1501 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1502 { | |
1503 if (internal_old_equal (elt, list_elt, 0)) | |
1504 return tail; | |
1505 } | |
1506 return Qnil; | |
1507 } | |
1508 | |
1509 DEFUN ("memq", Fmemq, 2, 2, 0, /* | |
1510 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. | |
1511 The value is actually the tail of LIST whose car is ELT. | |
1512 */ | |
1513 (elt, list)) | |
1514 { | |
1515 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1516 { | |
1517 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1518 return tail; | |
1519 } | |
1520 return Qnil; | |
1521 } | |
1522 | |
1523 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /* | |
1524 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'. | |
1525 The value is actually the tail of LIST whose car is ELT. | |
1526 This function is provided only for byte-code compatibility with v19. | |
1527 Do not use it. | |
1528 */ | |
1529 (elt, list)) | |
1530 { | |
1531 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1532 { | |
1533 if (HACKEQ_UNSAFE (elt, list_elt)) | |
1534 return tail; | |
1535 } | |
1536 return Qnil; | |
1537 } | |
1538 | |
1539 Lisp_Object | |
1540 memq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1541 { | |
1542 LIST_LOOP_3 (list_elt, list, tail) | |
1543 { | |
1544 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1545 return tail; | |
1546 } | |
1547 return Qnil; | |
1548 } | |
1549 | |
1550 DEFUN ("assoc", Fassoc, 2, 2, 0, /* | |
444 | 1551 Return non-nil if KEY is `equal' to the car of an element of ALIST. |
1552 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1553 */ |
444 | 1554 (key, alist)) |
428 | 1555 { |
1556 /* This function can GC. */ | |
444 | 1557 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1558 { |
1559 if (internal_equal (key, elt_car, 0)) | |
1560 return elt; | |
1561 } | |
1562 return Qnil; | |
1563 } | |
1564 | |
1565 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /* | |
444 | 1566 Return non-nil if KEY is `old-equal' to the car of an element of ALIST. |
1567 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1568 */ |
444 | 1569 (key, alist)) |
428 | 1570 { |
1571 /* This function can GC. */ | |
444 | 1572 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1573 { |
1574 if (internal_old_equal (key, elt_car, 0)) | |
1575 return elt; | |
1576 } | |
1577 return Qnil; | |
1578 } | |
1579 | |
1580 Lisp_Object | |
444 | 1581 assoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1582 { |
1583 int speccount = specpdl_depth (); | |
1584 specbind (Qinhibit_quit, Qt); | |
771 | 1585 return unbind_to_1 (speccount, Fassoc (key, alist)); |
428 | 1586 } |
1587 | |
1588 DEFUN ("assq", Fassq, 2, 2, 0, /* | |
444 | 1589 Return non-nil if KEY is `eq' to the car of an element of ALIST. |
1590 The value is actually the element of ALIST whose car is KEY. | |
1591 Elements of ALIST that are not conses are ignored. | |
428 | 1592 */ |
444 | 1593 (key, alist)) |
428 | 1594 { |
444 | 1595 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1596 { |
1597 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1598 return elt; | |
1599 } | |
1600 return Qnil; | |
1601 } | |
1602 | |
1603 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /* | |
444 | 1604 Return non-nil if KEY is `old-eq' to the car of an element of ALIST. |
1605 The value is actually the element of ALIST whose car is KEY. | |
1606 Elements of ALIST that are not conses are ignored. | |
428 | 1607 This function is provided only for byte-code compatibility with v19. |
1608 Do not use it. | |
1609 */ | |
444 | 1610 (key, alist)) |
428 | 1611 { |
444 | 1612 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1613 { |
1614 if (HACKEQ_UNSAFE (key, elt_car)) | |
1615 return elt; | |
1616 } | |
1617 return Qnil; | |
1618 } | |
1619 | |
1620 /* Like Fassq but never report an error and do not allow quits. | |
1621 Use only on lists known never to be circular. */ | |
1622 | |
1623 Lisp_Object | |
444 | 1624 assq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1625 { |
1626 /* This cannot GC. */ | |
444 | 1627 LIST_LOOP_2 (elt, alist) |
428 | 1628 { |
1629 Lisp_Object elt_car = XCAR (elt); | |
1630 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1631 return elt; | |
1632 } | |
1633 return Qnil; | |
1634 } | |
1635 | |
1636 DEFUN ("rassoc", Frassoc, 2, 2, 0, /* | |
444 | 1637 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST. |
1638 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1639 */ |
444 | 1640 (value, alist)) |
428 | 1641 { |
444 | 1642 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1643 { |
444 | 1644 if (internal_equal (value, elt_cdr, 0)) |
428 | 1645 return elt; |
1646 } | |
1647 return Qnil; | |
1648 } | |
1649 | |
1650 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /* | |
444 | 1651 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST. |
1652 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1653 */ |
444 | 1654 (value, alist)) |
428 | 1655 { |
444 | 1656 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1657 { |
444 | 1658 if (internal_old_equal (value, elt_cdr, 0)) |
428 | 1659 return elt; |
1660 } | |
1661 return Qnil; | |
1662 } | |
1663 | |
1664 DEFUN ("rassq", Frassq, 2, 2, 0, /* | |
444 | 1665 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST. |
1666 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1667 */ |
444 | 1668 (value, alist)) |
428 | 1669 { |
444 | 1670 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1671 { |
444 | 1672 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1673 return elt; |
1674 } | |
1675 return Qnil; | |
1676 } | |
1677 | |
1678 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /* | |
444 | 1679 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST. |
1680 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1681 */ |
444 | 1682 (value, alist)) |
428 | 1683 { |
444 | 1684 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1685 { |
444 | 1686 if (HACKEQ_UNSAFE (value, elt_cdr)) |
428 | 1687 return elt; |
1688 } | |
1689 return Qnil; | |
1690 } | |
1691 | |
444 | 1692 /* Like Frassq, but caller must ensure that ALIST is properly |
428 | 1693 nil-terminated and ebola-free. */ |
1694 Lisp_Object | |
444 | 1695 rassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1696 { |
444 | 1697 LIST_LOOP_2 (elt, alist) |
428 | 1698 { |
1699 Lisp_Object elt_cdr = XCDR (elt); | |
444 | 1700 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1701 return elt; |
1702 } | |
1703 return Qnil; | |
1704 } | |
1705 | |
1706 | |
1707 DEFUN ("delete", Fdelete, 2, 2, 0, /* | |
1708 Delete by side effect any occurrences of ELT as a member of LIST. | |
1709 The modified LIST is returned. Comparison is done with `equal'. | |
1710 If the first member of LIST is ELT, there is no way to remove it by side | |
1711 effect; therefore, write `(setq foo (delete element foo))' to be sure | |
1712 of changing the value of `foo'. | |
1713 Also see: `remove'. | |
1714 */ | |
1715 (elt, list)) | |
1716 { | |
1717 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1718 (internal_equal (elt, list_elt, 0))); | |
1719 return list; | |
1720 } | |
1721 | |
1722 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /* | |
1723 Delete by side effect any occurrences of ELT as a member of LIST. | |
1724 The modified LIST is returned. Comparison is done with `old-equal'. | |
1725 If the first member of LIST is ELT, there is no way to remove it by side | |
1726 effect; therefore, write `(setq foo (old-delete element foo))' to be sure | |
1727 of changing the value of `foo'. | |
1728 */ | |
1729 (elt, list)) | |
1730 { | |
1731 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1732 (internal_old_equal (elt, list_elt, 0))); | |
1733 return list; | |
1734 } | |
1735 | |
1736 DEFUN ("delq", Fdelq, 2, 2, 0, /* | |
1737 Delete by side effect any occurrences of ELT as a member of LIST. | |
1738 The modified LIST is returned. Comparison is done with `eq'. | |
1739 If the first member of LIST is ELT, there is no way to remove it by side | |
1740 effect; therefore, write `(setq foo (delq element foo))' to be sure of | |
1741 changing the value of `foo'. | |
1742 */ | |
1743 (elt, list)) | |
1744 { | |
1745 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1746 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1747 return list; | |
1748 } | |
1749 | |
1750 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /* | |
1751 Delete by side effect any occurrences of ELT as a member of LIST. | |
1752 The modified LIST is returned. Comparison is done with `old-eq'. | |
1753 If the first member of LIST is ELT, there is no way to remove it by side | |
1754 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of | |
1755 changing the value of `foo'. | |
1756 */ | |
1757 (elt, list)) | |
1758 { | |
1759 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1760 (HACKEQ_UNSAFE (elt, list_elt))); | |
1761 return list; | |
1762 } | |
1763 | |
1764 /* Like Fdelq, but caller must ensure that LIST is properly | |
1765 nil-terminated and ebola-free. */ | |
1766 | |
1767 Lisp_Object | |
1768 delq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1769 { | |
1770 LIST_LOOP_DELETE_IF (list_elt, list, | |
1771 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1772 return list; | |
1773 } | |
1774 | |
1775 /* Be VERY careful with this. This is like delq_no_quit() but | |
1776 also calls free_cons() on the removed conses. You must be SURE | |
1777 that no pointers to the freed conses remain around (e.g. | |
1778 someone else is pointing to part of the list). This function | |
1779 is useful on internal lists that are used frequently and where | |
1780 the actual list doesn't escape beyond known code bounds. */ | |
1781 | |
1782 Lisp_Object | |
1783 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list) | |
1784 { | |
1785 REGISTER Lisp_Object tail = list; | |
1786 REGISTER Lisp_Object prev = Qnil; | |
1787 | |
1788 while (!NILP (tail)) | |
1789 { | |
1790 REGISTER Lisp_Object tem = XCAR (tail); | |
1791 if (EQ (elt, tem)) | |
1792 { | |
1793 Lisp_Object cons_to_free = tail; | |
1794 if (NILP (prev)) | |
1795 list = XCDR (tail); | |
1796 else | |
1797 XCDR (prev) = XCDR (tail); | |
1798 tail = XCDR (tail); | |
853 | 1799 free_cons (cons_to_free); |
428 | 1800 } |
1801 else | |
1802 { | |
1803 prev = tail; | |
1804 tail = XCDR (tail); | |
1805 } | |
1806 } | |
1807 return list; | |
1808 } | |
1809 | |
1810 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /* | |
444 | 1811 Delete by side effect any elements of ALIST whose car is `equal' to KEY. |
1812 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1813 that is `equal' to KEY, there is no way to remove it by side effect; |
1814 therefore, write `(setq foo (remassoc key foo))' to be sure of changing | |
1815 the value of `foo'. | |
1816 */ | |
444 | 1817 (key, alist)) |
428 | 1818 { |
444 | 1819 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1820 (CONSP (elt) && |
1821 internal_equal (key, XCAR (elt), 0))); | |
444 | 1822 return alist; |
428 | 1823 } |
1824 | |
1825 Lisp_Object | |
444 | 1826 remassoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1827 { |
1828 int speccount = specpdl_depth (); | |
1829 specbind (Qinhibit_quit, Qt); | |
771 | 1830 return unbind_to_1 (speccount, Fremassoc (key, alist)); |
428 | 1831 } |
1832 | |
1833 DEFUN ("remassq", Fremassq, 2, 2, 0, /* | |
444 | 1834 Delete by side effect any elements of ALIST whose car is `eq' to KEY. |
1835 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1836 that is `eq' to KEY, there is no way to remove it by side effect; |
1837 therefore, write `(setq foo (remassq key foo))' to be sure of changing | |
1838 the value of `foo'. | |
1839 */ | |
444 | 1840 (key, alist)) |
428 | 1841 { |
444 | 1842 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1843 (CONSP (elt) && |
1844 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1845 return alist; |
428 | 1846 } |
1847 | |
1848 /* no quit, no errors; be careful */ | |
1849 | |
1850 Lisp_Object | |
444 | 1851 remassq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1852 { |
444 | 1853 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1854 (CONSP (elt) && |
1855 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1856 return alist; |
428 | 1857 } |
1858 | |
1859 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /* | |
444 | 1860 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE. |
1861 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1862 that is `equal' to VALUE, there is no way to remove it by side effect; |
1863 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing | |
1864 the value of `foo'. | |
1865 */ | |
444 | 1866 (value, alist)) |
428 | 1867 { |
444 | 1868 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1869 (CONSP (elt) && |
1870 internal_equal (value, XCDR (elt), 0))); | |
444 | 1871 return alist; |
428 | 1872 } |
1873 | |
1874 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /* | |
444 | 1875 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE. |
1876 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1877 that is `eq' to VALUE, there is no way to remove it by side effect; |
1878 therefore, write `(setq foo (remrassq value foo))' to be sure of changing | |
1879 the value of `foo'. | |
1880 */ | |
444 | 1881 (value, alist)) |
428 | 1882 { |
444 | 1883 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1884 (CONSP (elt) && |
1885 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1886 return alist; |
428 | 1887 } |
1888 | |
1889 /* Like Fremrassq, fast and unsafe; be careful */ | |
1890 Lisp_Object | |
444 | 1891 remrassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1892 { |
444 | 1893 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1894 (CONSP (elt) && |
1895 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1896 return alist; |
428 | 1897 } |
1898 | |
1899 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /* | |
1900 Reverse LIST by destructively modifying cdr pointers. | |
1901 Return the beginning of the reversed list. | |
1902 Also see: `reverse'. | |
1903 */ | |
1904 (list)) | |
1905 { | |
1906 struct gcpro gcpro1, gcpro2; | |
1849 | 1907 Lisp_Object prev = Qnil; |
1908 Lisp_Object tail = list; | |
428 | 1909 |
1910 /* We gcpro our args; see `nconc' */ | |
1911 GCPRO2 (prev, tail); | |
1912 while (!NILP (tail)) | |
1913 { | |
1914 REGISTER Lisp_Object next; | |
1915 CONCHECK_CONS (tail); | |
1916 next = XCDR (tail); | |
1917 XCDR (tail) = prev; | |
1918 prev = tail; | |
1919 tail = next; | |
1920 } | |
1921 UNGCPRO; | |
1922 return prev; | |
1923 } | |
1924 | |
1925 DEFUN ("reverse", Freverse, 1, 1, 0, /* | |
1926 Reverse LIST, copying. Return the beginning of the reversed list. | |
1927 See also the function `nreverse', which is used more often. | |
1928 */ | |
1929 (list)) | |
1930 { | |
1931 Lisp_Object reversed_list = Qnil; | |
1932 EXTERNAL_LIST_LOOP_2 (elt, list) | |
1933 { | |
1934 reversed_list = Fcons (elt, reversed_list); | |
1935 } | |
1936 return reversed_list; | |
1937 } | |
1938 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1939 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1940 c_merge_predicate_key (Lisp_Object obj1, Lisp_Object obj2, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1941 Lisp_Object pred, Lisp_Object key_func) |
428 | 1942 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1943 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1944 Lisp_Object args[3]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1945 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1946 /* We could use call2() and call3() here, but we're called O(nlogn) times |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1947 for a sequence of length n, it make some sense to inline them. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1948 args[0] = key_func; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1949 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1950 args[2] = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1951 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1952 GCPRO1 (args[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1953 gcpro1.nvars = countof (args); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1954 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1955 obj1 = IGNORE_MULTIPLE_VALUES (Ffuncall (2, args)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1956 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1957 args[1] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1958 obj2 = IGNORE_MULTIPLE_VALUES (Ffuncall (2, args)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1959 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1960 args[0] = pred; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1961 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1962 args[2] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1963 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1964 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args))); |
428 | 1965 } |
1966 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1967 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1968 c_merge_predicate_nokey (Lisp_Object obj1, Lisp_Object obj2, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1969 Lisp_Object pred, Lisp_Object UNUSED (key_func)) |
428 | 1970 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1971 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1972 Lisp_Object args[3]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1973 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1974 /* This is (almost) the implementation of call2, it makes some sense to |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1975 inline it here. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1976 args[0] = pred; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1977 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1978 args[2] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1979 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1980 GCPRO1 (args[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1981 gcpro1.nvars = countof (args); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1982 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1983 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args))); |
428 | 1984 } |
1985 | |
1986 Lisp_Object | |
1987 list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1988 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1989 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1990 Lisp_Object predicate, Lisp_Object key_func) |
428 | 1991 { |
1992 Lisp_Object value; | |
1993 Lisp_Object tail; | |
1994 Lisp_Object tem; | |
1995 Lisp_Object l1, l2; | |
1996 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
1997 int looped = 0; |
428 | 1998 |
1999 l1 = org_l1; | |
2000 l2 = org_l2; | |
2001 tail = Qnil; | |
2002 value = Qnil; | |
2003 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2004 if (NULL == c_predicate) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2005 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2006 c_predicate = EQ (key_func, Qidentity) ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2007 c_merge_predicate_nokey : c_merge_predicate_key; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2008 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2009 |
428 | 2010 /* It is sufficient to protect org_l1 and org_l2. |
2011 When l1 and l2 are updated, we copy the new values | |
2012 back into the org_ vars. */ | |
2013 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2014 GCPRO4 (org_l1, org_l2, predicate, value); |
428 | 2015 |
2016 while (1) | |
2017 { | |
2018 if (NILP (l1)) | |
2019 { | |
2020 UNGCPRO; | |
2021 if (NILP (tail)) | |
2022 return l2; | |
2023 Fsetcdr (tail, l2); | |
2024 return value; | |
2025 } | |
2026 if (NILP (l2)) | |
2027 { | |
2028 UNGCPRO; | |
2029 if (NILP (tail)) | |
2030 return l1; | |
2031 Fsetcdr (tail, l1); | |
2032 return value; | |
2033 } | |
2034 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2035 if (NILP (c_predicate (Fcar (l2), Fcar (l1), predicate, key_func))) |
428 | 2036 { |
2037 tem = l1; | |
2038 l1 = Fcdr (l1); | |
2039 org_l1 = l1; | |
2040 } | |
2041 else | |
2042 { | |
2043 tem = l2; | |
2044 l2 = Fcdr (l2); | |
2045 org_l2 = l2; | |
2046 } | |
2047 if (NILP (tail)) | |
2048 value = tem; | |
2049 else | |
2050 Fsetcdr (tail, tem); | |
2051 tail = tem; | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2052 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2053 if (++looped % CIRCULAR_LIST_SUSPICION_LENGTH) continue; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2054 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2055 /* Just check the lists aren't circular:*/ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2056 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2057 EXTERNAL_LIST_LOOP_1 (l1) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2058 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2059 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2060 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2061 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2062 EXTERNAL_LIST_LOOP_1 (l2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2063 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2064 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2065 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2066 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2067 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2068 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2069 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2070 array_merge (Lisp_Object *dest, Elemcount dest_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2071 Lisp_Object *front, Elemcount front_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2072 Lisp_Object *back, Elemcount back_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2073 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2074 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2075 Lisp_Object predicate, Lisp_Object key_func) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2076 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2077 Elemcount ii, fronting, backing; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2078 Lisp_Object *front_staging = front; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2079 Lisp_Object *back_staging = back; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2080 struct gcpro gcpro1, gcpro2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2081 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2082 assert (dest_len == (back_len + front_len)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2083 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2084 if (0 == dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2085 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2086 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2087 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2088 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2089 if (front >= dest && front < (dest + dest_len)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2090 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2091 front_staging = alloca_array (Lisp_Object, front_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2092 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2093 for (ii = 0; ii < front_len; ++ii) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2094 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2095 front_staging[ii] = front[ii]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2096 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2097 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2098 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2099 if (back >= dest && back < (dest + dest_len)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2100 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2101 back_staging = alloca_array (Lisp_Object, back_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2102 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2103 for (ii = 0; ii < back_len; ++ii) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2104 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2105 back_staging[ii] = back[ii]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2106 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2107 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2108 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2109 GCPRO2 (front_staging[0], back_staging[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2110 gcpro1.nvars = front_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2111 gcpro2.nvars = back_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2112 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2113 for (ii = fronting = backing = 0; ii < dest_len; ++ii) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2114 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2115 if (fronting >= front_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2116 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2117 while (ii < dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2118 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2119 dest[ii] = back_staging[backing]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2120 ++ii, ++backing; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2121 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2122 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2123 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2124 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2125 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2126 if (backing >= back_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2127 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2128 while (ii < dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2129 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2130 dest[ii] = front_staging[fronting]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2131 ++ii, ++fronting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2132 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2133 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2134 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2135 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2136 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2137 if (NILP (c_predicate (back_staging[backing], front_staging[fronting], |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2138 predicate, key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2139 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2140 dest[ii] = front_staging[fronting]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2141 ++fronting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2142 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2143 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2144 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2145 dest[ii] = back_staging[backing]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2146 ++backing; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2147 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2148 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2149 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2150 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2151 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2152 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2153 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2154 list_array_merge_into_list (Lisp_Object list, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2155 Lisp_Object *array, Elemcount array_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2156 Lisp_Object (*c_predicate) (Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2157 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2158 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2159 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2160 Lisp_Object predicate, Lisp_Object key_func, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2161 Boolint reverse_order) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2162 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2163 Lisp_Object tail = Qnil, value = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2164 struct gcpro gcpro1, gcpro2, gcpro3; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2165 Elemcount array_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2166 int looped = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2167 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2168 GCPRO3 (list, tail, value); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2169 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2170 while (1) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2171 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2172 if (NILP (list)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2173 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2174 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2175 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2176 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2177 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2178 return Flist (array_len, array); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2179 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2180 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2181 Fsetcdr (tail, Flist (array_len - array_index, array + array_index)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2182 return value; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2183 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2184 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2185 if (array_index >= array_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2186 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2187 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2188 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2189 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2190 return list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2191 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2192 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2193 Fsetcdr (tail, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2194 return value; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2195 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2196 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2197 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2198 if (reverse_order ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2199 !NILP (c_predicate (Fcar (list), array [array_index], predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2200 key_func)) : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2201 NILP (c_predicate (array [array_index], Fcar (list), predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2202 key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2203 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2204 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2205 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2206 value = tail = list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2207 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2208 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2209 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2210 Fsetcdr (tail, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2211 tail = XCDR (tail); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2212 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2213 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2214 list = Fcdr (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2215 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2216 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2217 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2218 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2219 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2220 value = tail = Fcons (array [array_index], Qnil); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2221 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2222 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2223 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2224 Fsetcdr (tail, Fcons (array [array_index], tail)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2225 tail = XCDR (tail); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2226 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2227 ++array_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2228 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2229 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2230 if (++looped % CIRCULAR_LIST_SUSPICION_LENGTH) continue; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2231 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2232 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2233 EXTERNAL_LIST_LOOP_1 (list) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2234 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2235 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2236 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2237 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2238 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2239 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2240 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2241 list_list_merge_into_array (Lisp_Object *output, Elemcount output_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2242 Lisp_Object list_one, Lisp_Object list_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2243 Lisp_Object (*c_predicate) (Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2244 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2245 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2246 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2247 Lisp_Object predicate, Lisp_Object key_func) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2248 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2249 Elemcount output_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2250 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2251 while (output_index < output_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2252 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2253 if (NILP (list_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2254 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2255 while (output_index < output_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2256 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2257 output [output_index] = Fcar (list_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2258 list_two = Fcdr (list_two), ++output_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2259 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2260 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2261 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2262 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2263 if (NILP (list_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2264 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2265 while (output_index < output_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2266 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2267 output [output_index] = Fcar (list_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2268 list_one = Fcdr (list_one), ++output_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2269 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2270 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2271 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2272 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2273 if (NILP (c_predicate (Fcar (list_two), Fcar (list_one), predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2274 key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2275 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2276 output [output_index] = XCAR (list_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2277 list_one = XCDR (list_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2278 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2279 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2280 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2281 output [output_index] = XCAR (list_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2282 list_two = XCDR (list_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2283 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2284 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2285 ++output_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2286 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2287 /* No need to check for circularity. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2288 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2289 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2290 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2291 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2292 list_array_merge_into_array (Lisp_Object *output, Elemcount output_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2293 Lisp_Object list, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2294 Lisp_Object *array, Elemcount array_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2295 Lisp_Object (*c_predicate) (Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2296 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2297 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2298 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2299 Lisp_Object predicate, Lisp_Object key_func, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2300 Boolint reverse_order) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2301 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2302 Elemcount output_index = 0, array_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2303 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2304 while (output_index < output_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2305 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2306 if (NILP (list)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2307 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2308 if (array_len - array_index != output_len - output_index) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2309 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2310 invalid_state ("List length modified during merge", Qunbound); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2311 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2312 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2313 while (array_index < array_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2314 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2315 output [output_index++] = array [array_index++]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2316 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2317 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2318 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2319 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2320 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2321 if (array_index >= array_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2322 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2323 while (output_index < output_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2324 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2325 output [output_index++] = Fcar (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2326 list = Fcdr (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2327 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2328 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2329 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2330 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2331 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2332 if (reverse_order ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2333 !NILP (c_predicate (Fcar (list), array [array_index], predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2334 key_func)) : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2335 NILP (c_predicate (array [array_index], Fcar (list), predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2336 key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2337 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2338 output [output_index] = XCAR (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2339 list = XCDR (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2340 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2341 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2342 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2343 output [output_index] = array [array_index]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2344 ++array_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2345 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2346 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2347 ++output_index; |
428 | 2348 } |
2349 } | |
2350 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2351 #define STRING_DATA_TO_OBJECT_ARRAY(strdata, c_array, counter, len) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2352 do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2353 c_array = alloca_array (Lisp_Object, len); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2354 for (counter = 0; counter < len; ++counter) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2355 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2356 c_array[counter] = make_char (itext_ichar (strdata)); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2357 INC_IBYTEPTR (strdata); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2358 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2359 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2360 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2361 #define BIT_VECTOR_TO_OBJECT_ARRAY(v, c_array, counter, len) do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2362 c_array = alloca_array (Lisp_Object, len); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2363 for (counter = 0; counter < len; ++counter) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2364 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2365 c_array[counter] = make_int (bit_vector_bit (v, counter)); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2366 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2367 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2368 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2369 /* This macro might eventually find a better home than here. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2370 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2371 #define CHECK_KEY_ARGUMENT(key, c_predicate) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2372 do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2373 if (NILP (key)) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2374 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2375 key = Qidentity; \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2376 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2377 \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2378 if (EQ (key, Qidentity)) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2379 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2380 c_predicate = c_merge_predicate_nokey; \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2381 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2382 else \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2383 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2384 key = indirect_function (key, 1); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2385 c_predicate = c_merge_predicate_key; \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2386 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2387 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2388 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2389 DEFUN ("merge", Fmerge, 4, MANY, 0, /* |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2390 Destructively merge SEQUENCE-ONE and SEQUENCE-TWO, producing a new sequence. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2391 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2392 TYPE is the type of sequence to return. PREDICATE is a `less-than' |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2393 predicate on the elements. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2394 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2395 Optional keyword argument KEY is a function used to extract an object to be |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2396 used for comparison from each element of SEQUENCE-ONE and SEQUENCE-TWO. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2397 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2398 arguments: (TYPE SEQUENCE-ONE SEQUENCE-TWO PREDICATE &key (KEY #'IDENTITY)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2399 */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2400 (int nargs, Lisp_Object *args)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2401 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2402 Lisp_Object type = args[0], sequence_one = args[1], sequence_two = args[2], |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2403 predicate = args[3], result = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2404 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object, Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2405 Lisp_Object); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2406 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2407 PARSE_KEYWORDS (Qmerge, nargs, args, 4, 1, (key), NULL, 0); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2408 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2409 CHECK_SEQUENCE (sequence_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2410 CHECK_SEQUENCE (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2411 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2412 CHECK_KEY_ARGUMENT (key, c_predicate); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2413 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2414 if (EQ (type, Qlist) && (LISTP (sequence_one) || LISTP (sequence_two))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2415 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2416 if (NILP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2417 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2418 result = Fappend (2, args + 1); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2419 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2420 else if (NILP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2421 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2422 args[3] = Qnil; /* Overwriting PREDICATE, and losing its GC |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2423 protection, but that doesn't matter. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2424 result = Fappend (2, args + 2); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2425 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2426 else if (CONSP (sequence_one) && CONSP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2427 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2428 result = list_merge (sequence_one, sequence_two, c_predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2429 predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2430 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2431 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2432 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2433 Lisp_Object *array_storage, swap; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2434 Elemcount array_length, i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2435 Boolint reverse_order = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2436 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2437 if (!CONSP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2438 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2439 /* Make sequence_one the cons, sequence_two the array: */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2440 swap = sequence_one; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2441 sequence_one = sequence_two; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2442 sequence_two = swap; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2443 reverse_order = 1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2444 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2445 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2446 if (VECTORP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2447 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2448 array_storage = XVECTOR_DATA (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2449 array_length = XVECTOR_LENGTH (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2450 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2451 else if (STRINGP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2452 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2453 Ibyte *strdata = XSTRING_DATA (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2454 array_length = string_char_length (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2455 /* No need to GCPRO, characters are immediate. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2456 STRING_DATA_TO_OBJECT_ARRAY (strdata, array_storage, i, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2457 array_length); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2458 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2459 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2460 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2461 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2462 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2463 array_length = bit_vector_length (v); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2464 /* No need to GCPRO, fixnums are immediate. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2465 BIT_VECTOR_TO_OBJECT_ARRAY (v, array_storage, i, array_length); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2466 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2467 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2468 result = list_array_merge_into_list (sequence_one, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2469 array_storage, array_length, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2470 c_predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2471 predicate, key, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2472 reverse_order); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2473 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2474 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2475 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2476 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2477 Elemcount sequence_one_len = XINT (Flength (sequence_one)), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2478 sequence_two_len = XINT (Flength (sequence_two)), i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2479 Elemcount output_len = 1 + sequence_one_len + sequence_two_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2480 Lisp_Object *output = alloca_array (Lisp_Object, output_len), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2481 *sequence_one_storage = NULL, *sequence_two_storage = NULL; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2482 Boolint do_coerce = !(EQ (type, Qvector) || EQ (type, Qstring) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2483 || EQ (type, Qbit_vector) || EQ (type, Qlist)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2484 Ibyte *strdata = NULL; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2485 Lisp_Bit_Vector *v = NULL; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2486 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2487 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2488 output[0] = do_coerce ? Qlist : type; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2489 for (i = 1; i < output_len; ++i) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2490 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2491 output[i] = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2492 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2493 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2494 GCPRO1 (output[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2495 gcpro1.nvars = output_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2496 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2497 if (VECTORP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2498 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2499 sequence_one_storage = XVECTOR_DATA (sequence_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2500 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2501 else if (STRINGP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2502 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2503 strdata = XSTRING_DATA (sequence_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2504 STRING_DATA_TO_OBJECT_ARRAY (strdata, sequence_one_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2505 i, sequence_one_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2506 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2507 else if (BIT_VECTORP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2508 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2509 v = XBIT_VECTOR (sequence_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2510 BIT_VECTOR_TO_OBJECT_ARRAY (v, sequence_one_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2511 i, sequence_one_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2512 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2513 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2514 if (VECTORP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2515 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2516 sequence_two_storage = XVECTOR_DATA (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2517 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2518 else if (STRINGP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2519 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2520 strdata = XSTRING_DATA (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2521 STRING_DATA_TO_OBJECT_ARRAY (strdata, sequence_two_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2522 i, sequence_two_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2523 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2524 else if (BIT_VECTORP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2525 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2526 v = XBIT_VECTOR (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2527 BIT_VECTOR_TO_OBJECT_ARRAY (v, sequence_two_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2528 i, sequence_two_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2529 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2530 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2531 if (LISTP (sequence_one) && LISTP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2532 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2533 list_list_merge_into_array (output + 1, output_len - 1, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2534 sequence_one, sequence_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2535 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2536 key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2537 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2538 else if (LISTP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2539 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2540 list_array_merge_into_array (output + 1, output_len - 1, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2541 sequence_one, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2542 sequence_two_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2543 sequence_two_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2544 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2545 key, 0); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2546 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2547 else if (LISTP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2548 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2549 list_array_merge_into_array (output + 1, output_len - 1, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2550 sequence_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2551 sequence_one_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2552 sequence_one_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2553 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2554 key, 1); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2555 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2556 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2557 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2558 array_merge (output + 1, output_len - 1, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2559 sequence_one_storage, sequence_one_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2560 sequence_two_storage, sequence_two_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2561 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2562 key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2563 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2564 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2565 result = Ffuncall (output_len, output); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2566 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2567 if (do_coerce) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2568 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2569 result = call2 (Qcoerce, result, type); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2570 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2571 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2572 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2573 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2574 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2575 return result; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2576 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2577 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2578 /* The sort function should return non-nil if OBJ1 < OBJ2, nil otherwise. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2579 NOTE: This is backwards from the way qsort() works. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2580 Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2581 list_sort (Lisp_Object list, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2582 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2583 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2584 Lisp_Object predicate, Lisp_Object key_func) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2585 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2586 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2587 Lisp_Object back, tem; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2588 Lisp_Object front = list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2589 Lisp_Object len = Flength (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2590 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2591 if (XINT (len) < 2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2592 return list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2593 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2594 if (NULL == c_predicate) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2595 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2596 c_predicate = EQ (key_func, Qidentity) ? c_merge_predicate_nokey : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2597 c_merge_predicate_key; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2598 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2599 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2600 len = make_int (XINT (len) / 2 - 1); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2601 tem = Fnthcdr (len, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2602 back = Fcdr (tem); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2603 Fsetcdr (tem, Qnil); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2604 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2605 GCPRO4 (front, back, predicate, key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2606 front = list_sort (front, c_predicate, predicate, key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2607 back = list_sort (back, c_predicate, predicate, key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2608 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2609 RETURN_UNGCPRO (list_merge (front, back, c_predicate, predicate, key_func)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2610 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2611 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2612 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2613 array_sort (Lisp_Object *array, Elemcount array_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2614 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2615 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2616 Lisp_Object predicate, Lisp_Object key_func) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2617 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2618 Elemcount split; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2619 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2620 if (array_len < 2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2621 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2622 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2623 split = array_len / 2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2624 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2625 array_sort (array, split, c_predicate, predicate, key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2626 array_sort (array + split, array_len - split, c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2627 key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2628 array_merge (array, array_len, array, split, array + split, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2629 array_len - split, c_predicate, predicate, key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2630 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2631 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2632 DEFUN ("sort*", FsortX, 2, MANY, 0, /* |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2633 Sort SEQUENCE, comparing elements using PREDICATE. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2634 Returns the sorted sequence. SEQUENCE is modified by side effect. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2635 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2636 PREDICATE is called with two elements of SEQUENCE, and should return t if |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2637 the first element is `less' than the second. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2638 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2639 Optional keyword argument KEY is a function used to extract an object to be |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2640 used for comparison from each element of SEQUENCE. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2641 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2642 In this implementation, sorting is always stable; but call `stable-sort' if |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2643 this stability is important to you, other implementations may not make the |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2644 same guarantees. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2645 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2646 arguments: (SEQUENCE PREDICATE &key (KEY #'IDENTITY)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2647 */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2648 (int nargs, Lisp_Object *args)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2649 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2650 Lisp_Object sequence = args[0], predicate = args[1]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2651 Lisp_Object *sequence_carray; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2652 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object, Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2653 Lisp_Object); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2654 Elemcount sequence_len, i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2655 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2656 PARSE_KEYWORDS (QsortX, nargs, args, 2, 1, (key), NULL, 0); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2657 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2658 CHECK_SEQUENCE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2659 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2660 CHECK_KEY_ARGUMENT (key, c_predicate); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2661 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2662 if (LISTP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2663 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2664 sequence = list_sort (sequence, c_predicate, predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2665 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2666 else if (VECTORP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2667 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2668 array_sort (XVECTOR_DATA (sequence), XVECTOR_LENGTH (sequence), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2669 c_predicate, predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2670 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2671 else if (STRINGP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2672 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2673 Ibyte *strdata = XSTRING_DATA (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2674 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2675 sequence_len = string_char_length (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2676 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2677 STRING_DATA_TO_OBJECT_ARRAY (strdata, sequence_carray, i, sequence_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2678 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2679 /* No GCPRO necessary, characters are immediate. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2680 array_sort (sequence_carray, sequence_len, c_predicate, predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2681 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2682 strdata = XSTRING_DATA (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2683 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2684 CHECK_LISP_WRITEABLE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2685 for (i = 0; i < sequence_len; ++i) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2686 { |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
2687 strdata += set_itext_ichar (strdata, XCHAR (sequence_carray[i])); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2688 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2689 |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
2690 init_string_ascii_begin (sequence); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2691 bump_string_modiff (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2692 sledgehammer_check_ascii_begin (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2693 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2694 else if (BIT_VECTORP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2695 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2696 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2697 sequence_len = bit_vector_length (v); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2698 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2699 BIT_VECTOR_TO_OBJECT_ARRAY (v, sequence_carray, i, sequence_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2700 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2701 /* No GCPRO necessary, bits are immediate. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2702 array_sort (sequence_carray, sequence_len, c_predicate, predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2703 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2704 for (i = 0; i < sequence_len; ++i) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2705 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2706 set_bit_vector_bit (v, i, XINT (sequence_carray [i])); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2707 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2708 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2709 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2710 return sequence; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2711 } |
428 | 2712 |
2713 /************************************************************************/ | |
2714 /* property-list functions */ | |
2715 /************************************************************************/ | |
2716 | |
2717 /* For properties of text, we need to do order-insensitive comparison of | |
2718 plists. That is, we need to compare two plists such that they are the | |
2719 same if they have the same set of keys, and equivalent values. | |
2720 So (a 1 b 2) would be equal to (b 2 a 1). | |
2721 | |
2722 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc. | |
2723 LAXP means use `equal' for comparisons. | |
2724 */ | |
2725 int | |
2726 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
|
2727 int laxp, int depth, int foldcase) |
428 | 2728 { |
438 | 2729 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */ |
428 | 2730 int la, lb, m, i, fill; |
2731 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
|
2732 Boolbyte *flags; |
428 | 2733 Lisp_Object rest; |
2734 | |
2735 if (NILP (a) && NILP (b)) | |
2736 return 0; | |
2737 | |
2738 Fcheck_valid_plist (a); | |
2739 Fcheck_valid_plist (b); | |
2740 | |
2741 la = XINT (Flength (a)); | |
2742 lb = XINT (Flength (b)); | |
2743 m = (la > lb ? la : lb); | |
2744 fill = 0; | |
2745 keys = alloca_array (Lisp_Object, m); | |
2746 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
|
2747 flags = alloca_array (Boolbyte, m); |
428 | 2748 |
2749 /* First extract the pairs from A. */ | |
2750 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2751 { | |
2752 Lisp_Object k = XCAR (rest); | |
2753 Lisp_Object v = XCAR (XCDR (rest)); | |
2754 /* Maybe be Ebolified. */ | |
2755 if (nil_means_not_present && NILP (v)) continue; | |
2756 keys [fill] = k; | |
2757 vals [fill] = v; | |
2758 flags[fill] = 0; | |
2759 fill++; | |
2760 } | |
2761 /* Now iterate over B, and stop if we find something that's not in A, | |
2762 or that doesn't match. As we match, mark them. */ | |
2763 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2764 { | |
2765 Lisp_Object k = XCAR (rest); | |
2766 Lisp_Object v = XCAR (XCDR (rest)); | |
2767 /* Maybe be Ebolified. */ | |
2768 if (nil_means_not_present && NILP (v)) continue; | |
2769 for (i = 0; i < fill; i++) | |
2770 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2771 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
|
2772 internal_equal_0 (k, keys [i], depth, foldcase)) |
428 | 2773 { |
434 | 2774 if (eqp |
2775 /* We narrowly escaped being Ebolified here. */ | |
2776 ? !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
|
2777 : !internal_equal_0 (v, vals [i], depth, foldcase)) |
428 | 2778 /* a property in B has a different value than in A */ |
2779 goto MISMATCH; | |
2780 flags [i] = 1; | |
2781 break; | |
2782 } | |
2783 } | |
2784 if (i == fill) | |
2785 /* there are some properties in B that are not in A */ | |
2786 goto MISMATCH; | |
2787 } | |
2788 /* Now check to see that all the properties in A were also in B */ | |
2789 for (i = 0; i < fill; i++) | |
2790 if (flags [i] == 0) | |
2791 goto MISMATCH; | |
2792 | |
2793 /* Ok. */ | |
2794 return 0; | |
2795 | |
2796 MISMATCH: | |
2797 return 1; | |
2798 } | |
2799 | |
2800 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /* | |
2801 Return non-nil if property lists A and B are `eq'. | |
2802 A property list is an alternating list of keywords and values. | |
2803 This function does order-insensitive comparisons of the property lists: | |
2804 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2805 Comparison between values is done using `eq'. See also `plists-equal'. | |
2806 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2807 a nil value is ignored. This feature is a virus that has infected | |
2808 old Lisp implementations, but should not be used except for backward | |
2809 compatibility. | |
2810 */ | |
2811 (a, b, nil_means_not_present)) | |
2812 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2813 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1, 0) |
428 | 2814 ? Qnil : Qt); |
2815 } | |
2816 | |
2817 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /* | |
2818 Return non-nil if property lists A and B are `equal'. | |
2819 A property list is an alternating list of keywords and values. This | |
2820 function does order-insensitive comparisons of the property lists: For | |
2821 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2822 Comparison between values is done using `equal'. See also `plists-eq'. | |
2823 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2824 a nil value is ignored. This feature is a virus that has infected | |
2825 old Lisp implementations, but should not be used except for backward | |
2826 compatibility. | |
2827 */ | |
2828 (a, b, nil_means_not_present)) | |
2829 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2830 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1, 0) |
428 | 2831 ? Qnil : Qt); |
2832 } | |
2833 | |
2834 | |
2835 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /* | |
2836 Return non-nil if lax property lists A and B are `eq'. | |
2837 A property list is an alternating list of keywords and values. | |
2838 This function does order-insensitive comparisons of the property lists: | |
2839 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2840 Comparison between values is done using `eq'. See also `plists-equal'. | |
2841 A lax property list is like a regular one except that comparisons between | |
2842 keywords is done using `equal' instead of `eq'. | |
2843 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2844 a nil value is ignored. This feature is a virus that has infected | |
2845 old Lisp implementations, but should not be used except for backward | |
2846 compatibility. | |
2847 */ | |
2848 (a, b, nil_means_not_present)) | |
2849 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2850 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1, 0) |
428 | 2851 ? Qnil : Qt); |
2852 } | |
2853 | |
2854 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /* | |
2855 Return non-nil if lax property lists A and B are `equal'. | |
2856 A property list is an alternating list of keywords and values. This | |
2857 function does order-insensitive comparisons of the property lists: For | |
2858 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2859 Comparison between values is done using `equal'. See also `plists-eq'. | |
2860 A lax property list is like a regular one except that comparisons between | |
2861 keywords is done using `equal' instead of `eq'. | |
2862 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2863 a nil value is ignored. This feature is a virus that has infected | |
2864 old Lisp implementations, but should not be used except for backward | |
2865 compatibility. | |
2866 */ | |
2867 (a, b, nil_means_not_present)) | |
2868 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2869 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1, 0) |
428 | 2870 ? Qnil : Qt); |
2871 } | |
2872 | |
2873 /* Return the value associated with key PROPERTY in property list PLIST. | |
2874 Return nil if key not found. This function is used for internal | |
2875 property lists that cannot be directly manipulated by the user. | |
2876 */ | |
2877 | |
2878 Lisp_Object | |
2879 internal_plist_get (Lisp_Object plist, Lisp_Object property) | |
2880 { | |
2881 Lisp_Object tail; | |
2882 | |
2883 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2884 { | |
2885 if (EQ (XCAR (tail), property)) | |
2886 return XCAR (XCDR (tail)); | |
2887 } | |
2888 | |
2889 return Qunbound; | |
2890 } | |
2891 | |
2892 /* Set PLIST's value for PROPERTY to VALUE. Analogous to | |
2893 internal_plist_get(). */ | |
2894 | |
2895 void | |
2896 internal_plist_put (Lisp_Object *plist, Lisp_Object property, | |
2897 Lisp_Object value) | |
2898 { | |
2899 Lisp_Object tail; | |
2900 | |
2901 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2902 { | |
2903 if (EQ (XCAR (tail), property)) | |
2904 { | |
2905 XCAR (XCDR (tail)) = value; | |
2906 return; | |
2907 } | |
2908 } | |
2909 | |
2910 *plist = Fcons (property, Fcons (value, *plist)); | |
2911 } | |
2912 | |
2913 int | |
2914 internal_remprop (Lisp_Object *plist, Lisp_Object property) | |
2915 { | |
2916 Lisp_Object tail, prev; | |
2917 | |
2918 for (tail = *plist, prev = Qnil; | |
2919 !NILP (tail); | |
2920 tail = XCDR (XCDR (tail))) | |
2921 { | |
2922 if (EQ (XCAR (tail), property)) | |
2923 { | |
2924 if (NILP (prev)) | |
2925 *plist = XCDR (XCDR (tail)); | |
2926 else | |
2927 XCDR (XCDR (prev)) = XCDR (XCDR (tail)); | |
2928 return 1; | |
2929 } | |
2930 else | |
2931 prev = tail; | |
2932 } | |
2933 | |
2934 return 0; | |
2935 } | |
2936 | |
2937 /* Called on a malformed property list. BADPLACE should be some | |
2938 place where truncating will form a good list -- i.e. we shouldn't | |
2939 result in a list with an odd length. */ | |
2940 | |
2941 static Lisp_Object | |
578 | 2942 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2943 { |
2944 if (ERRB_EQ (errb, ERROR_ME)) | |
2945 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace)); | |
2946 else | |
2947 { | |
2948 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2949 { | |
2950 warn_when_safe_lispobj | |
2951 (Qlist, Qwarning, | |
771 | 2952 list2 (build_msg_string |
428 | 2953 ("Malformed property list -- list has been truncated"), |
2954 *plist)); | |
793 | 2955 /* #### WARNING: This is more dangerous than it seems; perhaps |
2956 not a good idea. It also violates the principle of least | |
2957 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2958 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2959 *badplace = Qnil; |
2960 } | |
2961 return Qunbound; | |
2962 } | |
2963 } | |
2964 | |
2965 /* Called on a circular property list. BADPLACE should be some place | |
2966 where truncating will result in an even-length list, as above. | |
2967 If doesn't particularly matter where we truncate -- anywhere we | |
2968 truncate along the entire list will break the circularity, because | |
2969 it will create a terminus and the list currently doesn't have one. | |
2970 */ | |
2971 | |
2972 static Lisp_Object | |
578 | 2973 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2974 { |
2975 if (ERRB_EQ (errb, ERROR_ME)) | |
2976 return Fsignal (Qcircular_property_list, list1 (*plist)); | |
2977 else | |
2978 { | |
2979 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2980 { | |
2981 warn_when_safe_lispobj | |
2982 (Qlist, Qwarning, | |
771 | 2983 list2 (build_msg_string |
428 | 2984 ("Circular property list -- list has been truncated"), |
2985 *plist)); | |
793 | 2986 /* #### WARNING: This is more dangerous than it seems; perhaps |
2987 not a good idea. It also violates the principle of least | |
2988 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2989 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2990 *badplace = Qnil; |
2991 } | |
2992 return Qunbound; | |
2993 } | |
2994 } | |
2995 | |
2996 /* Advance the tortoise pointer by two (one iteration of a property-list | |
2997 loop) and the hare pointer by four and verify that no malformations | |
2998 or circularities exist. If so, return zero and store a value into | |
2999 RETVAL that should be returned by the calling function. Otherwise, | |
3000 return 1. See external_plist_get(). | |
3001 */ | |
3002 | |
3003 static int | |
3004 advance_plist_pointers (Lisp_Object *plist, | |
3005 Lisp_Object **tortoise, Lisp_Object **hare, | |
578 | 3006 Error_Behavior errb, Lisp_Object *retval) |
428 | 3007 { |
3008 int i; | |
3009 Lisp_Object *tortsave = *tortoise; | |
3010 | |
3011 /* Note that our "fixing" may be more brutal than necessary, | |
3012 but it's the user's own problem, not ours, if they went in and | |
3013 manually fucked up a plist. */ | |
3014 | |
3015 for (i = 0; i < 2; i++) | |
3016 { | |
3017 /* This is a standard iteration of a defensive-loop-checking | |
3018 loop. We just do it twice because we want to advance past | |
3019 both the property and its value. | |
3020 | |
3021 If the pointer indirection is confusing you, remember that | |
3022 one level of indirection on the hare and tortoise pointers | |
3023 is only due to pass-by-reference for this function. The other | |
3024 level is so that the plist can be fixed in place. */ | |
3025 | |
3026 /* When we reach the end of a well-formed plist, **HARE is | |
3027 nil. In that case, we don't do anything at all except | |
3028 advance TORTOISE by one. Otherwise, we advance HARE | |
3029 by two (making sure it's OK to do so), then advance | |
3030 TORTOISE by one (it will always be OK to do so because | |
3031 the HARE is always ahead of the TORTOISE and will have | |
3032 already verified the path), then make sure TORTOISE and | |
3033 HARE don't contain the same non-nil object -- if the | |
3034 TORTOISE and the HARE ever meet, then obviously we're | |
3035 in a circularity, and if we're in a circularity, then | |
3036 the TORTOISE and the HARE can't cross paths without | |
3037 meeting, since the HARE only gains one step over the | |
3038 TORTOISE per iteration. */ | |
3039 | |
3040 if (!NILP (**hare)) | |
3041 { | |
3042 Lisp_Object *haresave = *hare; | |
3043 if (!CONSP (**hare)) | |
3044 { | |
3045 *retval = bad_bad_bunny (plist, haresave, errb); | |
3046 return 0; | |
3047 } | |
3048 *hare = &XCDR (**hare); | |
3049 /* In a non-plist, we'd check here for a nil value for | |
3050 **HARE, which is OK (it just means the list has an | |
3051 odd number of elements). In a plist, it's not OK | |
3052 for the list to have an odd number of elements. */ | |
3053 if (!CONSP (**hare)) | |
3054 { | |
3055 *retval = bad_bad_bunny (plist, haresave, errb); | |
3056 return 0; | |
3057 } | |
3058 *hare = &XCDR (**hare); | |
3059 } | |
3060 | |
3061 *tortoise = &XCDR (**tortoise); | |
3062 if (!NILP (**hare) && EQ (**tortoise, **hare)) | |
3063 { | |
3064 *retval = bad_bad_turtle (plist, tortsave, errb); | |
3065 return 0; | |
3066 } | |
3067 } | |
3068 | |
3069 return 1; | |
3070 } | |
3071 | |
3072 /* Return the value of PROPERTY from PLIST, or Qunbound if | |
3073 property is not on the list. | |
3074 | |
3075 PLIST is a Lisp-accessible property list, meaning that it | |
3076 has to be checked for malformations and circularities. | |
3077 | |
3078 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the | |
3079 function will never signal an error; and if ERRB is ERROR_ME_WARN, | |
3080 on finding a malformation or a circularity, it issues a warning and | |
3081 attempts to silently fix the problem. | |
3082 | |
3083 A pointer to PLIST is passed in so that PLIST can be successfully | |
3084 "fixed" even if the error is at the beginning of the plist. */ | |
3085 | |
3086 Lisp_Object | |
3087 external_plist_get (Lisp_Object *plist, Lisp_Object property, | |
578 | 3088 int laxp, Error_Behavior errb) |
428 | 3089 { |
3090 Lisp_Object *tortoise = plist; | |
3091 Lisp_Object *hare = plist; | |
3092 | |
3093 while (!NILP (*tortoise)) | |
3094 { | |
3095 Lisp_Object *tortsave = tortoise; | |
3096 Lisp_Object retval; | |
3097 | |
3098 /* We do the standard tortoise/hare march. We isolate the | |
3099 grungy stuff to do this in advance_plist_pointers(), though. | |
3100 To us, all this function does is advance the tortoise | |
3101 pointer by two and the hare pointer by four and make sure | |
3102 everything's OK. We first advance the pointers and then | |
3103 check if a property matched; this ensures that our | |
3104 check for a matching property is safe. */ | |
3105 | |
3106 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3107 return retval; | |
3108 | |
3109 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3110 : internal_equal (XCAR (*tortsave), property, 0)) | |
3111 return XCAR (XCDR (*tortsave)); | |
3112 } | |
3113 | |
3114 return Qunbound; | |
3115 } | |
3116 | |
3117 /* Set PLIST's value for PROPERTY to VALUE, given a possibly | |
3118 malformed or circular plist. Analogous to external_plist_get(). */ | |
3119 | |
3120 void | |
3121 external_plist_put (Lisp_Object *plist, Lisp_Object property, | |
578 | 3122 Lisp_Object value, int laxp, Error_Behavior errb) |
428 | 3123 { |
3124 Lisp_Object *tortoise = plist; | |
3125 Lisp_Object *hare = plist; | |
3126 | |
3127 while (!NILP (*tortoise)) | |
3128 { | |
3129 Lisp_Object *tortsave = tortoise; | |
3130 Lisp_Object retval; | |
3131 | |
3132 /* See above */ | |
3133 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3134 return; | |
3135 | |
3136 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3137 : internal_equal (XCAR (*tortsave), property, 0)) | |
3138 { | |
3139 XCAR (XCDR (*tortsave)) = value; | |
3140 return; | |
3141 } | |
3142 } | |
3143 | |
3144 *plist = Fcons (property, Fcons (value, *plist)); | |
3145 } | |
3146 | |
3147 int | |
3148 external_remprop (Lisp_Object *plist, Lisp_Object property, | |
578 | 3149 int laxp, Error_Behavior errb) |
428 | 3150 { |
3151 Lisp_Object *tortoise = plist; | |
3152 Lisp_Object *hare = plist; | |
3153 | |
3154 while (!NILP (*tortoise)) | |
3155 { | |
3156 Lisp_Object *tortsave = tortoise; | |
3157 Lisp_Object retval; | |
3158 | |
3159 /* See above */ | |
3160 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3161 return 0; | |
3162 | |
3163 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3164 : internal_equal (XCAR (*tortsave), property, 0)) | |
3165 { | |
3166 /* Now you see why it's so convenient to have that level | |
3167 of indirection. */ | |
3168 *tortsave = XCDR (XCDR (*tortsave)); | |
3169 return 1; | |
3170 } | |
3171 } | |
3172 | |
3173 return 0; | |
3174 } | |
3175 | |
3176 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /* | |
3177 Extract a value from a property list. | |
3178 PLIST is a property list, which is a list of the form | |
444 | 3179 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...). |
3180 PROPERTY is usually a symbol. | |
3181 This function returns the value corresponding to the PROPERTY, | |
3182 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 3183 */ |
444 | 3184 (plist, property, default_)) |
428 | 3185 { |
444 | 3186 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME); |
3187 return UNBOUNDP (value) ? default_ : value; | |
428 | 3188 } |
3189 | |
3190 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /* | |
444 | 3191 Change value in PLIST of PROPERTY to VALUE. |
3192 PLIST is a property list, which is a list of the form | |
3193 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
3194 PROPERTY is usually a symbol and VALUE is any object. | |
3195 If PROPERTY is already a property on the list, its value is set to VALUE, | |
3196 otherwise the new PROPERTY VALUE pair is added. | |
3197 The new plist is returned; use `(setq x (plist-put x property value))' | |
3198 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 3199 */ |
444 | 3200 (plist, property, value)) |
428 | 3201 { |
444 | 3202 external_plist_put (&plist, property, value, 0, ERROR_ME); |
428 | 3203 return plist; |
3204 } | |
3205 | |
3206 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /* | |
444 | 3207 Remove from PLIST the property PROPERTY and its value. |
3208 PLIST is a property list, which is a list of the form | |
3209 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
3210 PROPERTY is usually a symbol. | |
3211 The new plist is returned; use `(setq x (plist-remprop x property))' | |
3212 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 3213 */ |
444 | 3214 (plist, property)) |
428 | 3215 { |
444 | 3216 external_remprop (&plist, property, 0, ERROR_ME); |
428 | 3217 return plist; |
3218 } | |
3219 | |
3220 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /* | |
444 | 3221 Return t if PROPERTY has a value specified in PLIST. |
428 | 3222 */ |
444 | 3223 (plist, property)) |
428 | 3224 { |
444 | 3225 Lisp_Object value = Fplist_get (plist, property, Qunbound); |
3226 return UNBOUNDP (value) ? Qnil : Qt; | |
428 | 3227 } |
3228 | |
3229 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /* | |
3230 Given a plist, signal an error if there is anything wrong with it. | |
3231 This means that it's a malformed or circular plist. | |
3232 */ | |
3233 (plist)) | |
3234 { | |
3235 Lisp_Object *tortoise; | |
3236 Lisp_Object *hare; | |
3237 | |
3238 start_over: | |
3239 tortoise = &plist; | |
3240 hare = &plist; | |
3241 while (!NILP (*tortoise)) | |
3242 { | |
3243 Lisp_Object retval; | |
3244 | |
3245 /* See above */ | |
3246 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME, | |
3247 &retval)) | |
3248 goto start_over; | |
3249 } | |
3250 | |
3251 return Qnil; | |
3252 } | |
3253 | |
3254 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /* | |
3255 Given a plist, return non-nil if its format is correct. | |
3256 If it returns nil, `check-valid-plist' will signal an error when given | |
442 | 3257 the plist; that means it's a malformed or circular plist. |
428 | 3258 */ |
3259 (plist)) | |
3260 { | |
3261 Lisp_Object *tortoise; | |
3262 Lisp_Object *hare; | |
3263 | |
3264 tortoise = &plist; | |
3265 hare = &plist; | |
3266 while (!NILP (*tortoise)) | |
3267 { | |
3268 Lisp_Object retval; | |
3269 | |
3270 /* See above */ | |
3271 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT, | |
3272 &retval)) | |
3273 return Qnil; | |
3274 } | |
3275 | |
3276 return Qt; | |
3277 } | |
3278 | |
3279 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /* | |
3280 Destructively remove any duplicate entries from a plist. | |
3281 In such cases, the first entry applies. | |
3282 | |
3283 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3284 a nil value is removed. This feature is a virus that has infected | |
3285 old Lisp implementations, but should not be used except for backward | |
3286 compatibility. | |
3287 | |
3288 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
3289 return value may not be EQ to the passed-in value, so make sure to | |
3290 `setq' the value back into where it came from. | |
3291 */ | |
3292 (plist, nil_means_not_present)) | |
3293 { | |
3294 Lisp_Object head = plist; | |
3295 | |
3296 Fcheck_valid_plist (plist); | |
3297 | |
3298 while (!NILP (plist)) | |
3299 { | |
3300 Lisp_Object prop = Fcar (plist); | |
3301 Lisp_Object next = Fcdr (plist); | |
3302 | |
3303 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
3304 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
3305 { | |
3306 if (EQ (head, plist)) | |
3307 head = Fcdr (next); | |
3308 plist = Fcdr (next); | |
3309 continue; | |
3310 } | |
3311 /* external_remprop returns 1 if it removed any property. | |
3312 We have to loop till it didn't remove anything, in case | |
3313 the property occurs many times. */ | |
3314 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME)) | |
3315 DO_NOTHING; | |
3316 plist = Fcdr (next); | |
3317 } | |
3318 | |
3319 return head; | |
3320 } | |
3321 | |
3322 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /* | |
3323 Extract a value from a lax property list. | |
444 | 3324 LAX-PLIST is a lax property list, which is a list of the form |
3325 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3326 properties is done using `equal' instead of `eq'. | |
3327 PROPERTY is usually a symbol. | |
3328 This function returns the value corresponding to PROPERTY, | |
3329 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 3330 */ |
444 | 3331 (lax_plist, property, default_)) |
428 | 3332 { |
444 | 3333 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME); |
3334 return UNBOUNDP (value) ? default_ : value; | |
428 | 3335 } |
3336 | |
3337 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /* | |
444 | 3338 Change value in LAX-PLIST of PROPERTY to VALUE. |
3339 LAX-PLIST is a lax property list, which is a list of the form | |
3340 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3341 properties is done using `equal' instead of `eq'. | |
3342 PROPERTY is usually a symbol and VALUE is any object. | |
3343 If PROPERTY is already a property on the list, its value is set to | |
3344 VALUE, otherwise the new PROPERTY VALUE pair is added. | |
3345 The new plist is returned; use `(setq x (lax-plist-put x property value))' | |
3346 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 3347 */ |
444 | 3348 (lax_plist, property, value)) |
428 | 3349 { |
444 | 3350 external_plist_put (&lax_plist, property, value, 1, ERROR_ME); |
428 | 3351 return lax_plist; |
3352 } | |
3353 | |
3354 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /* | |
444 | 3355 Remove from LAX-PLIST the property PROPERTY and its value. |
3356 LAX-PLIST is a lax property list, which is a list of the form | |
3357 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3358 properties is done using `equal' instead of `eq'. | |
3359 PROPERTY is usually a symbol. | |
3360 The new plist is returned; use `(setq x (lax-plist-remprop x property))' | |
3361 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 3362 */ |
444 | 3363 (lax_plist, property)) |
428 | 3364 { |
444 | 3365 external_remprop (&lax_plist, property, 1, ERROR_ME); |
428 | 3366 return lax_plist; |
3367 } | |
3368 | |
3369 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /* | |
444 | 3370 Return t if PROPERTY has a value specified in LAX-PLIST. |
3371 LAX-PLIST is a lax property list, which is a list of the form | |
3372 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3373 properties is done using `equal' instead of `eq'. | |
428 | 3374 */ |
444 | 3375 (lax_plist, property)) |
428 | 3376 { |
444 | 3377 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt; |
428 | 3378 } |
3379 | |
3380 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /* | |
3381 Destructively remove any duplicate entries from a lax plist. | |
3382 In such cases, the first entry applies. | |
3383 | |
3384 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3385 a nil value is removed. This feature is a virus that has infected | |
3386 old Lisp implementations, but should not be used except for backward | |
3387 compatibility. | |
3388 | |
3389 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
3390 return value may not be EQ to the passed-in value, so make sure to | |
3391 `setq' the value back into where it came from. | |
3392 */ | |
3393 (lax_plist, nil_means_not_present)) | |
3394 { | |
3395 Lisp_Object head = lax_plist; | |
3396 | |
3397 Fcheck_valid_plist (lax_plist); | |
3398 | |
3399 while (!NILP (lax_plist)) | |
3400 { | |
3401 Lisp_Object prop = Fcar (lax_plist); | |
3402 Lisp_Object next = Fcdr (lax_plist); | |
3403 | |
3404 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
3405 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
3406 { | |
3407 if (EQ (head, lax_plist)) | |
3408 head = Fcdr (next); | |
3409 lax_plist = Fcdr (next); | |
3410 continue; | |
3411 } | |
3412 /* external_remprop returns 1 if it removed any property. | |
3413 We have to loop till it didn't remove anything, in case | |
3414 the property occurs many times. */ | |
3415 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME)) | |
3416 DO_NOTHING; | |
3417 lax_plist = Fcdr (next); | |
3418 } | |
3419 | |
3420 return head; | |
3421 } | |
3422 | |
3423 /* In C because the frame props stuff uses it */ | |
3424 | |
3425 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /* | |
3426 Convert association list ALIST into the equivalent property-list form. | |
3427 The plist is returned. This converts from | |
3428 | |
3429 \((a . 1) (b . 2) (c . 3)) | |
3430 | |
3431 into | |
3432 | |
3433 \(a 1 b 2 c 3) | |
3434 | |
3435 The original alist is destroyed in the process of constructing the plist. | |
3436 See also `alist-to-plist'. | |
3437 */ | |
3438 (alist)) | |
3439 { | |
3440 Lisp_Object head = alist; | |
3441 while (!NILP (alist)) | |
3442 { | |
3443 /* remember the alist element. */ | |
3444 Lisp_Object el = Fcar (alist); | |
3445 | |
3446 Fsetcar (alist, Fcar (el)); | |
3447 Fsetcar (el, Fcdr (el)); | |
3448 Fsetcdr (el, Fcdr (alist)); | |
3449 Fsetcdr (alist, el); | |
3450 alist = Fcdr (Fcdr (alist)); | |
3451 } | |
3452 | |
3453 return head; | |
3454 } | |
3455 | |
3456 DEFUN ("get", Fget, 2, 3, 0, /* | |
442 | 3457 Return the value of OBJECT's PROPERTY property. |
3458 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'. | |
428 | 3459 If there is no such property, return optional third arg DEFAULT |
442 | 3460 \(which defaults to `nil'). OBJECT can be a symbol, string, extent, |
3461 face, or glyph. See also `put', `remprop', and `object-plist'. | |
428 | 3462 */ |
442 | 3463 (object, property, default_)) |
428 | 3464 { |
3465 /* Various places in emacs call Fget() and expect it not to quit, | |
3466 so don't quit. */ | |
442 | 3467 Lisp_Object val; |
3468 | |
3469 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop) | |
3470 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property); | |
428 | 3471 else |
563 | 3472 invalid_operation ("Object type has no properties", object); |
442 | 3473 |
3474 return UNBOUNDP (val) ? default_ : val; | |
428 | 3475 } |
3476 | |
3477 DEFUN ("put", Fput, 3, 3, 0, /* | |
442 | 3478 Set OBJECT's PROPERTY to VALUE. |
3479 It can be subsequently retrieved with `(get OBJECT PROPERTY)'. | |
3480 OBJECT can be a symbol, face, extent, or string. | |
428 | 3481 For a string, no properties currently have predefined meanings. |
3482 For the predefined properties for extents, see `set-extent-property'. | |
3483 For the predefined properties for faces, see `set-face-property'. | |
3484 See also `get', `remprop', and `object-plist'. | |
3485 */ | |
442 | 3486 (object, property, value)) |
428 | 3487 { |
1920 | 3488 /* This function cannot GC */ |
428 | 3489 CHECK_LISP_WRITEABLE (object); |
3490 | |
442 | 3491 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop) |
428 | 3492 { |
442 | 3493 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop |
3494 (object, property, value)) | |
563 | 3495 invalid_change ("Can't set property on object", property); |
428 | 3496 } |
3497 else | |
563 | 3498 invalid_change ("Object type has no settable properties", object); |
428 | 3499 |
3500 return value; | |
3501 } | |
3502 | |
3503 DEFUN ("remprop", Fremprop, 2, 2, 0, /* | |
442 | 3504 Remove, from OBJECT's property list, PROPERTY and its corresponding value. |
3505 OBJECT can be a symbol, string, extent, face, or glyph. Return non-nil | |
3506 if the property list was actually modified (i.e. if PROPERTY was present | |
3507 in the property list). See also `get', `put', and `object-plist'. | |
428 | 3508 */ |
442 | 3509 (object, property)) |
428 | 3510 { |
442 | 3511 int ret = 0; |
3512 | |
428 | 3513 CHECK_LISP_WRITEABLE (object); |
3514 | |
442 | 3515 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop) |
428 | 3516 { |
442 | 3517 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property); |
3518 if (ret == -1) | |
563 | 3519 invalid_change ("Can't remove property from object", property); |
428 | 3520 } |
3521 else | |
563 | 3522 invalid_change ("Object type has no removable properties", object); |
442 | 3523 |
3524 return ret ? Qt : Qnil; | |
428 | 3525 } |
3526 | |
3527 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /* | |
442 | 3528 Return a property list of OBJECT's properties. |
3529 For a symbol, this is equivalent to `symbol-plist'. | |
3530 OBJECT can be a symbol, string, extent, face, or glyph. | |
3531 Do not modify the returned property list directly; | |
3532 this may or may not have the desired effects. Use `put' instead. | |
428 | 3533 */ |
3534 (object)) | |
3535 { | |
442 | 3536 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist) |
3537 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object); | |
428 | 3538 else |
563 | 3539 invalid_operation ("Object type has no properties", object); |
428 | 3540 |
3541 return Qnil; | |
3542 } | |
3543 | |
3544 | |
853 | 3545 static Lisp_Object |
3546 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2, | |
3547 Lisp_Object depth) | |
3548 { | |
3549 return make_int (internal_equal (obj1, obj2, XINT (depth))); | |
3550 } | |
3551 | |
3552 int | |
3553 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
|
3554 const Ascbyte *warning_string, |
853 | 3555 int flags, |
3556 struct call_trapping_problems_result *p, | |
3557 int retval, | |
3558 Lisp_Object obj1, Lisp_Object obj2, | |
3559 int depth) | |
3560 { | |
3561 Lisp_Object glorp = | |
3562 va_call_trapping_problems (warning_class, warning_string, | |
3563 flags, p, | |
3564 (lisp_fn_t) tweaked_internal_equal, | |
3565 3, obj1, obj2, make_int (depth)); | |
3566 if (UNBOUNDP (glorp)) | |
3567 return retval; | |
3568 else | |
3569 return XINT (glorp); | |
3570 } | |
3571 | |
428 | 3572 int |
3573 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3574 { | |
3575 if (depth > 200) | |
563 | 3576 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3577 QUIT; |
3578 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
3579 return 1; | |
3580 /* Note that (equal 20 20.0) should be nil */ | |
3581 if (XTYPE (obj1) != XTYPE (obj2)) | |
3582 return 0; | |
3583 if (LRECORDP (obj1)) | |
3584 { | |
442 | 3585 const struct lrecord_implementation |
428 | 3586 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), |
3587 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3588 | |
3589 return (imp1 == imp2) && | |
3590 /* 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
|
3591 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 0)); |
428 | 3592 } |
3593 | |
3594 return 0; | |
3595 } | |
3596 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3597 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
|
3598 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3599 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
|
3600 ARRAY_STRING, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3601 ARRAY_VECTOR, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3602 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
|
3603 }; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3604 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3605 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
|
3606 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
|
3607 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3608 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
|
3609 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
|
3610 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
|
3611 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
|
3612 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
|
3613 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
|
3614 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
|
3615 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3616 |
801 | 3617 int |
3618 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3619 { | |
3620 if (depth > 200) | |
3621 stack_overflow ("Stack overflow in equalp", Qunbound); | |
3622 QUIT; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3623 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3624 /* 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
|
3625 of two equal fixnums or the same object seen twice. */ |
801 | 3626 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) |
3627 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
|
3628 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3629 /* 2. If both numbers, compare with `='. */ |
1983 | 3630 if (NUMBERP (obj1) && NUMBERP (obj2)) |
3631 { | |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
3632 return (0 == bytecode_arithcompare (obj1, obj2)); |
1983 | 3633 } |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3634 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3635 /* 3. If characters, compare case-insensitively. */ |
801 | 3636 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
|
3637 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
|
3638 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3639 /* 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
|
3640 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
|
3641 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3642 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
|
3643 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
|
3644 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
|
3645 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
|
3646 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3647 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
|
3648 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
|
3649 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
|
3650 /* 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
|
3651 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
|
3652 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3653 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
|
3654 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
|
3655 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
|
3656 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3657 return 1; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3658 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3659 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3660 /* 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
|
3661 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
|
3662 their contents, the equal() method will call internal_equal_0(). */ |
801 | 3663 if (XTYPE (obj1) != XTYPE (obj2)) |
3664 return 0; | |
3665 if (LRECORDP (obj1)) | |
3666 { | |
3667 const struct lrecord_implementation | |
3668 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), | |
3669 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3670 | |
3671 return (imp1 == imp2) && | |
3672 /* 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
|
3673 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 1)); |
801 | 3674 } |
3675 | |
3676 return 0; | |
3677 } | |
3678 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3679 int |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3680 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
|
3681 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3682 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3683 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
|
3684 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3685 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
|
3686 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3687 |
428 | 3688 /* Note that we may be calling sub-objects that will use |
3689 internal_equal() (instead of internal_old_equal()). Oh well. | |
3690 We will get an Ebola note if there's any possibility of confusion, | |
3691 but that seems unlikely. */ | |
3692 | |
3693 static int | |
3694 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3695 { | |
3696 if (depth > 200) | |
563 | 3697 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3698 QUIT; |
3699 if (HACKEQ_UNSAFE (obj1, obj2)) | |
3700 return 1; | |
3701 /* Note that (equal 20 20.0) should be nil */ | |
3702 if (XTYPE (obj1) != XTYPE (obj2)) | |
3703 return 0; | |
3704 | |
3705 return internal_equal (obj1, obj2, depth); | |
3706 } | |
3707 | |
3708 DEFUN ("equal", Fequal, 2, 2, 0, /* | |
3709 Return t if two Lisp objects have similar structure and contents. | |
3710 They must have the same data type. | |
3711 Conses are compared by comparing the cars and the cdrs. | |
3712 Vectors and strings are compared element by element. | |
3713 Numbers are compared by value. Symbols must match exactly. | |
3714 */ | |
444 | 3715 (object1, object2)) |
428 | 3716 { |
444 | 3717 return internal_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3718 } |
3719 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3720 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
|
3721 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
|
3722 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3723 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
|
3724 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
|
3725 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
|
3726 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3727 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
|
3728 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
|
3729 `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
|
3730 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3731 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
|
3732 `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
|
3733 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
|
3734 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
|
3735 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
|
3736 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
|
3737 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
|
3738 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
|
3739 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3740 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
|
3741 (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
|
3742 `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
|
3743 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
|
3744 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
|
3745 */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3746 (object1, object2)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3747 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3748 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
|
3749 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3750 |
428 | 3751 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* |
3752 Return t if two Lisp objects have similar structure and contents. | |
3753 They must have the same data type. | |
3754 \(Note, however, that an exception is made for characters and integers; | |
3755 this is known as the "char-int confoundance disease." See `eq' and | |
3756 `old-eq'.) | |
3757 This function is provided only for byte-code compatibility with v19. | |
3758 Do not use it. | |
3759 */ | |
444 | 3760 (object1, object2)) |
428 | 3761 { |
444 | 3762 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3763 } |
3764 | |
3765 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3766 DEFUN ("fill", Ffill, 2, MANY, 0, /* |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3767 Destructively modify SEQUENCE by replacing each element with ITEM. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3768 SEQUENCE is a list, vector, bit vector, or string. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3769 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3770 Optional keyword START is the index of the first element of SEQUENCE |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3771 to be modified, and defaults to zero. Optional keyword END is the |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3772 exclusive upper bound on the elements of SEQUENCE to be modified, and |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3773 defaults to the length of SEQUENCE. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3774 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3775 arguments: (SEQUENCE ITEM &key (START 0) END) |
428 | 3776 */ |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3777 (int nargs, Lisp_Object *args)) |
428 | 3778 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3779 Lisp_Object sequence = args[0]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3780 Lisp_Object item = args[1]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3781 Elemcount starting = 0, ending = EMACS_INT_MAX, ii; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3782 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3783 PARSE_KEYWORDS (Qfill, nargs, args, 2, 2, (start, end), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3784 (start = Qzero, end = Qunbound), 0); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3785 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3786 CHECK_NATNUM (start); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3787 starting = XINT (start); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3788 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3789 if (!UNBOUNDP (end)) |
428 | 3790 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3791 CHECK_NATNUM (end); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3792 ending = XINT (end); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3793 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3794 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3795 retry: |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3796 if (STRINGP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3797 { |
5187
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3798 Bytecount prefix_bytecount, item_bytecount, delta; |
867 | 3799 Ibyte item_buf[MAX_ICHAR_LEN]; |
5187
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3800 Ibyte *p, *pend; |
434 | 3801 |
428 | 3802 CHECK_CHAR_COERCE_INT (item); |
2720 | 3803 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3804 CHECK_LISP_WRITEABLE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3805 sledgehammer_check_ascii_begin (sequence); |
867 | 3806 item_bytecount = set_itext_ichar (item_buf, XCHAR (item)); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3807 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3808 p = XSTRING_DATA (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3809 p = (Ibyte *) itext_n_addr (p, starting); |
5187
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3810 prefix_bytecount = p - XSTRING_DATA (sequence); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3811 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3812 ending = min (ending, string_char_length (sequence)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3813 pend = (Ibyte *) itext_n_addr (p, ending - starting); |
5187
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3814 delta = ((ending - starting) * item_bytecount) - (pend - p); |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3815 |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3816 /* Resize the string if the bytecount for the area being modified is |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3817 different. */ |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3818 if (delta) |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3819 { |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3820 resize_string (sequence, prefix_bytecount, delta); |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3821 /* No need to zero-terminate the string, resize_string has done |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3822 that for us. */ |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3823 p = XSTRING_DATA (sequence) + prefix_bytecount; |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3824 pend = p + ((ending - starting) * item_bytecount); |
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3825 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3826 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3827 for (; p < pend; p += item_bytecount) |
434 | 3828 memcpy (p, item_buf, item_bytecount); |
5187
b51c2079ec8e
Be much more careful about resizing a string argument, #'fill
Aidan Kehoe <kehoea@parhasard.net>
parents:
5184
diff
changeset
|
3829 |
434 | 3830 |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
3831 init_string_ascii_begin (sequence); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3832 bump_string_modiff (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3833 sledgehammer_check_ascii_begin (sequence); |
428 | 3834 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3835 else if (VECTORP (sequence)) |
428 | 3836 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3837 Lisp_Object *p = XVECTOR_DATA (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3838 CHECK_LISP_WRITEABLE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3839 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3840 ending = min (ending, XVECTOR_LENGTH (sequence)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3841 for (ii = starting; ii < ending; ++ii) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3842 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3843 p[ii] = item; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3844 } |
428 | 3845 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3846 else if (BIT_VECTORP (sequence)) |
428 | 3847 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3848 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence); |
428 | 3849 int bit; |
3850 CHECK_BIT (item); | |
444 | 3851 bit = XINT (item); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3852 CHECK_LISP_WRITEABLE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3853 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3854 ending = min (ending, bit_vector_length (v)); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3855 for (ii = starting; ii < ending; ++ii) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3856 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3857 set_bit_vector_bit (v, ii, bit); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3858 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3859 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3860 else if (LISTP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3861 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3862 Elemcount counting = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3863 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3864 EXTERNAL_LIST_LOOP_3 (elt, sequence, tail) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3865 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3866 if (counting >= starting) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3867 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3868 if (counting < ending) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3869 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3870 XSETCAR (tail, item); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3871 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3872 else if (counting == ending) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3873 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3874 break; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3875 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3876 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3877 ++counting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3878 } |
428 | 3879 } |
3880 else | |
3881 { | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3882 sequence = wrong_type_argument (Qsequencep, sequence); |
428 | 3883 goto retry; |
3884 } | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3885 return sequence; |
428 | 3886 } |
3887 | |
3888 Lisp_Object | |
3889 nconc2 (Lisp_Object arg1, Lisp_Object arg2) | |
3890 { | |
3891 Lisp_Object args[2]; | |
3892 struct gcpro gcpro1; | |
3893 args[0] = arg1; | |
3894 args[1] = arg2; | |
3895 | |
3896 GCPRO1 (args[0]); | |
3897 gcpro1.nvars = 2; | |
3898 | |
3899 RETURN_UNGCPRO (bytecode_nconc2 (args)); | |
3900 } | |
3901 | |
3902 Lisp_Object | |
3903 bytecode_nconc2 (Lisp_Object *args) | |
3904 { | |
3905 retry: | |
3906 | |
3907 if (CONSP (args[0])) | |
3908 { | |
3909 /* (setcdr (last args[0]) args[1]) */ | |
3910 Lisp_Object tortoise, hare; | |
665 | 3911 Elemcount count; |
428 | 3912 |
3913 for (hare = tortoise = args[0], count = 0; | |
3914 CONSP (XCDR (hare)); | |
3915 hare = XCDR (hare), count++) | |
3916 { | |
3917 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3918 | |
3919 if (count & 1) | |
3920 tortoise = XCDR (tortoise); | |
3921 if (EQ (hare, tortoise)) | |
3922 signal_circular_list_error (args[0]); | |
3923 } | |
3924 XCDR (hare) = args[1]; | |
3925 return args[0]; | |
3926 } | |
3927 else if (NILP (args[0])) | |
3928 { | |
3929 return args[1]; | |
3930 } | |
3931 else | |
3932 { | |
3933 args[0] = wrong_type_argument (args[0], Qlistp); | |
3934 goto retry; | |
3935 } | |
3936 } | |
3937 | |
3938 DEFUN ("nconc", Fnconc, 0, MANY, 0, /* | |
3939 Concatenate any number of lists by altering them. | |
3940 Only the last argument is not altered, and need not be a list. | |
3941 Also see: `append'. | |
3942 If the first argument is nil, there is no way to modify it by side | |
3943 effect; therefore, write `(setq foo (nconc foo list))' to be sure of | |
3944 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
|
3945 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
3946 arguments: (&rest ARGS) |
428 | 3947 */ |
3948 (int nargs, Lisp_Object *args)) | |
3949 { | |
3950 int argnum = 0; | |
3951 struct gcpro gcpro1; | |
3952 | |
3953 /* The modus operandi in Emacs is "caller gc-protects args". | |
3954 However, nconc (particularly nconc2 ()) is called many times | |
3955 in Emacs on freshly created stuff (e.g. you see the idiom | |
3956 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those | |
3957 callers out by protecting the args ourselves to save them | |
3958 a lot of temporary-variable grief. */ | |
3959 | |
3960 GCPRO1 (args[0]); | |
3961 gcpro1.nvars = nargs; | |
3962 | |
3963 while (argnum < nargs) | |
3964 { | |
3965 Lisp_Object val; | |
3966 retry: | |
3967 val = args[argnum]; | |
3968 if (CONSP (val)) | |
3969 { | |
3970 /* `val' is the first cons, which will be our return value. */ | |
3971 /* `last_cons' will be the cons cell to mutate. */ | |
3972 Lisp_Object last_cons = val; | |
3973 Lisp_Object tortoise = val; | |
3974 | |
3975 for (argnum++; argnum < nargs; argnum++) | |
3976 { | |
3977 Lisp_Object next = args[argnum]; | |
3978 retry_next: | |
3979 if (CONSP (next) || argnum == nargs -1) | |
3980 { | |
3981 /* (setcdr (last val) next) */ | |
665 | 3982 Elemcount count; |
428 | 3983 |
3984 for (count = 0; | |
3985 CONSP (XCDR (last_cons)); | |
3986 last_cons = XCDR (last_cons), count++) | |
3987 { | |
3988 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3989 | |
3990 if (count & 1) | |
3991 tortoise = XCDR (tortoise); | |
3992 if (EQ (last_cons, tortoise)) | |
3993 signal_circular_list_error (args[argnum-1]); | |
3994 } | |
3995 XCDR (last_cons) = next; | |
3996 } | |
3997 else if (NILP (next)) | |
3998 { | |
3999 continue; | |
4000 } | |
4001 else | |
4002 { | |
4003 next = wrong_type_argument (Qlistp, next); | |
4004 goto retry_next; | |
4005 } | |
4006 } | |
4007 RETURN_UNGCPRO (val); | |
4008 } | |
4009 else if (NILP (val)) | |
4010 argnum++; | |
4011 else if (argnum == nargs - 1) /* last arg? */ | |
4012 RETURN_UNGCPRO (val); | |
4013 else | |
4014 { | |
4015 args[argnum] = wrong_type_argument (Qlistp, val); | |
4016 goto retry; | |
4017 } | |
4018 } | |
4019 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */ | |
4020 } | |
4021 | |
4022 | |
434 | 4023 /* 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
|
4024 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4025 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
|
4026 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
|
4027 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
|
4028 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
|
4029 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
|
4030 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
|
4031 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4032 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
|
4033 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
|
4034 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
|
4035 mapcarX. |
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 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
|
4038 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
|
4039 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
|
4040 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
|
4041 traversal operation. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4042 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4043 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
|
4044 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
|
4045 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
|
4046 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
|
4047 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
|
4048 alone. */ |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4049 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4050 #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
|
4051 #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
|
4052 #define SOME_OR_EVERY_EVERY 2 |
428 | 4053 |
4054 static void | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4055 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
|
4056 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
|
4057 int some_or_every) |
428 | 4058 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4059 Lisp_Object called, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4060 struct gcpro gcpro1, gcpro2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4061 int i, j; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4062 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
|
4063 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4064 assert (LRECORDP (lisp_vals)); |
4999 | 4065 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
|
4066 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4067 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
|
4068 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4069 for (i = 1; i <= nsequences; ++i) |
428 | 4070 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4071 args[i] = Qnil; |
428 | 4072 } |
4073 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4074 if (vals != NULL) |
428 | 4075 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4076 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
|
4077 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4078 gcpro2.nvars = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4079 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4080 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4081 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4082 GCPRO1 (args[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4083 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4084 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4085 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4086 /* 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
|
4087 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
|
4088 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
|
4089 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
|
4090 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
|
4091 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4092 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
|
4093 Lisp_Object *val = vals; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4094 for (i = 0; i < call_count; ++i) |
434 | 4095 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4096 *val++ = XCAR (lst); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4097 lst = XCDR (lst); |
428 | 4098 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4099 gcpro2.nvars = call_count; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4100 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4101 for (i = 0; i < call_count; ++i) |
428 | 4102 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4103 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
|
4104 vals[i] = IGNORE_MULTIPLE_VALUES (Ffuncall (nsequences + 1, args)); |
428 | 4105 } |
4106 } | |
4107 else | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4108 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4109 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
|
4110 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
|
4111 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4112 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
|
4113 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4114 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4115 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
|
4116 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4117 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
|
4118 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4119 switch (sequence_types[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4120 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4121 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4122 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4123 if (!CONSP (sequences[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4124 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4125 /* 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
|
4126 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
|
4127 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
|
4128 (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
|
4129 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
|
4130 callers. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4131 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
|
4132 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4133 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
|
4134 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
|
4135 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4136 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4137 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4138 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4139 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
|
4140 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4141 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4142 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4143 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4144 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
|
4145 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4146 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4147 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
|
4148 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4149 args[j + 1] |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4150 = 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
|
4151 i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4152 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4153 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4154 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4155 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4156 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4157 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4158 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
|
4159 if (vals != NULL) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4160 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4161 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
|
4162 gcpro2.nvars += 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4163 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4164 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4165 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4166 switch (lisp_vals_type) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4167 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4168 case lrecord_type_symbol: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4169 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4170 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4171 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4172 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
|
4173 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4174 called = IGNORE_MULTIPLE_VALUES (called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4175 if (!CONSP (lisp_vals)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4176 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4177 /* 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
|
4178 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
|
4179 relevant part, error. */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4180 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
|
4181 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4182 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4183 XSETCAR (lisp_vals, called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4184 lisp_vals = XCDR (lisp_vals); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4185 break; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4186 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4187 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4188 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
|
4189 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4190 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
|
4191 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4192 XCAR (lisp_vals) = called; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4193 UNGCPRO; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4194 return; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4195 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4196 break; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4197 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4198 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4199 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
|
4200 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4201 called = IGNORE_MULTIPLE_VALUES (called); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4202 if (NILP (called)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4203 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4204 XCAR (lisp_vals) = Qnil; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4205 UNGCPRO; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4206 return; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4207 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4208 break; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4209 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4210 |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
4211 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
|
4212 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4213 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4214 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4215 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
|
4216 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
|
4217 (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
|
4218 /* Let #'aset error. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4219 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
|
4220 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4221 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4222 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4223 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4224 /* 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
|
4225 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
|
4226 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
|
4227 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
|
4228 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
|
4229 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4230 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4231 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
|
4232 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4233 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
|
4234 (BITP (called) && |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4235 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
|
4236 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
|
4237 XINT (called)) : |
5002
0cd784a6ec44
fix some compile bugs of Aidan's
Ben Wing <ben@xemacs.org>
parents:
5001
diff
changeset
|
4238 (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
|
4239 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4240 } |
5034
1b96882bdf37
Fix a multiple-value bug, mapcarX; correct a comment and a label name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5002
diff
changeset
|
4241 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
|
4242 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4243 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4244 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4245 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4246 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4247 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4248 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4249 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4250 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4251 UNGCPRO; |
428 | 4252 } |
4253 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4254 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
|
4255 Call FUNCTION on each element of SEQUENCE, and concat results to a string. |
751 | 4256 Between each pair of results, insert SEPARATOR. |
4257 | |
4258 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR | |
4259 results in spaces between the values returned by FUNCTION. SEQUENCE itself | |
4260 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
|
4261 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4262 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
|
4263 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
|
4264 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
|
4265 `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
|
4266 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4267 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES) |
428 | 4268 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4269 (int nargs, Lisp_Object *args)) |
428 | 4270 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4271 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
|
4272 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
|
4273 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
|
4274 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
|
4275 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4276 EMACS_INT i, nargs0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4277 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4278 args[2] = sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4279 args[1] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4280 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4281 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
|
4282 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4283 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4284 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
|
4285 } |
428 | 4286 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4287 if (len == 0) return build_ascstring (""); |
428 | 4288 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4289 nargs0 = len + len - 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4290 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
|
4291 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4292 /* 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
|
4293 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
|
4294 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
|
4295 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
|
4296 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4297 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
|
4298 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4299 args0[i] = XCAR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4300 sequence = XCDR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4301 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4302 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4303 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4304 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4305 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
|
4306 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
|
4307 } |
428 | 4308 |
4309 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
|
4310 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
|
4311 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4312 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
|
4313 args0[i] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4314 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4315 return Fconcat (nargs0, args0); |
428 | 4316 } |
4317 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4318 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
|
4319 Call FUNCTION on each element of SEQUENCE; return a list of the results. |
434 | 4320 The result is a list of the same length as SEQUENCE. |
428 | 4321 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
|
4322 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4323 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
|
4324 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
|
4325 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
|
4326 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
|
4327 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4328 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4329 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4330 (int nargs, Lisp_Object *args)) |
428 | 4331 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4332 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
|
4333 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
|
4334 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4335 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4336 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4337 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
|
4338 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4339 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4340 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
|
4341 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4342 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4343 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
|
4344 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
|
4345 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
|
4346 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4347 return Flist ((int) len, args0); |
428 | 4348 } |
4349 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4350 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
|
4351 Call FUNCTION on each element of SEQUENCE; return a vector of the results. |
428 | 4352 The result is a vector of the same length as SEQUENCE. |
434 | 4353 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
|
4354 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4355 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
|
4356 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
|
4357 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
|
4358 `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
|
4359 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4360 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4361 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4362 (int nargs, Lisp_Object *args)) |
428 | 4363 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4364 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
|
4365 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
|
4366 Lisp_Object result; |
428 | 4367 struct gcpro gcpro1; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4368 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4369 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4370 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
|
4371 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4372 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4373 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
|
4374 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4375 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4376 result = make_vector (len, Qnil); |
428 | 4377 GCPRO1 (result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4378 /* 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
|
4379 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
|
4380 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
|
4381 SOME_OR_EVERY_NEITHER); |
428 | 4382 UNGCPRO; |
4383 | |
4384 return result; | |
4385 } | |
4386 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4387 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
|
4388 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
|
4389 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4390 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
|
4391 together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4392 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4393 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
|
4394 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
|
4395 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
|
4396 `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
|
4397 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4398 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
|
4399 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4400 (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
|
4401 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4402 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
|
4403 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
|
4404 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4405 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4406 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4407 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4408 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
|
4409 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4410 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4411 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
|
4412 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4413 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4414 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
|
4415 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
|
4416 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
|
4417 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4418 if (len < 2) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4419 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4420 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
|
4421 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4422 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4423 /* 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
|
4424 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
|
4425 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
|
4426 GCPRO1 (args0[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4427 gcpro1.nvars = len + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4428 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4429 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
|
4430 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4431 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
|
4432 args0[i + 1] = nconcing; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4433 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4434 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4435 RETURN_UNGCPRO (XCDR (nconcing)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4436 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4437 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4438 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
|
4439 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
|
4440 |
428 | 4441 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4442 This function is like `mapcar' but does not accumulate the results, | |
4443 which is more efficient if you do not use the results. | |
4444 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4445 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
|
4446 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
|
4447 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
|
4448 `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
|
4449 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4450 Return SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4451 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4452 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
|
4453 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4454 (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
|
4455 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4456 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
|
4457 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
|
4458 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4459 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4460 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4461 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
|
4462 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4463 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4464 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
|
4465 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4466 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4467 /* 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
|
4468 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
|
4469 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
|
4470 GCPRO1 (sequence); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4471 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
|
4472 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
|
4473 RETURN_UNGCPRO (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4474 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4475 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4476 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
|
4477 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
|
4478 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4479 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
|
4480 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
|
4481 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4482 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
|
4483 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
|
4484 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4485 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
|
4486 `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
|
4487 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
|
4488 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4489 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4490 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4491 (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
|
4492 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4493 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
|
4494 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
|
4495 Lisp_Object result = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4496 Lisp_Object *args0 = NULL; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4497 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
|
4498 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4499 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4500 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4501 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
|
4502 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4503 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4504 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
|
4505 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4506 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4507 if (!NILP (type)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4508 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4509 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
|
4510 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4511 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4512 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
|
4513 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
|
4514 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4515 if (EQ (type, Qnil)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4516 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4517 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4518 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4519 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4520 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
|
4521 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4522 result = Fvector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4523 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4524 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
|
4525 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4526 result = Fstring (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4527 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4528 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
|
4529 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4530 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4531 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4532 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
|
4533 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4534 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
|
4535 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4536 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4537 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4538 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4539 GCPRO1 (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4540 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
|
4541 UNGCPRO; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4542 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4543 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4544 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4545 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4546 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4547 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
|
4548 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
|
4549 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4550 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
|
4551 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4552 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
|
4553 \(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
|
4554 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
|
4555 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
|
4556 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4557 Return RESULT-SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4558 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4559 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
|
4560 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4561 (int nargs, Lisp_Object *args)) |
428 | 4562 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4563 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
|
4564 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
|
4565 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
|
4566 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4567 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4568 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4569 args[1] = result_sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4570 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4571 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
|
4572 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4573 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4574 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
|
4575 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4576 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4577 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
|
4578 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
|
4579 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4580 return result_sequence; |
428 | 4581 } |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4582 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4583 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
|
4584 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
|
4585 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4586 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
|
4587 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4588 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
|
4589 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
|
4590 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4591 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4592 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4593 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4594 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4595 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
|
4596 struct gcpro gcpro1; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4597 Elemcount len = EMACS_INT_MAX; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4598 int i; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4599 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4600 GCPRO1 (result_box); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4601 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4602 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
|
4603 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4604 CHECK_SEQUENCE (args[i]); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4605 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
|
4606 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4607 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4608 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
|
4609 SOME_OR_EVERY_SOME); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4610 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4611 RETURN_UNGCPRO (XCAR (result_box)); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4612 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4613 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4614 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
|
4615 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
|
4616 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4617 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
|
4618 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
|
4619 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4620 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
|
4621 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4622 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4623 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4624 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4625 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4626 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
|
4627 struct gcpro gcpro1; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4628 Elemcount len = EMACS_INT_MAX; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4629 int i; |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4630 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4631 GCPRO1 (result_box); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4632 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4633 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
|
4634 { |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4635 CHECK_SEQUENCE (args[i]); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4636 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
|
4637 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4638 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4639 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
|
4640 SOME_OR_EVERY_EVERY); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4641 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4642 RETURN_UNGCPRO (XCAR (result_box)); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4643 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4644 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4645 /* 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
|
4646 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
|
4647 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
|
4648 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4649 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
|
4650 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
|
4651 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4652 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
|
4653 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
|
4654 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
|
4655 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4656 static Lisp_Object |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4657 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
|
4658 int nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4659 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4660 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
|
4661 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
|
4662 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
|
4663 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
|
4664 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4665 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
|
4666 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4667 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
|
4668 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4669 args[i] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4670 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4671 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4672 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4673 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4674 nconcing[0] = result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4675 nconcing[1] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4676 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
|
4677 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4678 gcpro2.nvars = 2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4679 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4680 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4681 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4682 GCPRO2 (args[0], result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4683 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4684 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4685 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4686 while (continuing) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4687 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4688 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
|
4689 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4690 if (CONSP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4691 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4692 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
|
4693 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
|
4694 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4695 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
|
4696 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4697 continuing = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4698 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4699 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4700 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4701 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4702 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
|
4703 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4704 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4705 if (!continuing) break; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4706 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
|
4707 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4708 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4709 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4710 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4711 /* 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
|
4712 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
|
4713 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
|
4714 nconcing[1] = funcalled; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4715 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
|
4716 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4717 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4718 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4719 /* 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
|
4720 once we're done: */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4721 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
|
4722 accum = XCDR (accum); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4723 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4724 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4725 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4726 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
|
4727 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4728 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
|
4729 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4730 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
|
4731 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4732 /* 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
|
4733 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
|
4734 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4735 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4736 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4737 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4738 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4739 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4740 result = XCDR (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4741 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4742 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4743 RETURN_UNGCPRO (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4744 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4745 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4746 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
|
4747 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
|
4748 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
|
4749 the elements themselves." |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4750 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4751 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
|
4752 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4753 (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
|
4754 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4755 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
|
4756 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4757 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4758 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
|
4759 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
|
4760 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4761 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
|
4762 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4763 (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
|
4764 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4765 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
|
4766 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4767 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4768 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
|
4769 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
|
4770 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4771 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
|
4772 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
|
4773 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4774 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
|
4775 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4776 (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
|
4777 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4778 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
|
4779 } |
428 | 4780 |
771 | 4781 /* Extra random functions */ |
442 | 4782 |
4783 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /* | |
4784 Destructively replace the list OLD with NEW. | |
4785 This is like (copy-sequence NEW) except that it reuses the | |
4786 conses in OLD as much as possible. If OLD and NEW are the same | |
4787 length, no consing will take place. | |
4788 */ | |
3025 | 4789 (old, new_)) |
442 | 4790 { |
2367 | 4791 Lisp_Object oldtail = old, prevoldtail = Qnil; |
4792 | |
3025 | 4793 EXTERNAL_LIST_LOOP_2 (elt, new_) |
442 | 4794 { |
4795 if (!NILP (oldtail)) | |
4796 { | |
4797 CHECK_CONS (oldtail); | |
2367 | 4798 XCAR (oldtail) = elt; |
442 | 4799 } |
4800 else if (!NILP (prevoldtail)) | |
4801 { | |
2367 | 4802 XCDR (prevoldtail) = Fcons (elt, Qnil); |
442 | 4803 prevoldtail = XCDR (prevoldtail); |
4804 } | |
4805 else | |
2367 | 4806 old = oldtail = Fcons (elt, Qnil); |
442 | 4807 |
4808 if (!NILP (oldtail)) | |
4809 { | |
4810 prevoldtail = oldtail; | |
4811 oldtail = XCDR (oldtail); | |
4812 } | |
4813 } | |
4814 | |
4815 if (!NILP (prevoldtail)) | |
4816 XCDR (prevoldtail) = Qnil; | |
4817 else | |
4818 old = Qnil; | |
4819 | |
4820 return old; | |
4821 } | |
4822 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4823 |
771 | 4824 Lisp_Object |
2367 | 4825 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string) |
771 | 4826 { |
4827 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
|
4828 build_ascstring (ascii_string)), |
771 | 4829 Qnil); |
4830 } | |
4831 | |
4832 Lisp_Object | |
2367 | 4833 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol) |
771 | 4834 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4835 return Fintern (concat2 (build_ascstring (ascii_string), |
771 | 4836 Fsymbol_name (symbol)), |
4837 Qnil); | |
4838 } | |
4839 | |
442 | 4840 |
428 | 4841 /* #### this function doesn't belong in this file! */ |
4842 | |
442 | 4843 #ifdef HAVE_GETLOADAVG |
4844 #ifdef HAVE_SYS_LOADAVG_H | |
4845 #include <sys/loadavg.h> | |
4846 #endif | |
4847 #else | |
4848 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */ | |
4849 #endif | |
4850 | |
428 | 4851 DEFUN ("load-average", Fload_average, 0, 1, 0, /* |
4852 Return list of 1 minute, 5 minute and 15 minute load averages. | |
4853 Each of the three load averages is multiplied by 100, | |
4854 then converted to integer. | |
4855 | |
4856 When USE-FLOATS is non-nil, floats will be used instead of integers. | |
4857 These floats are not multiplied by 100. | |
4858 | |
4859 If the 5-minute or 15-minute load averages are not available, return a | |
4860 shortened list, containing only those averages which are available. | |
4861 | |
4862 On some systems, this won't work due to permissions on /dev/kmem, | |
4863 in which case you can't use this. | |
4864 */ | |
4865 (use_floats)) | |
4866 { | |
4867 double load_ave[3]; | |
4868 int loads = getloadavg (load_ave, countof (load_ave)); | |
4869 Lisp_Object ret = Qnil; | |
4870 | |
4871 if (loads == -2) | |
563 | 4872 signal_error (Qunimplemented, |
4873 "load-average not implemented for this operating system", | |
4874 Qunbound); | |
428 | 4875 else if (loads < 0) |
563 | 4876 invalid_operation ("Could not get load-average", lisp_strerror (errno)); |
428 | 4877 |
4878 while (loads-- > 0) | |
4879 { | |
4880 Lisp_Object load = (NILP (use_floats) ? | |
4881 make_int ((int) (100.0 * load_ave[loads])) | |
4882 : make_float (load_ave[loads])); | |
4883 ret = Fcons (load, ret); | |
4884 } | |
4885 return ret; | |
4886 } | |
4887 | |
4888 | |
4889 Lisp_Object Vfeatures; | |
4890 | |
4891 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /* | |
4892 Return non-nil if feature FEXP is present in this Emacs. | |
4893 Use this to conditionalize execution of lisp code based on the | |
4894 presence or absence of emacs or environment extensions. | |
4895 FEXP can be a symbol, a number, or a list. | |
4896 If it is a symbol, that symbol is looked up in the `features' variable, | |
4897 and non-nil will be returned if found. | |
4898 If it is a number, the function will return non-nil if this Emacs | |
4899 has an equal or greater version number than FEXP. | |
4900 If it is a list whose car is the symbol `and', it will return | |
4901 non-nil if all the features in its cdr are non-nil. | |
4902 If it is a list whose car is the symbol `or', it will return non-nil | |
4903 if any of the features in its cdr are non-nil. | |
4904 If it is a list whose car is the symbol `not', it will return | |
4905 non-nil if the feature is not present. | |
4906 | |
4907 Examples: | |
4908 | |
4909 (featurep 'xemacs) | |
4910 => ; Non-nil on XEmacs. | |
4911 | |
4912 (featurep '(and xemacs gnus)) | |
4913 => ; Non-nil on XEmacs with Gnus loaded. | |
4914 | |
4915 (featurep '(or tty-frames (and emacs 19.30))) | |
4916 => ; Non-nil if this Emacs supports TTY frames. | |
4917 | |
4918 (featurep '(or (and xemacs 19.15) (and emacs 19.34))) | |
4919 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later. | |
4920 | |
442 | 4921 (featurep '(and xemacs 21.02)) |
4922 => ; Non-nil on XEmacs 21.2 and later. | |
4923 | |
428 | 4924 NOTE: The advanced arguments of this function (anything other than a |
4925 symbol) are not yet supported by FSF Emacs. If you feel they are useful | |
4926 for supporting multiple Emacs variants, lobby Richard Stallman at | |
442 | 4927 <bug-gnu-emacs@gnu.org>. |
428 | 4928 */ |
4929 (fexp)) | |
4930 { | |
4931 #ifndef FEATUREP_SYNTAX | |
4932 CHECK_SYMBOL (fexp); | |
4933 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
4934 #else /* FEATUREP_SYNTAX */ | |
4935 static double featurep_emacs_version; | |
4936 | |
4937 /* Brute force translation from Erik Naggum's lisp function. */ | |
4938 if (SYMBOLP (fexp)) | |
4939 { | |
4940 /* Original definition */ | |
4941 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
4942 } | |
4943 else if (INTP (fexp) || FLOATP (fexp)) | |
4944 { | |
4945 double d = extract_float (fexp); | |
4946 | |
4947 if (featurep_emacs_version == 0.0) | |
4948 { | |
4949 featurep_emacs_version = XINT (Vemacs_major_version) + | |
4950 (XINT (Vemacs_minor_version) / 100.0); | |
4951 } | |
4952 return featurep_emacs_version >= d ? Qt : Qnil; | |
4953 } | |
4954 else if (CONSP (fexp)) | |
4955 { | |
4956 Lisp_Object tem = XCAR (fexp); | |
4957 if (EQ (tem, Qnot)) | |
4958 { | |
4959 Lisp_Object negate; | |
4960 | |
4961 tem = XCDR (fexp); | |
4962 negate = Fcar (tem); | |
4963 if (!NILP (tem)) | |
4964 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil; | |
4965 else | |
4966 return Fsignal (Qinvalid_read_syntax, list1 (tem)); | |
4967 } | |
4968 else if (EQ (tem, Qand)) | |
4969 { | |
4970 tem = XCDR (fexp); | |
4971 /* Use Fcar/Fcdr for error-checking. */ | |
4972 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem)))) | |
4973 { | |
4974 tem = Fcdr (tem); | |
4975 } | |
4976 return NILP (tem) ? Qt : Qnil; | |
4977 } | |
4978 else if (EQ (tem, Qor)) | |
4979 { | |
4980 tem = XCDR (fexp); | |
4981 /* Use Fcar/Fcdr for error-checking. */ | |
4982 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem)))) | |
4983 { | |
4984 tem = Fcdr (tem); | |
4985 } | |
4986 return NILP (tem) ? Qnil : Qt; | |
4987 } | |
4988 else | |
4989 { | |
4990 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp))); | |
4991 } | |
4992 } | |
4993 else | |
4994 { | |
4995 return Fsignal (Qinvalid_read_syntax, list1 (fexp)); | |
4996 } | |
4997 } | |
4998 #endif /* FEATUREP_SYNTAX */ | |
4999 | |
5000 DEFUN ("provide", Fprovide, 1, 1, 0, /* | |
5001 Announce that FEATURE is a feature of the current Emacs. | |
5002 This function updates the value of the variable `features'. | |
5003 */ | |
5004 (feature)) | |
5005 { | |
5006 Lisp_Object tem; | |
5007 CHECK_SYMBOL (feature); | |
5008 if (!NILP (Vautoload_queue)) | |
5009 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); | |
5010 tem = Fmemq (feature, Vfeatures); | |
5011 if (NILP (tem)) | |
5012 Vfeatures = Fcons (feature, Vfeatures); | |
5013 LOADHIST_ATTACH (Fcons (Qprovide, feature)); | |
5014 return feature; | |
5015 } | |
5016 | |
1067 | 5017 DEFUN ("require", Frequire, 1, 3, 0, /* |
3842 | 5018 Ensure that FEATURE is present in the Lisp environment. |
5019 FEATURE is a symbol naming a collection of resources (functions, etc). | |
5020 Optional FILENAME is a library from which to load resources; it defaults to | |
5021 the print name of FEATURE. | |
5022 Optional NOERROR, if non-nil, causes require to return nil rather than signal | |
5023 `file-error' if loading the library fails. | |
5024 | |
5025 If feature FEATURE is present in `features', update `load-history' to reflect | |
5026 the require and return FEATURE. Otherwise, try to load it from a library. | |
5027 The normal messages at start and end of loading are suppressed. | |
5028 If the library is successfully loaded and it calls `(provide FEATURE)', add | |
5029 FEATURE to `features', update `load-history' and return FEATURE. | |
5030 If the load succeeds but FEATURE is not provided by the library, signal | |
5031 `invalid-state'. | |
5032 | |
5033 The byte-compiler treats top-level calls to `require' specially, by evaluating | |
5034 them at compile time (and then compiling them normally). Thus a library may | |
5035 request that definitions that should be inlined such as macros and defsubsts | |
5036 be loaded into its compilation environment. Achieving this in other contexts | |
5037 requires an explicit \(eval-and-compile ...\) block. | |
428 | 5038 */ |
1067 | 5039 (feature, filename, noerror)) |
428 | 5040 { |
5041 Lisp_Object tem; | |
5042 CHECK_SYMBOL (feature); | |
5043 tem = Fmemq (feature, Vfeatures); | |
5044 LOADHIST_ATTACH (Fcons (Qrequire, feature)); | |
5045 if (!NILP (tem)) | |
5046 return feature; | |
5047 else | |
5048 { | |
5049 int speccount = specpdl_depth (); | |
5050 | |
5051 /* Value saved here is to be restored into Vautoload_queue */ | |
5052 record_unwind_protect (un_autoload, Vautoload_queue); | |
5053 Vautoload_queue = Qt; | |
5054 | |
1067 | 5055 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename, |
1261 | 5056 noerror, Qrequire, Qnil); |
1067 | 5057 /* If load failed entirely, return nil. */ |
5058 if (NILP (tem)) | |
5059 return unbind_to_1 (speccount, Qnil); | |
428 | 5060 |
5061 tem = Fmemq (feature, Vfeatures); | |
5062 if (NILP (tem)) | |
563 | 5063 invalid_state ("Required feature was not provided", feature); |
428 | 5064 |
5065 /* Once loading finishes, don't undo it. */ | |
5066 Vautoload_queue = Qt; | |
771 | 5067 return unbind_to_1 (speccount, feature); |
428 | 5068 } |
5069 } | |
5070 | |
5071 /* base64 encode/decode functions. | |
5072 | |
5073 Originally based on code from GNU recode. Ported to FSF Emacs by | |
5074 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and | |
5075 subsequently heavily hacked by Hrvoje Niksic. */ | |
5076 | |
5077 #define MIME_LINE_LENGTH 72 | |
5078 | |
5079 #define IS_ASCII(Character) \ | |
5080 ((Character) < 128) | |
5081 #define IS_BASE64(Character) \ | |
5082 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | |
5083 | |
5084 /* 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
|
5085 static Ascbyte base64_value_to_char[64] = |
428 | 5086 { |
5087 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */ | |
5088 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */ | |
5089 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */ | |
5090 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */ | |
5091 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */ | |
5092 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */ | |
5093 '8', '9', '+', '/' /* 60-63 */ | |
5094 }; | |
5095 | |
5096 /* Table of base64 values for first 128 characters. */ | |
5097 static short base64_char_to_value[128] = | |
5098 { | |
5099 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */ | |
5100 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */ | |
5101 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */ | |
5102 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */ | |
5103 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */ | |
5104 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */ | |
5105 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */ | |
5106 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */ | |
5107 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */ | |
5108 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */ | |
5109 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */ | |
5110 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */ | |
5111 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */ | |
5112 }; | |
5113 | |
5114 /* The following diagram shows the logical steps by which three octets | |
5115 get transformed into four base64 characters. | |
5116 | |
5117 .--------. .--------. .--------. | |
5118 |aaaaaabb| |bbbbcccc| |ccdddddd| | |
5119 `--------' `--------' `--------' | |
5120 6 2 4 4 2 6 | |
5121 .--------+--------+--------+--------. | |
5122 |00aaaaaa|00bbbbbb|00cccccc|00dddddd| | |
5123 `--------+--------+--------+--------' | |
5124 | |
5125 .--------+--------+--------+--------. | |
5126 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD| | |
5127 `--------+--------+--------+--------' | |
5128 | |
5129 The octets are divided into 6 bit chunks, which are then encoded into | |
5130 base64 characters. */ | |
5131 | |
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
|
5132 static DECLARE_DOESNT_RETURN (base64_conversion_error (const Ascbyte *, |
2268 | 5133 Lisp_Object)); |
5134 | |
575 | 5135 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
|
5136 base64_conversion_error (const Ascbyte *reason, Lisp_Object frob) |
563 | 5137 { |
5138 signal_error (Qbase64_conversion_error, reason, frob); | |
5139 } | |
5140 | |
5141 #define ADVANCE_INPUT(c, stream) \ | |
867 | 5142 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \ |
563 | 5143 ((ec > 255) ? \ |
5144 (base64_conversion_error ("Non-ascii character in base64 input", \ | |
5145 make_char (ec)), 0) \ | |
867 | 5146 : (c = (Ibyte)ec), 1)) |
665 | 5147 |
5148 static Bytebpos | |
867 | 5149 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break) |
428 | 5150 { |
5151 EMACS_INT counter = 0; | |
867 | 5152 Ibyte *e = to; |
5153 Ichar ec; | |
428 | 5154 unsigned int value; |
5155 | |
5156 while (1) | |
5157 { | |
1204 | 5158 Ibyte c = 0; |
428 | 5159 if (!ADVANCE_INPUT (c, istream)) |
5160 break; | |
5161 | |
5162 /* Wrap line every 76 characters. */ | |
5163 if (line_break) | |
5164 { | |
5165 if (counter < MIME_LINE_LENGTH / 4) | |
5166 counter++; | |
5167 else | |
5168 { | |
5169 *e++ = '\n'; | |
5170 counter = 1; | |
5171 } | |
5172 } | |
5173 | |
5174 /* Process first byte of a triplet. */ | |
5175 *e++ = base64_value_to_char[0x3f & c >> 2]; | |
5176 value = (0x03 & c) << 4; | |
5177 | |
5178 /* Process second byte of a triplet. */ | |
5179 if (!ADVANCE_INPUT (c, istream)) | |
5180 { | |
5181 *e++ = base64_value_to_char[value]; | |
5182 *e++ = '='; | |
5183 *e++ = '='; | |
5184 break; | |
5185 } | |
5186 | |
5187 *e++ = base64_value_to_char[value | (0x0f & c >> 4)]; | |
5188 value = (0x0f & c) << 2; | |
5189 | |
5190 /* Process third byte of a triplet. */ | |
5191 if (!ADVANCE_INPUT (c, istream)) | |
5192 { | |
5193 *e++ = base64_value_to_char[value]; | |
5194 *e++ = '='; | |
5195 break; | |
5196 } | |
5197 | |
5198 *e++ = base64_value_to_char[value | (0x03 & c >> 6)]; | |
5199 *e++ = base64_value_to_char[0x3f & c]; | |
5200 } | |
5201 | |
5202 return e - to; | |
5203 } | |
5204 #undef ADVANCE_INPUT | |
5205 | |
5206 /* Get next character from the stream, except that non-base64 | |
5207 characters are ignored. This is in accordance with rfc2045. EC | |
867 | 5208 should be an Ichar, so that it can hold -1 as the value for EOF. */ |
428 | 5209 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \ |
867 | 5210 ec = Lstream_get_ichar (stream); \ |
428 | 5211 ++streampos; \ |
5212 /* IS_BASE64 may not be called with negative arguments so check for \ | |
5213 EOF first. */ \ | |
5214 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \ | |
5215 break; \ | |
5216 } while (1) | |
5217 | |
5218 #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
|
5219 pos += set_itext_ichar (pos, (Ichar)((Binbyte)(val))); \ |
428 | 5220 ++ccnt; \ |
5221 } while (0) | |
5222 | |
665 | 5223 static Bytebpos |
867 | 5224 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr) |
428 | 5225 { |
5226 Charcount ccnt = 0; | |
867 | 5227 Ibyte *e = to; |
428 | 5228 EMACS_INT streampos = 0; |
5229 | |
5230 while (1) | |
5231 { | |
867 | 5232 Ichar ec; |
428 | 5233 unsigned long value; |
5234 | |
5235 /* Process first byte of a quadruplet. */ | |
5236 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
5237 if (ec < 0) | |
5238 break; | |
5239 if (ec == '=') | |
563 | 5240 base64_conversion_error ("Illegal `=' character while decoding base64", |
5241 make_int (streampos)); | |
428 | 5242 value = base64_char_to_value[ec] << 18; |
5243 | |
5244 /* Process second byte of a quadruplet. */ | |
5245 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
5246 if (ec < 0) | |
563 | 5247 base64_conversion_error ("Premature EOF while decoding base64", |
5248 Qunbound); | |
428 | 5249 if (ec == '=') |
563 | 5250 base64_conversion_error ("Illegal `=' character while decoding base64", |
5251 make_int (streampos)); | |
428 | 5252 value |= base64_char_to_value[ec] << 12; |
5253 STORE_BYTE (e, value >> 16, ccnt); | |
5254 | |
5255 /* Process third byte of a quadruplet. */ | |
5256 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
5257 if (ec < 0) | |
563 | 5258 base64_conversion_error ("Premature EOF while decoding base64", |
5259 Qunbound); | |
428 | 5260 |
5261 if (ec == '=') | |
5262 { | |
5263 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
5264 if (ec < 0) | |
563 | 5265 base64_conversion_error ("Premature EOF while decoding base64", |
5266 Qunbound); | |
428 | 5267 if (ec != '=') |
563 | 5268 base64_conversion_error |
5269 ("Padding `=' expected but not found while decoding base64", | |
5270 make_int (streampos)); | |
428 | 5271 continue; |
5272 } | |
5273 | |
5274 value |= base64_char_to_value[ec] << 6; | |
5275 STORE_BYTE (e, 0xff & value >> 8, ccnt); | |
5276 | |
5277 /* Process fourth byte of a quadruplet. */ | |
5278 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
5279 if (ec < 0) | |
563 | 5280 base64_conversion_error ("Premature EOF while decoding base64", |
5281 Qunbound); | |
428 | 5282 if (ec == '=') |
5283 continue; | |
5284 | |
5285 value |= base64_char_to_value[ec]; | |
5286 STORE_BYTE (e, 0xff & value, ccnt); | |
5287 } | |
5288 | |
5289 *ccptr = ccnt; | |
5290 return e - to; | |
5291 } | |
5292 #undef ADVANCE_INPUT | |
5293 #undef ADVANCE_INPUT_IGNORE_NONBASE64 | |
5294 #undef STORE_BYTE | |
5295 | |
5296 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /* | |
444 | 5297 Base64-encode the region between START and END. |
428 | 5298 Return the length of the encoded text. |
5299 Optional third argument NO-LINE-BREAK means do not break long lines | |
5300 into shorter lines. | |
5301 */ | |
444 | 5302 (start, end, no_line_break)) |
428 | 5303 { |
867 | 5304 Ibyte *encoded; |
665 | 5305 Bytebpos encoded_length; |
428 | 5306 Charcount allength, length; |
5307 struct buffer *buf = current_buffer; | |
665 | 5308 Charbpos begv, zv, old_pt = BUF_PT (buf); |
428 | 5309 Lisp_Object input; |
851 | 5310 int speccount = specpdl_depth (); |
428 | 5311 |
444 | 5312 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 5313 barf_if_buffer_read_only (buf, begv, zv); |
5314 | |
5315 /* We need to allocate enough room for encoding the text. | |
5316 We need 33 1/3% more space, plus a newline every 76 | |
5317 characters, and then we round up. */ | |
5318 length = zv - begv; | |
5319 allength = length + length/3 + 1; | |
5320 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
5321 | |
5322 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
867 | 5323 /* We needn't multiply allength with MAX_ICHAR_LEN because all the |
428 | 5324 base64 characters will be single-byte. */ |
867 | 5325 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 5326 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
5327 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
5328 assert (encoded_length <= allength); |
428 | 5329 Lstream_delete (XLSTREAM (input)); |
5330 | |
5331 /* Now we have encoded the region, so we insert the new contents | |
5332 and delete the old. (Insert first in order to preserve markers.) */ | |
5333 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0); | |
851 | 5334 unbind_to (speccount); |
428 | 5335 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0); |
5336 | |
5337 /* Simulate FSF Emacs implementation of this function: if point was | |
5338 in the region, place it at the beginning. */ | |
5339 if (old_pt >= begv && old_pt < zv) | |
5340 BUF_SET_PT (buf, begv); | |
5341 | |
5342 /* We return the length of the encoded text. */ | |
5343 return make_int (encoded_length); | |
5344 } | |
5345 | |
5346 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /* | |
5347 Base64 encode STRING and return the result. | |
444 | 5348 Optional argument NO-LINE-BREAK means do not break long lines |
5349 into shorter lines. | |
428 | 5350 */ |
5351 (string, no_line_break)) | |
5352 { | |
5353 Charcount allength, length; | |
665 | 5354 Bytebpos encoded_length; |
867 | 5355 Ibyte *encoded; |
428 | 5356 Lisp_Object input, result; |
5357 int speccount = specpdl_depth(); | |
5358 | |
5359 CHECK_STRING (string); | |
5360 | |
826 | 5361 length = string_char_length (string); |
428 | 5362 allength = length + length/3 + 1; |
5363 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
5364 | |
5365 input = make_lisp_string_input_stream (string, 0, -1); | |
867 | 5366 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 5367 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
5368 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
5369 assert (encoded_length <= allength); |
428 | 5370 Lstream_delete (XLSTREAM (input)); |
5371 result = make_string (encoded, encoded_length); | |
851 | 5372 unbind_to (speccount); |
428 | 5373 return result; |
5374 } | |
5375 | |
5376 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /* | |
444 | 5377 Base64-decode the region between START and END. |
428 | 5378 Return the length of the decoded text. |
5379 If the region can't be decoded, return nil and don't modify the buffer. | |
5380 Characters out of the base64 alphabet are ignored. | |
5381 */ | |
444 | 5382 (start, end)) |
428 | 5383 { |
5384 struct buffer *buf = current_buffer; | |
665 | 5385 Charbpos begv, zv, old_pt = BUF_PT (buf); |
867 | 5386 Ibyte *decoded; |
665 | 5387 Bytebpos decoded_length; |
428 | 5388 Charcount length, cc_decoded_length; |
5389 Lisp_Object input; | |
5390 int speccount = specpdl_depth(); | |
5391 | |
444 | 5392 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 5393 barf_if_buffer_read_only (buf, begv, zv); |
5394 | |
5395 length = zv - begv; | |
5396 | |
5397 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
5398 /* We need to allocate enough room for decoding the text. */ | |
867 | 5399 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 5400 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
|
5401 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 5402 Lstream_delete (XLSTREAM (input)); |
5403 | |
5404 /* Now we have decoded the region, so we insert the new contents | |
5405 and delete the old. (Insert first in order to preserve markers.) */ | |
5406 BUF_SET_PT (buf, begv); | |
5407 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0); | |
851 | 5408 unbind_to (speccount); |
428 | 5409 buffer_delete_range (buf, begv + cc_decoded_length, |
5410 zv + cc_decoded_length, 0); | |
5411 | |
5412 /* Simulate FSF Emacs implementation of this function: if point was | |
5413 in the region, place it at the beginning. */ | |
5414 if (old_pt >= begv && old_pt < zv) | |
5415 BUF_SET_PT (buf, begv); | |
5416 | |
5417 return make_int (cc_decoded_length); | |
5418 } | |
5419 | |
5420 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /* | |
5421 Base64-decode STRING and return the result. | |
5422 Characters out of the base64 alphabet are ignored. | |
5423 */ | |
5424 (string)) | |
5425 { | |
867 | 5426 Ibyte *decoded; |
665 | 5427 Bytebpos decoded_length; |
428 | 5428 Charcount length, cc_decoded_length; |
5429 Lisp_Object input, result; | |
5430 int speccount = specpdl_depth(); | |
5431 | |
5432 CHECK_STRING (string); | |
5433 | |
826 | 5434 length = string_char_length (string); |
428 | 5435 /* We need to allocate enough room for decoding the text. */ |
867 | 5436 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 5437 |
5438 input = make_lisp_string_input_stream (string, 0, -1); | |
5439 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, | |
5440 &cc_decoded_length); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
5441 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 5442 Lstream_delete (XLSTREAM (input)); |
5443 | |
5444 result = make_string (decoded, decoded_length); | |
851 | 5445 unbind_to (speccount); |
428 | 5446 return result; |
5447 } | |
5448 | |
5449 Lisp_Object Qyes_or_no_p; | |
5450 | |
5451 void | |
5452 syms_of_fns (void) | |
5453 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
5454 INIT_LISP_OBJECT (bit_vector); |
442 | 5455 |
563 | 5456 DEFSYMBOL (Qstring_lessp); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5457 DEFSYMBOL (Qsort); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5458 DEFSYMBOL (Qmerge); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5459 DEFSYMBOL (Qfill); |
563 | 5460 DEFSYMBOL (Qidentity); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5461 DEFSYMBOL (Qvector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5462 DEFSYMBOL (Qarray); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5463 DEFSYMBOL (Qstring); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5464 DEFSYMBOL (Qlist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5465 DEFSYMBOL (Qbit_vector); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5466 defsymbol (&QsortX, "sort*"); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5467 |
563 | 5468 DEFSYMBOL (Qyes_or_no_p); |
5469 | |
5470 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error); | |
428 | 5471 |
5472 DEFSUBR (Fidentity); | |
5473 DEFSUBR (Frandom); | |
5474 DEFSUBR (Flength); | |
5475 DEFSUBR (Fsafe_length); | |
5476 DEFSUBR (Fstring_equal); | |
801 | 5477 DEFSUBR (Fcompare_strings); |
428 | 5478 DEFSUBR (Fstring_lessp); |
5479 DEFSUBR (Fstring_modified_tick); | |
5480 DEFSUBR (Fappend); | |
5481 DEFSUBR (Fconcat); | |
5482 DEFSUBR (Fvconcat); | |
5483 DEFSUBR (Fbvconcat); | |
5484 DEFSUBR (Fcopy_list); | |
5485 DEFSUBR (Fcopy_sequence); | |
5486 DEFSUBR (Fcopy_alist); | |
5487 DEFSUBR (Fcopy_tree); | |
5488 DEFSUBR (Fsubseq); | |
5489 DEFSUBR (Fnthcdr); | |
5490 DEFSUBR (Fnth); | |
5491 DEFSUBR (Felt); | |
5492 DEFSUBR (Flast); | |
5493 DEFSUBR (Fbutlast); | |
5494 DEFSUBR (Fnbutlast); | |
5495 DEFSUBR (Fmember); | |
5496 DEFSUBR (Fold_member); | |
5497 DEFSUBR (Fmemq); | |
5498 DEFSUBR (Fold_memq); | |
5499 DEFSUBR (Fassoc); | |
5500 DEFSUBR (Fold_assoc); | |
5501 DEFSUBR (Fassq); | |
5502 DEFSUBR (Fold_assq); | |
5503 DEFSUBR (Frassoc); | |
5504 DEFSUBR (Fold_rassoc); | |
5505 DEFSUBR (Frassq); | |
5506 DEFSUBR (Fold_rassq); | |
5507 DEFSUBR (Fdelete); | |
5508 DEFSUBR (Fold_delete); | |
5509 DEFSUBR (Fdelq); | |
5510 DEFSUBR (Fold_delq); | |
5511 DEFSUBR (Fremassoc); | |
5512 DEFSUBR (Fremassq); | |
5513 DEFSUBR (Fremrassoc); | |
5514 DEFSUBR (Fremrassq); | |
5515 DEFSUBR (Fnreverse); | |
5516 DEFSUBR (Freverse); | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5517 DEFSUBR (FsortX); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5518 Ffset (intern ("sort"), QsortX); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5519 DEFSUBR (Fmerge); |
428 | 5520 DEFSUBR (Fplists_eq); |
5521 DEFSUBR (Fplists_equal); | |
5522 DEFSUBR (Flax_plists_eq); | |
5523 DEFSUBR (Flax_plists_equal); | |
5524 DEFSUBR (Fplist_get); | |
5525 DEFSUBR (Fplist_put); | |
5526 DEFSUBR (Fplist_remprop); | |
5527 DEFSUBR (Fplist_member); | |
5528 DEFSUBR (Fcheck_valid_plist); | |
5529 DEFSUBR (Fvalid_plist_p); | |
5530 DEFSUBR (Fcanonicalize_plist); | |
5531 DEFSUBR (Flax_plist_get); | |
5532 DEFSUBR (Flax_plist_put); | |
5533 DEFSUBR (Flax_plist_remprop); | |
5534 DEFSUBR (Flax_plist_member); | |
5535 DEFSUBR (Fcanonicalize_lax_plist); | |
5536 DEFSUBR (Fdestructive_alist_to_plist); | |
5537 DEFSUBR (Fget); | |
5538 DEFSUBR (Fput); | |
5539 DEFSUBR (Fremprop); | |
5540 DEFSUBR (Fobject_plist); | |
5541 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
|
5542 DEFSUBR (Fequalp); |
428 | 5543 DEFSUBR (Fold_equal); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5544 DEFSUBR (Ffill); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5545 Ffset (intern ("fillarray"), Qfill); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
5546 |
428 | 5547 DEFSUBR (Fnconc); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5548 DEFSUBR (FmapcarX); |
428 | 5549 DEFSUBR (Fmapvector); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5550 DEFSUBR (Fmapcan); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5551 DEFSUBR (Fmapc); |
428 | 5552 DEFSUBR (Fmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5553 DEFSUBR (Fmap); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5554 DEFSUBR (Fmap_into); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
5555 DEFSUBR (Fsome); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
5556 DEFSUBR (Fevery); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5557 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
|
5558 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
|
5559 DEFSUBR (Fmaplist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5560 DEFSUBR (Fmapl); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5561 DEFSUBR (Fmapcon); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5562 |
442 | 5563 DEFSUBR (Freplace_list); |
428 | 5564 DEFSUBR (Fload_average); |
5565 DEFSUBR (Ffeaturep); | |
5566 DEFSUBR (Frequire); | |
5567 DEFSUBR (Fprovide); | |
5568 DEFSUBR (Fbase64_encode_region); | |
5569 DEFSUBR (Fbase64_encode_string); | |
5570 DEFSUBR (Fbase64_decode_region); | |
5571 DEFSUBR (Fbase64_decode_string); | |
771 | 5572 |
5573 DEFSUBR (Fsplit_string_by_char); | |
5574 DEFSUBR (Fsplit_path); /* #### */ | |
5575 } | |
5576 | |
5577 void | |
5578 vars_of_fns (void) | |
5579 { | |
5580 DEFVAR_LISP ("path-separator", &Vpath_separator /* | |
5581 The directory separator in search paths, as a string. | |
5582 */ ); | |
5583 { | |
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
|
5584 Ascbyte c = SEPCHAR; |
867 | 5585 Vpath_separator = make_string ((Ibyte *) &c, 1); |
771 | 5586 } |
428 | 5587 } |
5588 | |
5589 void | |
5590 init_provide_once (void) | |
5591 { | |
5592 DEFVAR_LISP ("features", &Vfeatures /* | |
5593 A list of symbols which are the features of the executing emacs. | |
5594 Used by `featurep' and `require', and altered by `provide'. | |
5595 */ ); | |
5596 Vfeatures = Qnil; | |
5597 | |
5598 Fprovide (intern ("base64")); | |
5599 } |