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