Mercurial > hg > xemacs-beta
annotate src/fns.c @ 5273:799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
src/ChangeLog addition:
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (Flist_length): New, moved here from cl-extra.el, needed
by the next function.
(shortest_length_among_sequences): New.
(Fmapconcat, FmapcarX, Fmapvector, Fmapcan, Fmapc, Fmap)
(Fmap_into, Fsome, Fevery):
Use shortest_length_among_sequences() when working out how many
iterations to do, only giving circular list errors if all
arguments are circular.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 16 Sep 2010 20:34:49 +0100 |
parents | 66dbef5f8076 |
children | 5a9aa6c40c9b |
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 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
57 Lisp_Object Qstring_lessp, Qsort, Qmerge, Qfill, Qreplace; |
428 | 58 Lisp_Object Qidentity; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
59 Lisp_Object Qvector, Qarray, Qbit_vector, QsortX, Q_from_end, Q_initial_value; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
60 Lisp_Object Qmapconcat, QmapcarX, Qmapvector, Qmapcan, Qmapc, Qmap, Qmap_into; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
61 Lisp_Object Qsome, Qevery, Qmaplist, Qmapl, Qmapcon, Qreduce; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
62 Lisp_Object Q_start1, Q_start2, Q_end1, Q_end2; |
428 | 63 |
563 | 64 Lisp_Object Qbase64_conversion_error; |
65 | |
771 | 66 Lisp_Object Vpath_separator; |
67 | |
428 | 68 static int internal_old_equal (Lisp_Object, Lisp_Object, int); |
454 | 69 Lisp_Object safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth); |
428 | 70 |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
71 static DOESNT_RETURN |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
72 mapping_interaction_error (Lisp_Object func, Lisp_Object object) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
73 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
74 invalid_state_2 ("object modified while traversing it", func, object); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
75 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
76 |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
77 static void |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
78 check_sequence_range (Lisp_Object sequence, Lisp_Object start, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
79 Lisp_Object end, Lisp_Object length) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
80 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
81 Elemcount starting = XINT (start), ending, len = XINT (length); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
82 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
83 ending = NILP (end) ? XINT (length) : XINT (end); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
84 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
85 if (!(0 <= starting && starting <= ending && ending <= len)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
86 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
87 args_out_of_range_3 (sequence, start, make_int (ending)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
88 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
89 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
90 |
428 | 91 static Lisp_Object |
2286 | 92 mark_bit_vector (Lisp_Object UNUSED (obj)) |
428 | 93 { |
94 return Qnil; | |
95 } | |
96 | |
97 static void | |
2286 | 98 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, |
99 int UNUSED (escapeflag)) | |
428 | 100 { |
665 | 101 Elemcount i; |
440 | 102 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
665 | 103 Elemcount len = bit_vector_length (v); |
104 Elemcount last = len; | |
428 | 105 |
106 if (INTP (Vprint_length)) | |
107 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
|
108 write_ascstring (printcharfun, "#*"); |
428 | 109 for (i = 0; i < last; i++) |
110 { | |
111 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
|
112 write_ascstring (printcharfun, "1"); |
428 | 113 else |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
114 write_ascstring (printcharfun, "0"); |
428 | 115 } |
116 | |
117 if (last != len) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
118 write_ascstring (printcharfun, "..."); |
428 | 119 } |
120 | |
121 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
|
122 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
|
123 int UNUSED (foldcase)) |
428 | 124 { |
440 | 125 Lisp_Bit_Vector *v1 = XBIT_VECTOR (obj1); |
126 Lisp_Bit_Vector *v2 = XBIT_VECTOR (obj2); | |
428 | 127 |
128 return ((bit_vector_length (v1) == bit_vector_length (v2)) && | |
129 !memcmp (v1->bits, v2->bits, | |
130 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) * | |
131 sizeof (long))); | |
132 } | |
133 | |
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
|
134 /* 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
|
135 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
|
136 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
|
137 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
|
138 now that doesn't seem worth it. */ |
665 | 139 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
|
140 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
|
141 { |
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 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
|
143 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
|
144 |
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 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
|
146 { |
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
|
147 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
|
148 { |
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 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
|
150 (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
|
151 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
|
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 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
|
154 } |
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
|
155 |
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
|
156 /* 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 ((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
|
163 |
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
|
164 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
|
165 } |
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
|
166 |
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
|
167 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
|
168 bit_vector_hash (Lisp_Object obj, int UNUSED (depth), Boolint equalp) |
428 | 169 { |
440 | 170 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
|
171 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
|
172 { |
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
|
173 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
|
174 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
|
175 } |
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
|
176 |
428 | 177 return HASH2 (bit_vector_length (v), |
178 memory_hash (v->bits, | |
179 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) * | |
180 sizeof (long))); | |
181 } | |
182 | |
665 | 183 static Bytecount |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
184 size_bit_vector (Lisp_Object obj) |
442 | 185 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
186 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
456 | 187 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, unsigned long, bits, |
442 | 188 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v))); |
189 } | |
190 | |
1204 | 191 static const struct memory_description bit_vector_description[] = { |
428 | 192 { XD_END } |
193 }; | |
194 | |
195 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
196 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
|
197 mark_bit_vector, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
198 print_bit_vector, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
199 bit_vector_equal, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
200 bit_vector_hash, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
201 bit_vector_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
202 size_bit_vector, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
203 Lisp_Bit_Vector); |
934 | 204 |
428 | 205 |
206 DEFUN ("identity", Fidentity, 1, 1, 0, /* | |
207 Return the argument unchanged. | |
208 */ | |
209 (arg)) | |
210 { | |
211 return arg; | |
212 } | |
213 | |
214 DEFUN ("random", Frandom, 0, 1, 0, /* | |
215 Return a pseudo-random number. | |
1983 | 216 All fixnums are equally likely. On most systems, this is 31 bits' worth. |
428 | 217 With positive integer argument N, return random number in interval [0,N). |
1983 | 218 N can be a bignum, in which case the range of possible values is extended. |
428 | 219 With argument t, set the random number seed from the current time and pid. |
220 */ | |
221 (limit)) | |
222 { | |
223 EMACS_INT val; | |
224 unsigned long denominator; | |
225 | |
226 if (EQ (limit, Qt)) | |
771 | 227 seed_random (qxe_getpid () + time (NULL)); |
428 | 228 if (NATNUMP (limit) && !ZEROP (limit)) |
229 { | |
230 /* Try to take our random number from the higher bits of VAL, | |
231 not the lower, since (says Gentzel) the low bits of `random' | |
232 are less random than the higher ones. We do this by using the | |
233 quotient rather than the remainder. At the high end of the RNG | |
234 it's possible to get a quotient larger than limit; discarding | |
235 these values eliminates the bias that would otherwise appear | |
236 when using a large limit. */ | |
2039 | 237 denominator = ((unsigned long)1 << INT_VALBITS) / XINT (limit); |
428 | 238 do |
239 val = get_random () / denominator; | |
240 while (val >= XINT (limit)); | |
241 } | |
1983 | 242 #ifdef HAVE_BIGNUM |
243 else if (BIGNUMP (limit)) | |
244 { | |
245 bignum_random (scratch_bignum, XBIGNUM_DATA (limit)); | |
246 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
247 } | |
248 #endif | |
428 | 249 else |
250 val = get_random (); | |
251 | |
252 return make_int (val); | |
253 } | |
254 | |
255 /* Random data-structure functions */ | |
256 | |
257 #ifdef LOSING_BYTECODE | |
258 | |
259 /* #### Delete this shit */ | |
260 | |
261 /* Charcount is a misnomer here as we might be dealing with the | |
262 length of a vector or list, but emphasizes that we're not dealing | |
263 with Bytecounts in strings */ | |
264 static Charcount | |
265 length_with_bytecode_hack (Lisp_Object seq) | |
266 { | |
267 if (!COMPILED_FUNCTIONP (seq)) | |
268 return XINT (Flength (seq)); | |
269 else | |
270 { | |
440 | 271 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (seq); |
428 | 272 |
273 return (f->flags.interactivep ? COMPILED_INTERACTIVE : | |
274 f->flags.domainp ? COMPILED_DOMAIN : | |
275 COMPILED_DOC_STRING) | |
276 + 1; | |
277 } | |
278 } | |
279 | |
280 #endif /* LOSING_BYTECODE */ | |
281 | |
282 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
|
283 check_losing_bytecode (const Ascbyte *function, Lisp_Object seq) |
428 | 284 { |
285 if (COMPILED_FUNCTIONP (seq)) | |
563 | 286 signal_ferror_with_frob |
287 (Qinvalid_argument, seq, | |
428 | 288 "As of 20.3, `%s' no longer works with compiled-function objects", |
289 function); | |
290 } | |
291 | |
292 DEFUN ("length", Flength, 1, 1, 0, /* | |
293 Return the length of vector, bit vector, list or string SEQUENCE. | |
294 */ | |
295 (sequence)) | |
296 { | |
297 retry: | |
298 if (STRINGP (sequence)) | |
826 | 299 return make_int (string_char_length (sequence)); |
428 | 300 else if (CONSP (sequence)) |
301 { | |
665 | 302 Elemcount len; |
428 | 303 GET_EXTERNAL_LIST_LENGTH (sequence, len); |
304 return make_int (len); | |
305 } | |
306 else if (VECTORP (sequence)) | |
307 return make_int (XVECTOR_LENGTH (sequence)); | |
308 else if (NILP (sequence)) | |
309 return Qzero; | |
310 else if (BIT_VECTORP (sequence)) | |
311 return make_int (bit_vector_length (XBIT_VECTOR (sequence))); | |
312 else | |
313 { | |
314 check_losing_bytecode ("length", sequence); | |
315 sequence = wrong_type_argument (Qsequencep, sequence); | |
316 goto retry; | |
317 } | |
318 } | |
319 | |
320 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /* | |
321 Return the length of a list, but avoid error or infinite loop. | |
322 This function never gets an error. If LIST is not really a list, | |
323 it returns 0. If LIST is circular, it returns a finite value | |
324 which is at least the number of distinct elements. | |
325 */ | |
326 (list)) | |
327 { | |
328 Lisp_Object hare, tortoise; | |
665 | 329 Elemcount len; |
428 | 330 |
331 for (hare = tortoise = list, len = 0; | |
332 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); | |
333 hare = XCDR (hare), len++) | |
334 { | |
335 if (len & 1) | |
336 tortoise = XCDR (tortoise); | |
337 } | |
338 | |
339 return make_int (len); | |
340 } | |
341 | |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
342 /* This is almost the above, but is defined by Common Lisp. We need it in C |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
343 for shortest_length_among_sequences(), below, for the various sequence |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
344 functions that can usefully operate on circular lists. */ |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
345 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
346 DEFUN ("list-length", Flist_length, 1, 1, 0, /* |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
347 Return the length of LIST. Return nil if LIST is circular. |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
348 */ |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
349 (list)) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
350 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
351 Lisp_Object hare, tortoise; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
352 Elemcount len; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
353 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
354 for (hare = tortoise = list, len = 0; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
355 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
356 hare = XCDR (hare), len++) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
357 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
358 if (len & 1) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
359 tortoise = XCDR (tortoise); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
360 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
361 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
362 return EQ (hare, tortoise) && len != 0 ? Qnil : make_int (len); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
363 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
364 |
428 | 365 /*** string functions. ***/ |
366 | |
367 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /* | |
368 Return t if two strings have identical contents. | |
369 Case is significant. Text properties are ignored. | |
370 \(Under XEmacs, `equal' also ignores text properties and extents in | |
371 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20 | |
372 `equal' is the same as in XEmacs, in that respect.) | |
373 Symbols are also allowed; their print names are used instead. | |
374 */ | |
444 | 375 (string1, string2)) |
428 | 376 { |
377 Bytecount len; | |
793 | 378 Lisp_Object p1, p2; |
428 | 379 |
444 | 380 if (SYMBOLP (string1)) |
381 p1 = XSYMBOL (string1)->name; | |
428 | 382 else |
383 { | |
444 | 384 CHECK_STRING (string1); |
793 | 385 p1 = string1; |
428 | 386 } |
387 | |
444 | 388 if (SYMBOLP (string2)) |
389 p2 = XSYMBOL (string2)->name; | |
428 | 390 else |
391 { | |
444 | 392 CHECK_STRING (string2); |
793 | 393 p2 = string2; |
428 | 394 } |
395 | |
793 | 396 return (((len = XSTRING_LENGTH (p1)) == XSTRING_LENGTH (p2)) && |
397 !memcmp (XSTRING_DATA (p1), XSTRING_DATA (p2), len)) ? Qt : Qnil; | |
428 | 398 } |
399 | |
801 | 400 DEFUN ("compare-strings", Fcompare_strings, 6, 7, 0, /* |
401 Compare the contents of two strings, maybe ignoring case. | |
402 In string STR1, skip the first START1 characters and stop at END1. | |
403 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
|
404 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
|
405 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
|
406 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
|
407 |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
408 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
|
409 Case is significant by default. |
801 | 410 |
411 The value is t if the strings (or specified portions) match. | |
412 If string STR1 is less, the value is a negative number N; | |
413 - 1 - N is the number of characters that match at the beginning. | |
414 If string STR1 is greater, the value is a positive number N; | |
415 N - 1 is the number of characters that match at the beginning. | |
416 */ | |
417 (str1, start1, end1, str2, start2, end2, ignore_case)) | |
418 { | |
419 Charcount ccstart1, ccend1, ccstart2, ccend2; | |
420 Bytecount bstart1, blen1, bstart2, blen2; | |
421 Charcount matching; | |
422 int res; | |
423 | |
424 CHECK_STRING (str1); | |
425 CHECK_STRING (str2); | |
426 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
|
427 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 428 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
|
429 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 430 |
431 bstart1 = string_index_char_to_byte (str1, ccstart1); | |
432 blen1 = string_offset_char_to_byte_len (str1, bstart1, ccend1 - ccstart1); | |
433 bstart2 = string_index_char_to_byte (str2, ccstart2); | |
434 blen2 = string_offset_char_to_byte_len (str2, bstart2, ccend2 - ccstart2); | |
435 | |
436 res = ((NILP (ignore_case) ? qxetextcmp_matching : qxetextcasecmp_matching) | |
437 (XSTRING_DATA (str1) + bstart1, blen1, | |
438 XSTRING_DATA (str2) + bstart2, blen2, | |
439 &matching)); | |
440 | |
441 if (!res) | |
442 return Qt; | |
443 else if (res > 0) | |
444 return make_int (1 + matching); | |
445 else | |
446 return make_int (-1 - matching); | |
447 } | |
448 | |
428 | 449 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /* |
450 Return t if first arg string is less than second in lexicographic order. | |
771 | 451 Comparison is simply done on a character-by-character basis using the |
452 numeric value of a character. (Note that this may not produce | |
453 particularly meaningful results under Mule if characters from | |
454 different charsets are being compared.) | |
428 | 455 |
456 Symbols are also allowed; their print names are used instead. | |
457 | |
771 | 458 Currently we don't do proper language-specific collation or handle |
459 multiple character sets. This may be changed when Unicode support | |
460 is implemented. | |
428 | 461 */ |
444 | 462 (string1, string2)) |
428 | 463 { |
793 | 464 Lisp_Object p1, p2; |
428 | 465 Charcount end, len2; |
466 int i; | |
467 | |
444 | 468 if (SYMBOLP (string1)) |
469 p1 = XSYMBOL (string1)->name; | |
793 | 470 else |
471 { | |
444 | 472 CHECK_STRING (string1); |
793 | 473 p1 = string1; |
428 | 474 } |
475 | |
444 | 476 if (SYMBOLP (string2)) |
477 p2 = XSYMBOL (string2)->name; | |
428 | 478 else |
479 { | |
444 | 480 CHECK_STRING (string2); |
793 | 481 p2 = string2; |
428 | 482 } |
483 | |
826 | 484 end = string_char_length (p1); |
485 len2 = string_char_length (p2); | |
428 | 486 if (end > len2) |
487 end = len2; | |
488 | |
489 { | |
867 | 490 Ibyte *ptr1 = XSTRING_DATA (p1); |
491 Ibyte *ptr2 = XSTRING_DATA (p2); | |
428 | 492 |
493 /* #### It is not really necessary to do this: We could compare | |
494 byte-by-byte and still get a reasonable comparison, since this | |
495 would compare characters with a charset in the same way. With | |
496 a little rearrangement of the leading bytes, we could make most | |
497 inter-charset comparisons work out the same, too; even if some | |
498 don't, this is not a big deal because inter-charset comparisons | |
499 aren't really well-defined anyway. */ | |
500 for (i = 0; i < end; i++) | |
501 { | |
867 | 502 if (itext_ichar (ptr1) != itext_ichar (ptr2)) |
503 return itext_ichar (ptr1) < itext_ichar (ptr2) ? Qt : Qnil; | |
504 INC_IBYTEPTR (ptr1); | |
505 INC_IBYTEPTR (ptr2); | |
428 | 506 } |
507 } | |
508 /* Can't do i < len2 because then comparison between "foo" and "foo^@" | |
509 won't work right in I18N2 case */ | |
510 return end < len2 ? Qt : Qnil; | |
511 } | |
512 | |
513 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /* | |
514 Return STRING's tick counter, incremented for each change to the string. | |
515 Each string has a tick counter which is incremented each time the contents | |
516 of the string are changed (e.g. with `aset'). It wraps around occasionally. | |
517 */ | |
518 (string)) | |
519 { | |
520 CHECK_STRING (string); | |
793 | 521 if (CONSP (XSTRING_PLIST (string)) && INTP (XCAR (XSTRING_PLIST (string)))) |
522 return XCAR (XSTRING_PLIST (string)); | |
428 | 523 else |
524 return Qzero; | |
525 } | |
526 | |
527 void | |
528 bump_string_modiff (Lisp_Object str) | |
529 { | |
793 | 530 Lisp_Object *ptr = &XSTRING_PLIST (str); |
428 | 531 |
532 #ifdef I18N3 | |
533 /* #### remove the `string-translatable' property from the string, | |
534 if there is one. */ | |
535 #endif | |
536 /* skip over extent info if it's there */ | |
537 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
538 ptr = &XCDR (*ptr); | |
539 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
793 | 540 XCAR (*ptr) = make_int (1+XINT (XCAR (*ptr))); |
428 | 541 else |
542 *ptr = Fcons (make_int (1), *ptr); | |
543 } | |
544 | |
545 | |
546 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector }; | |
547 static Lisp_Object concat (int nargs, Lisp_Object *args, | |
548 enum concat_target_type target_type, | |
549 int last_special); | |
550 | |
551 Lisp_Object | |
444 | 552 concat2 (Lisp_Object string1, Lisp_Object string2) |
428 | 553 { |
554 Lisp_Object args[2]; | |
444 | 555 args[0] = string1; |
556 args[1] = string2; | |
428 | 557 return concat (2, args, c_string, 0); |
558 } | |
559 | |
560 Lisp_Object | |
444 | 561 concat3 (Lisp_Object string1, Lisp_Object string2, Lisp_Object string3) |
428 | 562 { |
563 Lisp_Object args[3]; | |
444 | 564 args[0] = string1; |
565 args[1] = string2; | |
566 args[2] = string3; | |
428 | 567 return concat (3, args, c_string, 0); |
568 } | |
569 | |
570 Lisp_Object | |
444 | 571 vconcat2 (Lisp_Object vec1, Lisp_Object vec2) |
428 | 572 { |
573 Lisp_Object args[2]; | |
444 | 574 args[0] = vec1; |
575 args[1] = vec2; | |
428 | 576 return concat (2, args, c_vector, 0); |
577 } | |
578 | |
579 Lisp_Object | |
444 | 580 vconcat3 (Lisp_Object vec1, Lisp_Object vec2, Lisp_Object vec3) |
428 | 581 { |
582 Lisp_Object args[3]; | |
444 | 583 args[0] = vec1; |
584 args[1] = vec2; | |
585 args[2] = vec3; | |
428 | 586 return concat (3, args, c_vector, 0); |
587 } | |
588 | |
589 DEFUN ("append", Fappend, 0, MANY, 0, /* | |
590 Concatenate all the arguments and make the result a list. | |
591 The result is a list whose elements are the elements of all the arguments. | |
592 Each argument may be a list, vector, bit vector, or string. | |
593 The last argument is not copied, just used as the tail of the new list. | |
594 Also see: `nconc'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
595 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
596 arguments: (&rest ARGS) |
428 | 597 */ |
598 (int nargs, Lisp_Object *args)) | |
599 { | |
600 return concat (nargs, args, c_cons, 1); | |
601 } | |
602 | |
603 DEFUN ("concat", Fconcat, 0, MANY, 0, /* | |
604 Concatenate all the arguments and make the result a string. | |
605 The result is a string whose elements are the elements of all the arguments. | |
606 Each argument may be a string or a list or vector of characters. | |
607 | |
608 As of XEmacs 21.0, this function does NOT accept individual integers | |
609 as arguments. Old code that relies on, for example, (concat "foo" 50) | |
610 returning "foo50" will fail. To fix such code, either apply | |
611 `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
|
612 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
613 arguments: (&rest ARGS) |
428 | 614 */ |
615 (int nargs, Lisp_Object *args)) | |
616 { | |
617 return concat (nargs, args, c_string, 0); | |
618 } | |
619 | |
620 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /* | |
621 Concatenate all the arguments and make the result a vector. | |
622 The result is a vector whose elements are the elements of all the arguments. | |
623 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
|
624 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
625 arguments: (&rest ARGS) |
428 | 626 */ |
627 (int nargs, Lisp_Object *args)) | |
628 { | |
629 return concat (nargs, args, c_vector, 0); | |
630 } | |
631 | |
632 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /* | |
633 Concatenate all the arguments and make the result a bit vector. | |
634 The result is a bit vector whose elements are the elements of all the | |
635 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
|
636 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
637 arguments: (&rest ARGS) |
428 | 638 */ |
639 (int nargs, Lisp_Object *args)) | |
640 { | |
641 return concat (nargs, args, c_bit_vector, 0); | |
642 } | |
643 | |
644 /* Copy a (possibly dotted) list. LIST must be a cons. | |
645 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */ | |
646 static Lisp_Object | |
647 copy_list (Lisp_Object list) | |
648 { | |
649 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list)); | |
650 Lisp_Object last = list_copy; | |
651 Lisp_Object hare, tortoise; | |
665 | 652 Elemcount len; |
428 | 653 |
654 for (tortoise = hare = XCDR (list), len = 1; | |
655 CONSP (hare); | |
656 hare = XCDR (hare), len++) | |
657 { | |
658 XCDR (last) = Fcons (XCAR (hare), XCDR (hare)); | |
659 last = XCDR (last); | |
660 | |
661 if (len < CIRCULAR_LIST_SUSPICION_LENGTH) | |
662 continue; | |
663 if (len & 1) | |
664 tortoise = XCDR (tortoise); | |
665 if (EQ (tortoise, hare)) | |
666 signal_circular_list_error (list); | |
667 } | |
668 | |
669 return list_copy; | |
670 } | |
671 | |
672 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /* | |
673 Return a copy of list LIST, which may be a dotted list. | |
674 The elements of LIST are not copied; they are shared | |
675 with the original. | |
676 */ | |
677 (list)) | |
678 { | |
679 again: | |
680 if (NILP (list)) return list; | |
681 if (CONSP (list)) return copy_list (list); | |
682 | |
683 list = wrong_type_argument (Qlistp, list); | |
684 goto again; | |
685 } | |
686 | |
687 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /* | |
688 Return a copy of list, vector, bit vector or string SEQUENCE. | |
689 The elements of a list or vector are not copied; they are shared | |
690 with the original. SEQUENCE may be a dotted list. | |
691 */ | |
692 (sequence)) | |
693 { | |
694 again: | |
695 if (NILP (sequence)) return sequence; | |
696 if (CONSP (sequence)) return copy_list (sequence); | |
697 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0); | |
698 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0); | |
699 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0); | |
700 | |
701 check_losing_bytecode ("copy-sequence", sequence); | |
702 sequence = wrong_type_argument (Qsequencep, sequence); | |
703 goto again; | |
704 } | |
705 | |
706 struct merge_string_extents_struct | |
707 { | |
708 Lisp_Object string; | |
709 Bytecount entry_offset; | |
710 Bytecount entry_length; | |
711 }; | |
712 | |
713 static Lisp_Object | |
714 concat (int nargs, Lisp_Object *args, | |
715 enum concat_target_type target_type, | |
716 int last_special) | |
717 { | |
718 Lisp_Object val; | |
719 Lisp_Object tail = Qnil; | |
720 int toindex; | |
721 int argnum; | |
722 Lisp_Object last_tail; | |
723 Lisp_Object prev; | |
724 struct merge_string_extents_struct *args_mse = 0; | |
867 | 725 Ibyte *string_result = 0; |
726 Ibyte *string_result_ptr = 0; | |
428 | 727 struct gcpro gcpro1; |
851 | 728 int sdep = specpdl_depth (); |
428 | 729 |
730 /* The modus operandi in Emacs is "caller gc-protects args". | |
731 However, concat is called many times in Emacs on freshly | |
732 created stuff. So we help those callers out by protecting | |
733 the args ourselves to save them a lot of temporary-variable | |
734 grief. */ | |
735 | |
736 GCPRO1 (args[0]); | |
737 gcpro1.nvars = nargs; | |
738 | |
739 #ifdef I18N3 | |
740 /* #### if the result is a string and any of the strings have a string | |
741 for the `string-translatable' property, then concat should also | |
742 concat the args but use the `string-translatable' strings, and store | |
743 the result in the returned string's `string-translatable' property. */ | |
744 #endif | |
745 if (target_type == c_string) | |
746 args_mse = alloca_array (struct merge_string_extents_struct, nargs); | |
747 | |
748 /* In append, the last arg isn't treated like the others */ | |
749 if (last_special && nargs > 0) | |
750 { | |
751 nargs--; | |
752 last_tail = args[nargs]; | |
753 } | |
754 else | |
755 last_tail = Qnil; | |
756 | |
757 /* Check and coerce the arguments. */ | |
758 for (argnum = 0; argnum < nargs; argnum++) | |
759 { | |
760 Lisp_Object seq = args[argnum]; | |
761 if (LISTP (seq)) | |
762 ; | |
763 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq)) | |
764 ; | |
765 #ifdef LOSING_BYTECODE | |
766 else if (COMPILED_FUNCTIONP (seq)) | |
767 /* Urk! We allow this, for "compatibility"... */ | |
768 ; | |
769 #endif | |
770 #if 0 /* removed for XEmacs 21 */ | |
771 else if (INTP (seq)) | |
772 /* This is too revolting to think about but maintains | |
773 compatibility with FSF (and lots and lots of old code). */ | |
774 args[argnum] = Fnumber_to_string (seq); | |
775 #endif | |
776 else | |
777 { | |
778 check_losing_bytecode ("concat", seq); | |
779 args[argnum] = wrong_type_argument (Qsequencep, seq); | |
780 } | |
781 | |
782 if (args_mse) | |
783 { | |
784 if (STRINGP (seq)) | |
785 args_mse[argnum].string = seq; | |
786 else | |
787 args_mse[argnum].string = Qnil; | |
788 } | |
789 } | |
790 | |
791 { | |
792 /* Charcount is a misnomer here as we might be dealing with the | |
793 length of a vector or list, but emphasizes that we're not dealing | |
794 with Bytecounts in strings */ | |
795 Charcount total_length; | |
796 | |
797 for (argnum = 0, total_length = 0; argnum < nargs; argnum++) | |
798 { | |
799 #ifdef LOSING_BYTECODE | |
800 Charcount thislen = length_with_bytecode_hack (args[argnum]); | |
801 #else | |
802 Charcount thislen = XINT (Flength (args[argnum])); | |
803 #endif | |
804 total_length += thislen; | |
805 } | |
806 | |
807 switch (target_type) | |
808 { | |
809 case c_cons: | |
810 if (total_length == 0) | |
851 | 811 { |
812 unbind_to (sdep); | |
813 /* In append, if all but last arg are nil, return last arg */ | |
814 RETURN_UNGCPRO (last_tail); | |
815 } | |
428 | 816 val = Fmake_list (make_int (total_length), Qnil); |
817 break; | |
818 case c_vector: | |
819 val = make_vector (total_length, Qnil); | |
820 break; | |
821 case c_bit_vector: | |
822 val = make_bit_vector (total_length, Qzero); | |
823 break; | |
824 case c_string: | |
825 /* We don't make the string yet because we don't know the | |
826 actual number of bytes. This loop was formerly written | |
827 to call Fmake_string() here and then call set_string_char() | |
828 for each char. This seems logical enough but is waaaaaaaay | |
829 slow -- set_string_char() has to scan the whole string up | |
830 to the place where the substitution is called for in order | |
831 to find the place to change, and may have to do some | |
832 realloc()ing in order to make the char fit properly. | |
833 O(N^2) yuckage. */ | |
834 val = Qnil; | |
851 | 835 string_result = |
867 | 836 (Ibyte *) MALLOC_OR_ALLOCA (total_length * MAX_ICHAR_LEN); |
428 | 837 string_result_ptr = string_result; |
838 break; | |
839 default: | |
442 | 840 val = Qnil; |
2500 | 841 ABORT (); |
428 | 842 } |
843 } | |
844 | |
845 | |
846 if (CONSP (val)) | |
847 tail = val, toindex = -1; /* -1 in toindex is flag we are | |
848 making a list */ | |
849 else | |
850 toindex = 0; | |
851 | |
852 prev = Qnil; | |
853 | |
854 for (argnum = 0; argnum < nargs; argnum++) | |
855 { | |
856 Charcount thisleni = 0; | |
857 Charcount thisindex = 0; | |
858 Lisp_Object seq = args[argnum]; | |
867 | 859 Ibyte *string_source_ptr = 0; |
860 Ibyte *string_prev_result_ptr = string_result_ptr; | |
428 | 861 |
862 if (!CONSP (seq)) | |
863 { | |
864 #ifdef LOSING_BYTECODE | |
865 thisleni = length_with_bytecode_hack (seq); | |
866 #else | |
867 thisleni = XINT (Flength (seq)); | |
868 #endif | |
869 } | |
870 if (STRINGP (seq)) | |
871 string_source_ptr = XSTRING_DATA (seq); | |
872 | |
873 while (1) | |
874 { | |
875 Lisp_Object elt; | |
876 | |
877 /* We've come to the end of this arg, so exit. */ | |
878 if (NILP (seq)) | |
879 break; | |
880 | |
881 /* Fetch next element of `seq' arg into `elt' */ | |
882 if (CONSP (seq)) | |
883 { | |
884 elt = XCAR (seq); | |
885 seq = XCDR (seq); | |
886 } | |
887 else | |
888 { | |
889 if (thisindex >= thisleni) | |
890 break; | |
891 | |
892 if (STRINGP (seq)) | |
893 { | |
867 | 894 elt = make_char (itext_ichar (string_source_ptr)); |
895 INC_IBYTEPTR (string_source_ptr); | |
428 | 896 } |
897 else if (VECTORP (seq)) | |
898 elt = XVECTOR_DATA (seq)[thisindex]; | |
899 else if (BIT_VECTORP (seq)) | |
900 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq), | |
901 thisindex)); | |
902 else | |
903 elt = Felt (seq, make_int (thisindex)); | |
904 thisindex++; | |
905 } | |
906 | |
907 /* Store into result */ | |
908 if (toindex < 0) | |
909 { | |
910 /* toindex negative means we are making a list */ | |
911 XCAR (tail) = elt; | |
912 prev = tail; | |
913 tail = XCDR (tail); | |
914 } | |
915 else if (VECTORP (val)) | |
916 XVECTOR_DATA (val)[toindex++] = elt; | |
917 else if (BIT_VECTORP (val)) | |
918 { | |
919 CHECK_BIT (elt); | |
920 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt)); | |
921 } | |
922 else | |
923 { | |
924 CHECK_CHAR_COERCE_INT (elt); | |
867 | 925 string_result_ptr += set_itext_ichar (string_result_ptr, |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
926 XCHAR (elt)); |
428 | 927 } |
928 } | |
929 if (args_mse) | |
930 { | |
931 args_mse[argnum].entry_offset = | |
932 string_prev_result_ptr - string_result; | |
933 args_mse[argnum].entry_length = | |
934 string_result_ptr - string_prev_result_ptr; | |
935 } | |
936 } | |
937 | |
938 /* Now we finally make the string. */ | |
939 if (target_type == c_string) | |
940 { | |
941 val = make_string (string_result, string_result_ptr - string_result); | |
942 for (argnum = 0; argnum < nargs; argnum++) | |
943 { | |
944 if (STRINGP (args_mse[argnum].string)) | |
945 copy_string_extents (val, args_mse[argnum].string, | |
946 args_mse[argnum].entry_offset, 0, | |
947 args_mse[argnum].entry_length); | |
948 } | |
949 } | |
950 | |
951 if (!NILP (prev)) | |
952 XCDR (prev) = last_tail; | |
953 | |
851 | 954 unbind_to (sdep); |
428 | 955 RETURN_UNGCPRO (val); |
956 } | |
957 | |
958 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /* | |
959 Return a copy of ALIST. | |
960 This is an alist which represents the same mapping from objects to objects, | |
961 but does not share the alist structure with ALIST. | |
962 The objects mapped (cars and cdrs of elements of the alist) | |
963 are shared, however. | |
964 Elements of ALIST that are not conses are also shared. | |
965 */ | |
966 (alist)) | |
967 { | |
968 Lisp_Object tail; | |
969 | |
970 if (NILP (alist)) | |
971 return alist; | |
972 CHECK_CONS (alist); | |
973 | |
974 alist = concat (1, &alist, c_cons, 0); | |
975 for (tail = alist; CONSP (tail); tail = XCDR (tail)) | |
976 { | |
977 Lisp_Object car = XCAR (tail); | |
978 | |
979 if (CONSP (car)) | |
980 XCAR (tail) = Fcons (XCAR (car), XCDR (car)); | |
981 } | |
982 return alist; | |
983 } | |
984 | |
985 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /* | |
986 Return a copy of a list and substructures. | |
987 The argument is copied, and any lists contained within it are copied | |
988 recursively. Circularities and shared substructures are not preserved. | |
989 Second arg VECP causes vectors to be copied, too. Strings and bit vectors | |
990 are not copied. | |
991 */ | |
992 (arg, vecp)) | |
993 { | |
454 | 994 return safe_copy_tree (arg, vecp, 0); |
995 } | |
996 | |
997 Lisp_Object | |
998 safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth) | |
999 { | |
1000 if (depth > 200) | |
563 | 1001 stack_overflow ("Stack overflow in copy-tree", arg); |
454 | 1002 |
428 | 1003 if (CONSP (arg)) |
1004 { | |
1005 Lisp_Object rest; | |
1006 rest = arg = Fcopy_sequence (arg); | |
1007 while (CONSP (rest)) | |
1008 { | |
1009 Lisp_Object elt = XCAR (rest); | |
1010 QUIT; | |
1011 if (CONSP (elt) || VECTORP (elt)) | |
454 | 1012 XCAR (rest) = safe_copy_tree (elt, vecp, depth + 1); |
428 | 1013 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */ |
454 | 1014 XCDR (rest) = safe_copy_tree (XCDR (rest), vecp, depth +1); |
428 | 1015 rest = XCDR (rest); |
1016 } | |
1017 } | |
1018 else if (VECTORP (arg) && ! NILP (vecp)) | |
1019 { | |
1020 int i = XVECTOR_LENGTH (arg); | |
1021 int j; | |
1022 arg = Fcopy_sequence (arg); | |
1023 for (j = 0; j < i; j++) | |
1024 { | |
1025 Lisp_Object elt = XVECTOR_DATA (arg) [j]; | |
1026 QUIT; | |
1027 if (CONSP (elt) || VECTORP (elt)) | |
454 | 1028 XVECTOR_DATA (arg) [j] = safe_copy_tree (elt, vecp, depth + 1); |
428 | 1029 } |
1030 } | |
1031 return arg; | |
1032 } | |
1033 | |
1034 DEFUN ("subseq", Fsubseq, 2, 3, 0, /* | |
442 | 1035 Return the subsequence of SEQUENCE starting at START and ending before END. |
1036 END may be omitted; then the subsequence runs to the end of SEQUENCE. | |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1037 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1038 If START or END is negative, it counts from the end, in contravention of |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1039 Common Lisp. |
442 | 1040 The returned subsequence is always of the same type as SEQUENCE. |
1041 If SEQUENCE is a string, relevant parts of the string-extent-data | |
1042 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
|
1043 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1044 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
|
1045 not copy extent data. |
428 | 1046 */ |
442 | 1047 (sequence, start, end)) |
428 | 1048 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1049 Elemcount len, ss, ee = EMACS_INT_MAX, ii; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1050 Lisp_Object result = Qnil; |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5051
diff
changeset
|
1051 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1052 CHECK_SEQUENCE (sequence); |
442 | 1053 CHECK_INT (start); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1054 ss = XINT (start); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1055 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1056 if (!NILP (end)) |
428 | 1057 { |
442 | 1058 CHECK_INT (end); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1059 ee = XINT (end); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1060 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1061 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1062 if (STRINGP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1063 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1064 Bytecount bstart, blen; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1065 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1066 get_string_range_char (sequence, start, end, &ss, &ee, |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1067 GB_HISTORICAL_STRING_BEHAVIOR); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1068 bstart = string_index_char_to_byte (sequence, ss); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1069 blen = string_offset_char_to_byte_len (sequence, bstart, ee - ss); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1070 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1071 result = make_string (XSTRING_DATA (sequence) + bstart, blen); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1072 /* Copy any applicable extent information into the new string. */ |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1073 copy_string_extents (result, sequence, 0, bstart, blen); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1074 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1075 else if (CONSP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1076 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1077 Lisp_Object result_tail, saved = sequence; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1078 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1079 if (ss < 0 || ee < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1080 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1081 len = XINT (Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1082 if (ss < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1083 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1084 ss = len + ss; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1085 start = make_integer (ss); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1086 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1087 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1088 if (ee < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1089 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1090 ee = len + ee; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1091 end = make_integer (ee); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1092 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1093 else |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1094 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1095 ee = min (ee, len); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1096 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1097 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1098 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1099 if (0 != ss) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1100 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1101 sequence = Fnthcdr (make_int (ss), sequence); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1102 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1103 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1104 if (ss < ee && !NILP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1105 { |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
1106 result = result_tail = Fcons (Fcar (sequence), Qnil); |
442 | 1107 sequence = Fcdr (sequence); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1108 ii = ss + 1; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1109 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1110 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1111 EXTERNAL_LIST_LOOP_2 (elt, sequence) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1112 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1113 if (!(ii < ee)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1114 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1115 break; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1116 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1117 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1118 XSETCDR (result_tail, Fcons (elt, Qnil)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1119 result_tail = XCDR (result_tail); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1120 ii++; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1121 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1122 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1123 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1124 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1125 if (NILP (result) || (ii < ee && !NILP (end))) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1126 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1127 /* We were handed a cons, which definitely has elements. nil |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1128 result means either ss >= ee or SEQUENCE was nil after the |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1129 nthcdr; in both cases that means START and END were incorrectly |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1130 specified for this sequence. ii < ee with a non-nil end means |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1131 the user handed us a bogus end value. */ |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1132 check_sequence_range (saved, start, end, Flength (saved)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1133 } |
442 | 1134 } |
1135 else | |
1136 { | |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1137 len = XINT (Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1138 if (ss < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1139 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1140 ss = len + ss; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1141 start = make_integer (ss); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1142 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1143 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1144 if (ee < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1145 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1146 ee = len + ee; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1147 end = make_integer (ee); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1148 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1149 else |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1150 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1151 ee = min (len, ee); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1152 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1153 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1154 check_sequence_range (sequence, start, end, make_int (len)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1155 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1156 if (VECTORP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1157 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1158 result = Fvector (ee - ss, XVECTOR_DATA (sequence) + ss); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1159 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1160 else if (BIT_VECTORP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1161 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1162 result = make_bit_vector (ee - ss, Qzero); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1163 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1164 for (ii = ss; ii < ee; ii++) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1165 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1166 set_bit_vector_bit (XBIT_VECTOR (result), ii - ss, |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1167 bit_vector_bit (XBIT_VECTOR (sequence), ii)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1168 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1169 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1170 else if (NILP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1171 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1172 DO_NOTHING; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1173 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1174 else |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1175 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1176 /* Won't happen, since CHECK_SEQUENCE didn't error. */ |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1177 ABORT (); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1178 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1179 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1180 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1181 return result; |
428 | 1182 } |
1183 | |
5224
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1184 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
|
1185 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
|
1186 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
|
1187 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
|
1188 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1189 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
|
1190 */ |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1191 (string, start, end)) |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1192 { |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1193 Charcount ccstart, ccend; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1194 Bytecount bstart, blen; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1195 Lisp_Object val; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1196 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1197 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
|
1198 GB_HISTORICAL_STRING_BEHAVIOR); |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1199 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
|
1200 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
|
1201 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
|
1202 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1203 return val; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1204 } |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1205 |
771 | 1206 /* 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
|
1207 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
|
1208 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1209 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
|
1210 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
|
1211 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
|
1212 |
771 | 1213 static Lisp_Object |
867 | 1214 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
|
1215 Ichar sepchar, int unescape, Ichar escapechar) |
771 | 1216 { |
1217 Lisp_Object result = Qnil; | |
867 | 1218 const Ibyte *end = string + size; |
771 | 1219 |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1220 if (unescape) |
771 | 1221 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1222 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
|
1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1229 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1230 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1231 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
|
1232 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
|
1233 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
|
1234 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1235 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
|
1236 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1237 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
|
1238 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1239 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
|
1240 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1241 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
|
1242 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1243 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1244 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1245 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1246 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
|
1247 /* 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
|
1248 && !previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1249 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1250 ++deleting_escapes; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1251 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
|
1252 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1253 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1254 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1255 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
|
1256 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1257 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1258 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
|
1259 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1260 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1261 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
|
1262 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1263 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
|
1264 > 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
|
1265 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1266 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
|
1267 ((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
|
1268 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
|
1269 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1270 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1271 cursor = string; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1272 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
|
1273 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
|
1274 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1275 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
|
1276 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1277 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
|
1278 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1279 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
|
1280 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1281 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
|
1282 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
|
1283 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
|
1284 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1285 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1286 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
|
1287 && (pchar == escapechar); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1288 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1289 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
|
1290 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1291 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1292 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
|
1293 unescape_cursor |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1294 - 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
|
1295 result); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1296 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1297 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1298 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1299 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
|
1300 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1301 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
|
1302 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1303 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1304 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
|
1305 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1306 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1307 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1308 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1309 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1310 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1311 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1312 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1313 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1314 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
|
1315 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
|
1316 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1317 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
|
1318 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1319 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
|
1320 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1321 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
|
1322 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
|
1323 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1324 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1325 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
|
1326 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1327 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1328 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1329 } |
771 | 1330 } |
1331 return Fnreverse (result); | |
1332 } | |
1333 | |
1334 /* The same as the above, except PATH is an external C string (it is | |
1335 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR | |
1336 (':' or whatever). */ | |
1337 Lisp_Object | |
1338 split_external_path (const Extbyte *path) | |
1339 { | |
1340 Bytecount newlen; | |
867 | 1341 Ibyte *newpath; |
771 | 1342 if (!path) |
1343 return Qnil; | |
1344 | |
1345 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name); | |
1346 | |
1347 /* #### Does this make sense? It certainly does for | |
1348 split_env_path(), but it looks dubious here. Does any code | |
1349 depend on split_external_path("") returning nil instead of an empty | |
1350 string? */ | |
1351 if (!newlen) | |
1352 return Qnil; | |
1353 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1354 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR, 0, 0); |
771 | 1355 } |
1356 | |
1357 Lisp_Object | |
867 | 1358 split_env_path (const CIbyte *evarname, const Ibyte *default_) |
771 | 1359 { |
867 | 1360 const Ibyte *path = 0; |
771 | 1361 if (evarname) |
1362 path = egetenv (evarname); | |
1363 if (!path) | |
1364 path = default_; | |
1365 if (!path) | |
1366 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
|
1367 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR, 0, 0); |
771 | 1368 } |
1369 | |
1370 /* Ben thinks this function should not exist or be exported to Lisp. | |
1371 We use it to define split-path-string in subr.el (not!). */ | |
1372 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1373 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 3, 0, /* |
771 | 1374 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
|
1375 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1376 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
|
1377 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
|
1378 will be necessary for a single ESCAPE-CHAR to appear in the output string. |
771 | 1379 */ |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1380 (string, sepchar, escape_char)) |
771 | 1381 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1382 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
|
1383 |
771 | 1384 CHECK_STRING (string); |
1385 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
|
1386 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
|
1387 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1388 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
|
1389 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
|
1390 } |
867 | 1391 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
|
1392 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
|
1393 XCHAR (sepchar), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1394 !NILP (escape_char), escape_ichar); |
771 | 1395 } |
1396 | |
1397 /* #### This was supposed to be in subr.el, but is used VERY early in | |
1398 the bootstrap process, so it goes here. Damn. */ | |
1399 | |
1400 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /* | |
1401 Explode a search path into a list of strings. | |
1402 The path components are separated with the characters specified | |
1403 with `path-separator'. | |
1404 */ | |
1405 (path)) | |
1406 { | |
1407 CHECK_STRING (path); | |
1408 | |
1409 while (!STRINGP (Vpath_separator) | |
826 | 1410 || (string_char_length (Vpath_separator) != 1)) |
771 | 1411 Vpath_separator = signal_continuable_error |
1412 (Qinvalid_state, | |
1413 "`path-separator' should be set to a single-character string", | |
1414 Vpath_separator); | |
1415 | |
867 | 1416 return (split_string_by_ichar_1 |
771 | 1417 (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
|
1418 itext_ichar (XSTRING_DATA (Vpath_separator)), 0, 0)); |
771 | 1419 } |
1420 | |
428 | 1421 |
1422 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* | |
1423 Take cdr N times on LIST, and return the result. | |
1424 */ | |
1425 (n, list)) | |
1426 { | |
1920 | 1427 /* This function can GC */ |
647 | 1428 REGISTER EMACS_INT i; |
428 | 1429 REGISTER Lisp_Object tail = list; |
1430 CHECK_NATNUM (n); | |
1431 for (i = XINT (n); i; i--) | |
1432 { | |
1433 if (CONSP (tail)) | |
1434 tail = XCDR (tail); | |
1435 else if (NILP (tail)) | |
1436 return Qnil; | |
1437 else | |
1438 { | |
1439 tail = wrong_type_argument (Qlistp, tail); | |
1440 i++; | |
1441 } | |
1442 } | |
1443 return tail; | |
1444 } | |
1445 | |
1446 DEFUN ("nth", Fnth, 2, 2, 0, /* | |
1447 Return the Nth element of LIST. | |
1448 N counts from zero. If LIST is not that long, nil is returned. | |
1449 */ | |
1450 (n, list)) | |
1451 { | |
1920 | 1452 /* This function can GC */ |
428 | 1453 return Fcar (Fnthcdr (n, list)); |
1454 } | |
1455 | |
1456 DEFUN ("elt", Felt, 2, 2, 0, /* | |
1457 Return element of SEQUENCE at index N. | |
1458 */ | |
1459 (sequence, n)) | |
1460 { | |
1920 | 1461 /* This function can GC */ |
428 | 1462 retry: |
1463 CHECK_INT_COERCE_CHAR (n); /* yuck! */ | |
1464 if (LISTP (sequence)) | |
1465 { | |
1466 Lisp_Object tem = Fnthcdr (n, sequence); | |
1467 /* #### Utterly, completely, fucking disgusting. | |
1468 * #### The whole point of "elt" is that it operates on | |
1469 * #### sequences, and does error- (bounds-) checking. | |
1470 */ | |
1471 if (CONSP (tem)) | |
1472 return XCAR (tem); | |
1473 else | |
1474 #if 1 | |
1475 /* This is The Way It Has Always Been. */ | |
1476 return Qnil; | |
1477 #else | |
1478 /* This is The Way Mly and Cltl2 say It Should Be. */ | |
1479 args_out_of_range (sequence, n); | |
1480 #endif | |
1481 } | |
1482 else if (STRINGP (sequence) || | |
1483 VECTORP (sequence) || | |
1484 BIT_VECTORP (sequence)) | |
1485 return Faref (sequence, n); | |
1486 #ifdef LOSING_BYTECODE | |
1487 else if (COMPILED_FUNCTIONP (sequence)) | |
1488 { | |
1489 EMACS_INT idx = XINT (n); | |
1490 if (idx < 0) | |
1491 { | |
1492 lose: | |
1493 args_out_of_range (sequence, n); | |
1494 } | |
1495 /* Utter perversity */ | |
1496 { | |
1497 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence); | |
1498 switch (idx) | |
1499 { | |
1500 case COMPILED_ARGLIST: | |
1501 return compiled_function_arglist (f); | |
1502 case COMPILED_INSTRUCTIONS: | |
1503 return compiled_function_instructions (f); | |
1504 case COMPILED_CONSTANTS: | |
1505 return compiled_function_constants (f); | |
1506 case COMPILED_STACK_DEPTH: | |
1507 return compiled_function_stack_depth (f); | |
1508 case COMPILED_DOC_STRING: | |
1509 return compiled_function_documentation (f); | |
1510 case COMPILED_DOMAIN: | |
1511 return compiled_function_domain (f); | |
1512 case COMPILED_INTERACTIVE: | |
1513 if (f->flags.interactivep) | |
1514 return compiled_function_interactive (f); | |
1515 /* if we return nil, can't tell interactive with no args | |
1516 from noninteractive. */ | |
1517 goto lose; | |
1518 default: | |
1519 goto lose; | |
1520 } | |
1521 } | |
1522 } | |
1523 #endif /* LOSING_BYTECODE */ | |
1524 else | |
1525 { | |
1526 check_losing_bytecode ("elt", sequence); | |
1527 sequence = wrong_type_argument (Qsequencep, sequence); | |
1528 goto retry; | |
1529 } | |
1530 } | |
1531 | |
1532 DEFUN ("last", Flast, 1, 2, 0, /* | |
1533 Return the tail of list LIST, of length N (default 1). | |
1534 LIST may be a dotted list, but not a circular list. | |
1535 Optional argument N must be a non-negative integer. | |
1536 If N is zero, then the atom that terminates the list is returned. | |
1537 If N is greater than the length of LIST, then LIST itself is returned. | |
1538 */ | |
1539 (list, n)) | |
1540 { | |
1541 EMACS_INT int_n, count; | |
1542 Lisp_Object retval, tortoise, hare; | |
1543 | |
1544 CHECK_LIST (list); | |
1545 | |
1546 if (NILP (n)) | |
1547 int_n = 1; | |
1548 else | |
1549 { | |
1550 CHECK_NATNUM (n); | |
1551 int_n = XINT (n); | |
1552 } | |
1553 | |
1554 for (retval = tortoise = hare = list, count = 0; | |
1555 CONSP (hare); | |
1556 hare = XCDR (hare), | |
1557 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0), | |
1558 count++) | |
1559 { | |
1560 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
1561 | |
1562 if (count & 1) | |
1563 tortoise = XCDR (tortoise); | |
1564 if (EQ (hare, tortoise)) | |
1565 signal_circular_list_error (list); | |
1566 } | |
1567 | |
1568 return retval; | |
1569 } | |
1570 | |
1571 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /* | |
1572 Modify LIST to remove the last N (default 1) elements. | |
1573 If LIST has N or fewer elements, nil is returned and LIST is unmodified. | |
1574 */ | |
1575 (list, n)) | |
1576 { | |
1577 EMACS_INT int_n; | |
1578 | |
1579 CHECK_LIST (list); | |
1580 | |
1581 if (NILP (n)) | |
1582 int_n = 1; | |
1583 else | |
1584 { | |
1585 CHECK_NATNUM (n); | |
1586 int_n = XINT (n); | |
1587 } | |
1588 | |
1589 { | |
1590 Lisp_Object last_cons = list; | |
1591 | |
1592 EXTERNAL_LIST_LOOP_1 (list) | |
1593 { | |
1594 if (int_n-- < 0) | |
1595 last_cons = XCDR (last_cons); | |
1596 } | |
1597 | |
1598 if (int_n >= 0) | |
1599 return Qnil; | |
1600 | |
1601 XCDR (last_cons) = Qnil; | |
1602 return list; | |
1603 } | |
1604 } | |
1605 | |
1606 DEFUN ("butlast", Fbutlast, 1, 2, 0, /* | |
1607 Return a copy of LIST with the last N (default 1) elements removed. | |
1608 If LIST has N or fewer elements, nil is returned. | |
1609 */ | |
1610 (list, n)) | |
1611 { | |
444 | 1612 EMACS_INT int_n; |
428 | 1613 |
1614 CHECK_LIST (list); | |
1615 | |
1616 if (NILP (n)) | |
1617 int_n = 1; | |
1618 else | |
1619 { | |
1620 CHECK_NATNUM (n); | |
1621 int_n = XINT (n); | |
1622 } | |
1623 | |
1624 { | |
1625 Lisp_Object retval = Qnil; | |
1626 Lisp_Object tail = list; | |
1627 | |
1628 EXTERNAL_LIST_LOOP_1 (list) | |
1629 { | |
1630 if (--int_n < 0) | |
1631 { | |
1632 retval = Fcons (XCAR (tail), retval); | |
1633 tail = XCDR (tail); | |
1634 } | |
1635 } | |
1636 | |
1637 return Fnreverse (retval); | |
1638 } | |
1639 } | |
1640 | |
1641 DEFUN ("member", Fmember, 2, 2, 0, /* | |
1642 Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | |
1643 The value is actually the tail of LIST whose car is ELT. | |
1644 */ | |
1645 (elt, list)) | |
1646 { | |
1647 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1648 { | |
1649 if (internal_equal (elt, list_elt, 0)) | |
1650 return tail; | |
1651 } | |
1652 return Qnil; | |
1653 } | |
1654 | |
1655 DEFUN ("old-member", Fold_member, 2, 2, 0, /* | |
1656 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'. | |
1657 The value is actually the tail of LIST whose car is ELT. | |
1658 This function is provided only for byte-code compatibility with v19. | |
1659 Do not use it. | |
1660 */ | |
1661 (elt, list)) | |
1662 { | |
1663 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1664 { | |
1665 if (internal_old_equal (elt, list_elt, 0)) | |
1666 return tail; | |
1667 } | |
1668 return Qnil; | |
1669 } | |
1670 | |
1671 DEFUN ("memq", Fmemq, 2, 2, 0, /* | |
1672 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. | |
1673 The value is actually the tail of LIST whose car is ELT. | |
1674 */ | |
1675 (elt, list)) | |
1676 { | |
1677 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1678 { | |
1679 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1680 return tail; | |
1681 } | |
1682 return Qnil; | |
1683 } | |
1684 | |
1685 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /* | |
1686 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'. | |
1687 The value is actually the tail of LIST whose car is ELT. | |
1688 This function is provided only for byte-code compatibility with v19. | |
1689 Do not use it. | |
1690 */ | |
1691 (elt, list)) | |
1692 { | |
1693 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1694 { | |
1695 if (HACKEQ_UNSAFE (elt, list_elt)) | |
1696 return tail; | |
1697 } | |
1698 return Qnil; | |
1699 } | |
1700 | |
1701 Lisp_Object | |
1702 memq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1703 { | |
1704 LIST_LOOP_3 (list_elt, list, tail) | |
1705 { | |
1706 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1707 return tail; | |
1708 } | |
1709 return Qnil; | |
1710 } | |
1711 | |
1712 DEFUN ("assoc", Fassoc, 2, 2, 0, /* | |
444 | 1713 Return non-nil if KEY is `equal' to the car of an element of ALIST. |
1714 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1715 */ |
444 | 1716 (key, alist)) |
428 | 1717 { |
1718 /* This function can GC. */ | |
444 | 1719 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1720 { |
1721 if (internal_equal (key, elt_car, 0)) | |
1722 return elt; | |
1723 } | |
1724 return Qnil; | |
1725 } | |
1726 | |
1727 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /* | |
444 | 1728 Return non-nil if KEY is `old-equal' to the car of an element of ALIST. |
1729 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1730 */ |
444 | 1731 (key, alist)) |
428 | 1732 { |
1733 /* This function can GC. */ | |
444 | 1734 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1735 { |
1736 if (internal_old_equal (key, elt_car, 0)) | |
1737 return elt; | |
1738 } | |
1739 return Qnil; | |
1740 } | |
1741 | |
1742 Lisp_Object | |
444 | 1743 assoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1744 { |
1745 int speccount = specpdl_depth (); | |
1746 specbind (Qinhibit_quit, Qt); | |
771 | 1747 return unbind_to_1 (speccount, Fassoc (key, alist)); |
428 | 1748 } |
1749 | |
1750 DEFUN ("assq", Fassq, 2, 2, 0, /* | |
444 | 1751 Return non-nil if KEY is `eq' to the car of an element of ALIST. |
1752 The value is actually the element of ALIST whose car is KEY. | |
1753 Elements of ALIST that are not conses are ignored. | |
428 | 1754 */ |
444 | 1755 (key, alist)) |
428 | 1756 { |
444 | 1757 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1758 { |
1759 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1760 return elt; | |
1761 } | |
1762 return Qnil; | |
1763 } | |
1764 | |
1765 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /* | |
444 | 1766 Return non-nil if KEY is `old-eq' to the car of an element of ALIST. |
1767 The value is actually the element of ALIST whose car is KEY. | |
1768 Elements of ALIST that are not conses are ignored. | |
428 | 1769 This function is provided only for byte-code compatibility with v19. |
1770 Do not use it. | |
1771 */ | |
444 | 1772 (key, alist)) |
428 | 1773 { |
444 | 1774 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1775 { |
1776 if (HACKEQ_UNSAFE (key, elt_car)) | |
1777 return elt; | |
1778 } | |
1779 return Qnil; | |
1780 } | |
1781 | |
1782 /* Like Fassq but never report an error and do not allow quits. | |
1783 Use only on lists known never to be circular. */ | |
1784 | |
1785 Lisp_Object | |
444 | 1786 assq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1787 { |
1788 /* This cannot GC. */ | |
444 | 1789 LIST_LOOP_2 (elt, alist) |
428 | 1790 { |
1791 Lisp_Object elt_car = XCAR (elt); | |
1792 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1793 return elt; | |
1794 } | |
1795 return Qnil; | |
1796 } | |
1797 | |
1798 DEFUN ("rassoc", Frassoc, 2, 2, 0, /* | |
444 | 1799 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST. |
1800 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1801 */ |
444 | 1802 (value, alist)) |
428 | 1803 { |
444 | 1804 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1805 { |
444 | 1806 if (internal_equal (value, elt_cdr, 0)) |
428 | 1807 return elt; |
1808 } | |
1809 return Qnil; | |
1810 } | |
1811 | |
1812 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /* | |
444 | 1813 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST. |
1814 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1815 */ |
444 | 1816 (value, alist)) |
428 | 1817 { |
444 | 1818 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1819 { |
444 | 1820 if (internal_old_equal (value, elt_cdr, 0)) |
428 | 1821 return elt; |
1822 } | |
1823 return Qnil; | |
1824 } | |
1825 | |
1826 DEFUN ("rassq", Frassq, 2, 2, 0, /* | |
444 | 1827 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST. |
1828 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1829 */ |
444 | 1830 (value, alist)) |
428 | 1831 { |
444 | 1832 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1833 { |
444 | 1834 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1835 return elt; |
1836 } | |
1837 return Qnil; | |
1838 } | |
1839 | |
1840 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /* | |
444 | 1841 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST. |
1842 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1843 */ |
444 | 1844 (value, alist)) |
428 | 1845 { |
444 | 1846 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1847 { |
444 | 1848 if (HACKEQ_UNSAFE (value, elt_cdr)) |
428 | 1849 return elt; |
1850 } | |
1851 return Qnil; | |
1852 } | |
1853 | |
444 | 1854 /* Like Frassq, but caller must ensure that ALIST is properly |
428 | 1855 nil-terminated and ebola-free. */ |
1856 Lisp_Object | |
444 | 1857 rassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1858 { |
444 | 1859 LIST_LOOP_2 (elt, alist) |
428 | 1860 { |
1861 Lisp_Object elt_cdr = XCDR (elt); | |
444 | 1862 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1863 return elt; |
1864 } | |
1865 return Qnil; | |
1866 } | |
1867 | |
1868 | |
1869 DEFUN ("delete", Fdelete, 2, 2, 0, /* | |
1870 Delete by side effect any occurrences of ELT as a member of LIST. | |
1871 The modified LIST is returned. Comparison is done with `equal'. | |
1872 If the first member of LIST is ELT, there is no way to remove it by side | |
1873 effect; therefore, write `(setq foo (delete element foo))' to be sure | |
1874 of changing the value of `foo'. | |
1875 Also see: `remove'. | |
1876 */ | |
1877 (elt, list)) | |
1878 { | |
1879 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1880 (internal_equal (elt, list_elt, 0))); | |
1881 return list; | |
1882 } | |
1883 | |
1884 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /* | |
1885 Delete by side effect any occurrences of ELT as a member of LIST. | |
1886 The modified LIST is returned. Comparison is done with `old-equal'. | |
1887 If the first member of LIST is ELT, there is no way to remove it by side | |
1888 effect; therefore, write `(setq foo (old-delete element foo))' to be sure | |
1889 of changing the value of `foo'. | |
1890 */ | |
1891 (elt, list)) | |
1892 { | |
1893 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1894 (internal_old_equal (elt, list_elt, 0))); | |
1895 return list; | |
1896 } | |
1897 | |
1898 DEFUN ("delq", Fdelq, 2, 2, 0, /* | |
1899 Delete by side effect any occurrences of ELT as a member of LIST. | |
1900 The modified LIST is returned. Comparison is done with `eq'. | |
1901 If the first member of LIST is ELT, there is no way to remove it by side | |
1902 effect; therefore, write `(setq foo (delq element foo))' to be sure of | |
1903 changing the value of `foo'. | |
1904 */ | |
1905 (elt, list)) | |
1906 { | |
1907 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1908 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1909 return list; | |
1910 } | |
1911 | |
1912 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /* | |
1913 Delete by side effect any occurrences of ELT as a member of LIST. | |
1914 The modified LIST is returned. Comparison is done with `old-eq'. | |
1915 If the first member of LIST is ELT, there is no way to remove it by side | |
1916 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of | |
1917 changing the value of `foo'. | |
1918 */ | |
1919 (elt, list)) | |
1920 { | |
1921 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1922 (HACKEQ_UNSAFE (elt, list_elt))); | |
1923 return list; | |
1924 } | |
1925 | |
1926 /* Like Fdelq, but caller must ensure that LIST is properly | |
1927 nil-terminated and ebola-free. */ | |
1928 | |
1929 Lisp_Object | |
1930 delq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1931 { | |
1932 LIST_LOOP_DELETE_IF (list_elt, list, | |
1933 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1934 return list; | |
1935 } | |
1936 | |
1937 /* Be VERY careful with this. This is like delq_no_quit() but | |
1938 also calls free_cons() on the removed conses. You must be SURE | |
1939 that no pointers to the freed conses remain around (e.g. | |
1940 someone else is pointing to part of the list). This function | |
1941 is useful on internal lists that are used frequently and where | |
1942 the actual list doesn't escape beyond known code bounds. */ | |
1943 | |
1944 Lisp_Object | |
1945 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list) | |
1946 { | |
1947 REGISTER Lisp_Object tail = list; | |
1948 REGISTER Lisp_Object prev = Qnil; | |
1949 | |
1950 while (!NILP (tail)) | |
1951 { | |
1952 REGISTER Lisp_Object tem = XCAR (tail); | |
1953 if (EQ (elt, tem)) | |
1954 { | |
1955 Lisp_Object cons_to_free = tail; | |
1956 if (NILP (prev)) | |
1957 list = XCDR (tail); | |
1958 else | |
1959 XCDR (prev) = XCDR (tail); | |
1960 tail = XCDR (tail); | |
853 | 1961 free_cons (cons_to_free); |
428 | 1962 } |
1963 else | |
1964 { | |
1965 prev = tail; | |
1966 tail = XCDR (tail); | |
1967 } | |
1968 } | |
1969 return list; | |
1970 } | |
1971 | |
1972 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /* | |
444 | 1973 Delete by side effect any elements of ALIST whose car is `equal' to KEY. |
1974 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1975 that is `equal' to KEY, there is no way to remove it by side effect; |
1976 therefore, write `(setq foo (remassoc key foo))' to be sure of changing | |
1977 the value of `foo'. | |
1978 */ | |
444 | 1979 (key, alist)) |
428 | 1980 { |
444 | 1981 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1982 (CONSP (elt) && |
1983 internal_equal (key, XCAR (elt), 0))); | |
444 | 1984 return alist; |
428 | 1985 } |
1986 | |
1987 Lisp_Object | |
444 | 1988 remassoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1989 { |
1990 int speccount = specpdl_depth (); | |
1991 specbind (Qinhibit_quit, Qt); | |
771 | 1992 return unbind_to_1 (speccount, Fremassoc (key, alist)); |
428 | 1993 } |
1994 | |
1995 DEFUN ("remassq", Fremassq, 2, 2, 0, /* | |
444 | 1996 Delete by side effect any elements of ALIST whose car is `eq' to KEY. |
1997 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1998 that is `eq' to KEY, there is no way to remove it by side effect; |
1999 therefore, write `(setq foo (remassq key foo))' to be sure of changing | |
2000 the value of `foo'. | |
2001 */ | |
444 | 2002 (key, alist)) |
428 | 2003 { |
444 | 2004 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2005 (CONSP (elt) && |
2006 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 2007 return alist; |
428 | 2008 } |
2009 | |
2010 /* no quit, no errors; be careful */ | |
2011 | |
2012 Lisp_Object | |
444 | 2013 remassq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 2014 { |
444 | 2015 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2016 (CONSP (elt) && |
2017 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 2018 return alist; |
428 | 2019 } |
2020 | |
2021 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /* | |
444 | 2022 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE. |
2023 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 2024 that is `equal' to VALUE, there is no way to remove it by side effect; |
2025 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing | |
2026 the value of `foo'. | |
2027 */ | |
444 | 2028 (value, alist)) |
428 | 2029 { |
444 | 2030 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2031 (CONSP (elt) && |
2032 internal_equal (value, XCDR (elt), 0))); | |
444 | 2033 return alist; |
428 | 2034 } |
2035 | |
2036 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /* | |
444 | 2037 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE. |
2038 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 2039 that is `eq' to VALUE, there is no way to remove it by side effect; |
2040 therefore, write `(setq foo (remrassq value foo))' to be sure of changing | |
2041 the value of `foo'. | |
2042 */ | |
444 | 2043 (value, alist)) |
428 | 2044 { |
444 | 2045 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2046 (CONSP (elt) && |
2047 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 2048 return alist; |
428 | 2049 } |
2050 | |
2051 /* Like Fremrassq, fast and unsafe; be careful */ | |
2052 Lisp_Object | |
444 | 2053 remrassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 2054 { |
444 | 2055 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2056 (CONSP (elt) && |
2057 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 2058 return alist; |
428 | 2059 } |
2060 | |
2061 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /* | |
2062 Reverse LIST by destructively modifying cdr pointers. | |
2063 Return the beginning of the reversed list. | |
2064 Also see: `reverse'. | |
2065 */ | |
2066 (list)) | |
2067 { | |
2068 struct gcpro gcpro1, gcpro2; | |
1849 | 2069 Lisp_Object prev = Qnil; |
2070 Lisp_Object tail = list; | |
428 | 2071 |
2072 /* We gcpro our args; see `nconc' */ | |
2073 GCPRO2 (prev, tail); | |
2074 while (!NILP (tail)) | |
2075 { | |
2076 REGISTER Lisp_Object next; | |
2077 CONCHECK_CONS (tail); | |
2078 next = XCDR (tail); | |
2079 XCDR (tail) = prev; | |
2080 prev = tail; | |
2081 tail = next; | |
2082 } | |
2083 UNGCPRO; | |
2084 return prev; | |
2085 } | |
2086 | |
2087 DEFUN ("reverse", Freverse, 1, 1, 0, /* | |
2088 Reverse LIST, copying. Return the beginning of the reversed list. | |
2089 See also the function `nreverse', which is used more often. | |
2090 */ | |
2091 (list)) | |
2092 { | |
2093 Lisp_Object reversed_list = Qnil; | |
2094 EXTERNAL_LIST_LOOP_2 (elt, list) | |
2095 { | |
2096 reversed_list = Fcons (elt, reversed_list); | |
2097 } | |
2098 return reversed_list; | |
2099 } | |
2100 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2101 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2102 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
|
2103 Lisp_Object pred, Lisp_Object key_func) |
428 | 2104 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2105 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2106 Lisp_Object args[3]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2107 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2108 /* 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
|
2109 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
|
2110 args[0] = key_func; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2111 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2112 args[2] = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2113 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2114 GCPRO1 (args[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2115 gcpro1.nvars = countof (args); |
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 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
|
2118 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2119 args[1] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2120 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
|
2121 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2122 args[0] = pred; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2123 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2124 args[2] = obj2; |
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 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args))); |
428 | 2127 } |
2128 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2129 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2130 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
|
2131 Lisp_Object pred, Lisp_Object UNUSED (key_func)) |
428 | 2132 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2133 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2134 Lisp_Object args[3]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2135 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2136 /* 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
|
2137 inline it here. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2138 args[0] = pred; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2139 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2140 args[2] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2141 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2142 GCPRO1 (args[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2143 gcpro1.nvars = countof (args); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2144 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2145 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args))); |
428 | 2146 } |
2147 | |
2148 Lisp_Object | |
2149 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
|
2150 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
|
2151 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2152 Lisp_Object predicate, Lisp_Object key_func) |
428 | 2153 { |
2154 Lisp_Object value; | |
2155 Lisp_Object tail; | |
2156 Lisp_Object tem; | |
2157 Lisp_Object l1, l2; | |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2158 Lisp_Object tortoises[2]; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2159 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2160 int looped = 0; |
428 | 2161 |
2162 l1 = org_l1; | |
2163 l2 = org_l2; | |
2164 tail = Qnil; | |
2165 value = Qnil; | |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2166 tortoises[0] = org_l1; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2167 tortoises[1] = org_l2; |
428 | 2168 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2169 if (NULL == c_predicate) |
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 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
|
2172 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
|
2173 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2174 |
428 | 2175 /* It is sufficient to protect org_l1 and org_l2. |
2176 When l1 and l2 are updated, we copy the new values | |
2177 back into the org_ vars. */ | |
2178 | |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2179 GCPRO5 (org_l1, org_l2, predicate, value, tortoises[0]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2180 gcpro5.nvars = 2; |
428 | 2181 |
2182 while (1) | |
2183 { | |
2184 if (NILP (l1)) | |
2185 { | |
2186 UNGCPRO; | |
2187 if (NILP (tail)) | |
2188 return l2; | |
2189 Fsetcdr (tail, l2); | |
2190 return value; | |
2191 } | |
2192 if (NILP (l2)) | |
2193 { | |
2194 UNGCPRO; | |
2195 if (NILP (tail)) | |
2196 return l1; | |
2197 Fsetcdr (tail, l1); | |
2198 return value; | |
2199 } | |
2200 | |
5182
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 (Fcar (l2), Fcar (l1), predicate, key_func))) |
428 | 2202 { |
2203 tem = l1; | |
2204 l1 = Fcdr (l1); | |
2205 org_l1 = l1; | |
2206 } | |
2207 else | |
2208 { | |
2209 tem = l2; | |
2210 l2 = Fcdr (l2); | |
2211 org_l2 = l2; | |
2212 } | |
2213 if (NILP (tail)) | |
2214 value = tem; | |
2215 else | |
2216 Fsetcdr (tail, tem); | |
2217 tail = tem; | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2218 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2219 if (++looped > CIRCULAR_LIST_SUSPICION_LENGTH) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2220 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2221 if (looped & 1) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2222 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2223 tortoises[0] = XCDR (tortoises[0]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2224 tortoises[1] = XCDR (tortoises[1]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2225 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2226 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2227 if (EQ (org_l1, tortoises[0])) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2228 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2229 signal_circular_list_error (org_l1); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2230 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2231 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2232 if (EQ (org_l2, tortoises[1])) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2233 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2234 signal_circular_list_error (org_l2); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2235 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2236 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2237 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2238 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2239 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2240 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2241 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
|
2242 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
|
2243 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
|
2244 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
|
2245 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2246 Lisp_Object 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
|
2247 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2248 Elemcount ii, fronting, backing; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2249 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
|
2250 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
|
2251 struct gcpro gcpro1, gcpro2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2252 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2253 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
|
2254 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2255 if (0 == dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2256 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2257 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2258 } |
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 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
|
2261 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2262 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
|
2263 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2264 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
|
2265 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2266 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
|
2267 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2268 } |
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 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
|
2271 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2272 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
|
2273 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2274 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
|
2275 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2276 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
|
2277 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2278 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2279 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2280 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
|
2281 gcpro1.nvars = front_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2282 gcpro2.nvars = back_len; |
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 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
|
2285 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2286 if (fronting >= front_len) |
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 while (ii < dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2289 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2290 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
|
2291 ++ii, ++backing; |
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 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2294 return; |
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 if (backing >= back_len) |
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 while (ii < dest_len) |
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 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
|
2302 ++ii, ++fronting; |
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 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2305 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2306 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2307 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2308 if (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
|
2309 predicate, key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2310 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2311 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
|
2312 ++fronting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2313 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2314 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2315 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2316 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
|
2317 ++backing; |
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 } |
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 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2322 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2323 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2324 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2325 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
|
2326 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
|
2327 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
|
2328 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2329 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2330 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2331 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
|
2332 Boolint reverse_order) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2333 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2334 Lisp_Object tail = Qnil, value = Qnil, tortoise = list; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2335 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
|
2336 Elemcount array_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2337 int looped = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2338 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2339 GCPRO4 (list, tail, value, tortoise); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2340 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2341 while (1) |
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 if (NILP (list)) |
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 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2346 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2347 if (NILP (tail)) |
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 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
|
2350 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2351 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2352 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
|
2353 return value; |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2356 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
|
2357 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2358 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2359 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2360 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2361 return list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2362 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2363 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2364 Fsetcdr (tail, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2365 return value; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2366 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2367 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2368 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2369 if (reverse_order ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2370 !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
|
2371 key_func)) : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2372 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
|
2373 key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2374 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2375 if (NILP (tail)) |
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 value = tail = list; |
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 else |
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 Fsetcdr (tail, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2382 tail = XCDR (tail); |
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 list = Fcdr (list); |
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 else |
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 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2390 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2391 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
|
2392 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2393 else |
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 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
|
2396 tail = XCDR (tail); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2397 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2398 ++array_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2399 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2400 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2401 if (++looped > CIRCULAR_LIST_SUSPICION_LENGTH) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2402 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2403 if (looped & 1) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2404 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2405 tortoise = XCDR (tortoise); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2406 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2407 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2408 if (EQ (list, tortoise)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2409 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2410 signal_circular_list_error (list); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2411 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2412 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2413 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2414 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2415 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2416 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2417 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
|
2418 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
|
2419 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
|
2420 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2421 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2422 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2423 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
|
2424 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2425 Elemcount output_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2426 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2427 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
|
2428 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2429 if (NILP (list_one)) |
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 (output_index < output_len) |
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 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
|
2434 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
|
2435 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2436 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2437 } |
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 if (NILP (list_two)) |
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 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
|
2442 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2443 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
|
2444 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
|
2445 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2446 return; |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2449 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
|
2450 key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2451 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2452 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
|
2453 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
|
2454 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2455 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2456 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2457 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
|
2458 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
|
2459 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2460 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2461 ++output_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2462 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2463 /* 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
|
2464 } |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2467 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2468 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
|
2469 Lisp_Object list, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2470 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
|
2471 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
|
2472 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2473 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2474 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2475 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
|
2476 Boolint reverse_order) |
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 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
|
2479 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2480 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
|
2481 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2482 if (NILP (list)) |
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 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
|
2485 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2486 mapping_interaction_error (Qmerge, list); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2487 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2488 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2489 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
|
2490 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2491 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
|
2492 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2493 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2494 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2495 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2496 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2497 if (array_index >= array_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2498 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2499 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
|
2500 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2501 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
|
2502 list = Fcdr (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2503 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2504 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2505 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2506 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2507 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2508 if (reverse_order ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2509 !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
|
2510 key_func)) : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2511 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
|
2512 key_func))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2513 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2514 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
|
2515 list = XCDR (list); |
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 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2518 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2519 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
|
2520 ++array_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2521 } |
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 ++output_index; |
428 | 2524 } |
2525 } | |
2526 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2527 #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
|
2528 do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2529 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
|
2530 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
|
2531 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2532 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
|
2533 INC_IBYTEPTR (strdata); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2534 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2535 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2536 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2537 #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
|
2538 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
|
2539 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
|
2540 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2541 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
|
2542 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2543 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2544 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2545 /* 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
|
2546 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2547 #define CHECK_KEY_ARGUMENT(key) \ |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2548 do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2549 if (NILP (key)) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2550 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2551 key = Qidentity; \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2552 } \ |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2553 \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2554 if (!EQ (key, Qidentity)) \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2555 { \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2556 key = indirect_function (key, 1); \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2557 } \ |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2558 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2559 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2560 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
|
2561 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
|
2562 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2563 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
|
2564 predicate on the elements. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2565 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2566 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
|
2567 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
|
2568 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2569 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
|
2570 */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2571 (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
|
2572 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2573 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
|
2574 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
|
2575 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
|
2576 Lisp_Object); |
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 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
|
2579 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2580 CHECK_SEQUENCE (sequence_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2581 CHECK_SEQUENCE (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2582 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2583 CHECK_KEY_ARGUMENT (key); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2584 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2585 c_predicate = EQ (key, Qidentity) ? |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2586 c_merge_predicate_nokey : c_merge_predicate_key; |
5182
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 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
|
2589 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2590 if (NILP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2591 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2592 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
|
2593 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2594 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
|
2595 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2596 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
|
2597 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
|
2598 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
|
2599 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2600 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
|
2601 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2602 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
|
2603 predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2604 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2605 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2606 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2607 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
|
2608 Elemcount array_length, i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2609 Boolint reverse_order = 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 if (!CONSP (sequence_one)) |
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 /* 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
|
2614 swap = sequence_one; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2615 sequence_one = sequence_two; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2616 sequence_two = swap; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2617 reverse_order = 1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2618 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2619 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2620 if (VECTORP (sequence_two)) |
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_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
|
2623 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
|
2624 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2625 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
|
2626 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2627 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
|
2628 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
|
2629 /* 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
|
2630 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
|
2631 array_length); |
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 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2634 else |
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 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
|
2637 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
|
2638 /* 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
|
2639 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
|
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 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
|
2643 array_storage, array_length, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2644 c_predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2645 predicate, key, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2646 reverse_order); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2647 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2648 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2649 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2650 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2651 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
|
2652 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
|
2653 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
|
2654 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
|
2655 *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
|
2656 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
|
2657 || 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
|
2658 Ibyte *strdata = NULL; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2659 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
|
2660 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2661 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2662 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
|
2663 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
|
2664 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2665 output[i] = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2666 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2667 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2668 GCPRO1 (output[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2669 gcpro1.nvars = output_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2670 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2671 if (VECTORP (sequence_one)) |
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 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
|
2674 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2675 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
|
2676 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2677 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
|
2678 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
|
2679 i, sequence_one_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2680 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2681 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
|
2682 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2683 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
|
2684 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
|
2685 i, sequence_one_len); |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2688 if (VECTORP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2689 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2690 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
|
2691 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2692 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
|
2693 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2694 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
|
2695 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
|
2696 i, sequence_two_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2697 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2698 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
|
2699 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2700 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
|
2701 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
|
2702 i, sequence_two_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2703 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2704 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2705 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
|
2706 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2707 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
|
2708 sequence_one, sequence_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2709 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2710 key); |
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 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
|
2713 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2714 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
|
2715 sequence_one, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2716 sequence_two_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2717 sequence_two_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2718 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2719 key, 0); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2720 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2721 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
|
2722 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2723 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
|
2724 sequence_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2725 sequence_one_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2726 sequence_one_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2727 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2728 key, 1); |
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 |
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_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
|
2733 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
|
2734 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
|
2735 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2736 key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2737 } |
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 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
|
2740 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2741 if (do_coerce) |
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 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
|
2744 } |
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 UNGCPRO; |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2749 return result; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2750 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2751 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2752 /* 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
|
2753 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
|
2754 Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2755 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
|
2756 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
|
2757 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2758 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
|
2759 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2760 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
|
2761 Lisp_Object back, tem; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2762 Lisp_Object front = list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2763 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
|
2764 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2765 if (XINT (len) < 2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2766 return list; |
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 if (NULL == c_predicate) |
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 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
|
2771 c_merge_predicate_key; |
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 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
|
2775 tem = Fnthcdr (len, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2776 back = Fcdr (tem); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2777 Fsetcdr (tem, Qnil); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2778 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2779 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
|
2780 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
|
2781 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
|
2782 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2783 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
|
2784 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2785 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2786 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2787 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
|
2788 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
|
2789 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2790 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
|
2791 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2792 Elemcount split; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2793 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2794 if (array_len < 2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2795 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2796 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2797 split = array_len / 2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2798 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2799 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
|
2800 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
|
2801 key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2802 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
|
2803 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
|
2804 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2805 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2806 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
|
2807 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
|
2808 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
|
2809 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2810 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
|
2811 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
|
2812 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2813 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
|
2814 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
|
2815 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2816 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
|
2817 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
|
2818 same guarantees. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2819 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2820 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
|
2821 */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2822 (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
|
2823 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2824 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
|
2825 Lisp_Object *sequence_carray; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2826 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
|
2827 Lisp_Object); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2828 Elemcount sequence_len, i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2829 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2830 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
|
2831 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2832 CHECK_SEQUENCE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2833 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2834 CHECK_KEY_ARGUMENT (key); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2835 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2836 c_predicate = EQ (key, Qidentity) ? |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2837 c_merge_predicate_nokey : c_merge_predicate_key; |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2838 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2839 if (LISTP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2840 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2841 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
|
2842 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2843 else if (VECTORP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2844 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2845 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
|
2846 c_predicate, predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2847 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2848 else if (STRINGP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2849 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2850 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
|
2851 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2852 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
|
2853 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2854 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
|
2855 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2856 /* 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
|
2857 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
|
2858 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2859 strdata = XSTRING_DATA (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2860 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2861 CHECK_LISP_WRITEABLE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2862 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
|
2863 { |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
2864 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
|
2865 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2866 |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
2867 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
|
2868 bump_string_modiff (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2869 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
|
2870 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2871 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
|
2872 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2873 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
|
2874 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
|
2875 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2876 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
|
2877 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2878 /* 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
|
2879 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
|
2880 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2881 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
|
2882 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2883 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
|
2884 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2885 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2886 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2887 return sequence; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2888 } |
428 | 2889 |
2890 /************************************************************************/ | |
2891 /* property-list functions */ | |
2892 /************************************************************************/ | |
2893 | |
2894 /* For properties of text, we need to do order-insensitive comparison of | |
2895 plists. That is, we need to compare two plists such that they are the | |
2896 same if they have the same set of keys, and equivalent values. | |
2897 So (a 1 b 2) would be equal to (b 2 a 1). | |
2898 | |
2899 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc. | |
2900 LAXP means use `equal' for comparisons. | |
2901 */ | |
2902 int | |
2903 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
|
2904 int laxp, int depth, int foldcase) |
428 | 2905 { |
438 | 2906 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */ |
428 | 2907 int la, lb, m, i, fill; |
2908 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
|
2909 Boolbyte *flags; |
428 | 2910 Lisp_Object rest; |
2911 | |
2912 if (NILP (a) && NILP (b)) | |
2913 return 0; | |
2914 | |
2915 Fcheck_valid_plist (a); | |
2916 Fcheck_valid_plist (b); | |
2917 | |
2918 la = XINT (Flength (a)); | |
2919 lb = XINT (Flength (b)); | |
2920 m = (la > lb ? la : lb); | |
2921 fill = 0; | |
2922 keys = alloca_array (Lisp_Object, m); | |
2923 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
|
2924 flags = alloca_array (Boolbyte, m); |
428 | 2925 |
2926 /* First extract the pairs from A. */ | |
2927 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2928 { | |
2929 Lisp_Object k = XCAR (rest); | |
2930 Lisp_Object v = XCAR (XCDR (rest)); | |
2931 /* Maybe be Ebolified. */ | |
2932 if (nil_means_not_present && NILP (v)) continue; | |
2933 keys [fill] = k; | |
2934 vals [fill] = v; | |
2935 flags[fill] = 0; | |
2936 fill++; | |
2937 } | |
2938 /* Now iterate over B, and stop if we find something that's not in A, | |
2939 or that doesn't match. As we match, mark them. */ | |
2940 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2941 { | |
2942 Lisp_Object k = XCAR (rest); | |
2943 Lisp_Object v = XCAR (XCDR (rest)); | |
2944 /* Maybe be Ebolified. */ | |
2945 if (nil_means_not_present && NILP (v)) continue; | |
2946 for (i = 0; i < fill; i++) | |
2947 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2948 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
|
2949 internal_equal_0 (k, keys [i], depth, foldcase)) |
428 | 2950 { |
434 | 2951 if (eqp |
2952 /* We narrowly escaped being Ebolified here. */ | |
2953 ? !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
|
2954 : !internal_equal_0 (v, vals [i], depth, foldcase)) |
428 | 2955 /* a property in B has a different value than in A */ |
2956 goto MISMATCH; | |
2957 flags [i] = 1; | |
2958 break; | |
2959 } | |
2960 } | |
2961 if (i == fill) | |
2962 /* there are some properties in B that are not in A */ | |
2963 goto MISMATCH; | |
2964 } | |
2965 /* Now check to see that all the properties in A were also in B */ | |
2966 for (i = 0; i < fill; i++) | |
2967 if (flags [i] == 0) | |
2968 goto MISMATCH; | |
2969 | |
2970 /* Ok. */ | |
2971 return 0; | |
2972 | |
2973 MISMATCH: | |
2974 return 1; | |
2975 } | |
2976 | |
2977 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /* | |
2978 Return non-nil if property lists A and B are `eq'. | |
2979 A property list is an alternating list of keywords and values. | |
2980 This function does order-insensitive comparisons of the property lists: | |
2981 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2982 Comparison between values is done using `eq'. See also `plists-equal'. | |
2983 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2984 a nil value is ignored. This feature is a virus that has infected | |
2985 old Lisp implementations, but should not be used except for backward | |
2986 compatibility. | |
2987 */ | |
2988 (a, b, nil_means_not_present)) | |
2989 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
2990 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1, 0) |
428 | 2991 ? Qnil : Qt); |
2992 } | |
2993 | |
2994 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /* | |
2995 Return non-nil if property lists A and B are `equal'. | |
2996 A property list is an alternating list of keywords and values. This | |
2997 function does order-insensitive comparisons of the property lists: For | |
2998 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2999 Comparison between values is done using `equal'. See also `plists-eq'. | |
3000 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3001 a nil value is ignored. This feature is a virus that has infected | |
3002 old Lisp implementations, but should not be used except for backward | |
3003 compatibility. | |
3004 */ | |
3005 (a, b, nil_means_not_present)) | |
3006 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3007 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1, 0) |
428 | 3008 ? Qnil : Qt); |
3009 } | |
3010 | |
3011 | |
3012 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /* | |
3013 Return non-nil if lax property lists A and B are `eq'. | |
3014 A property list is an alternating list of keywords and values. | |
3015 This function does order-insensitive comparisons of the property lists: | |
3016 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
3017 Comparison between values is done using `eq'. See also `plists-equal'. | |
3018 A lax property list is like a regular one except that comparisons between | |
3019 keywords is done using `equal' instead of `eq'. | |
3020 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3021 a nil value is ignored. This feature is a virus that has infected | |
3022 old Lisp implementations, but should not be used except for backward | |
3023 compatibility. | |
3024 */ | |
3025 (a, b, nil_means_not_present)) | |
3026 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3027 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1, 0) |
428 | 3028 ? Qnil : Qt); |
3029 } | |
3030 | |
3031 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /* | |
3032 Return non-nil if lax property lists A and B are `equal'. | |
3033 A property list is an alternating list of keywords and values. This | |
3034 function does order-insensitive comparisons of the property lists: For | |
3035 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
3036 Comparison between values is done using `equal'. See also `plists-eq'. | |
3037 A lax property list is like a regular one except that comparisons between | |
3038 keywords is done using `equal' instead of `eq'. | |
3039 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3040 a nil value is ignored. This feature is a virus that has infected | |
3041 old Lisp implementations, but should not be used except for backward | |
3042 compatibility. | |
3043 */ | |
3044 (a, b, nil_means_not_present)) | |
3045 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3046 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1, 0) |
428 | 3047 ? Qnil : Qt); |
3048 } | |
3049 | |
3050 /* Return the value associated with key PROPERTY in property list PLIST. | |
3051 Return nil if key not found. This function is used for internal | |
3052 property lists that cannot be directly manipulated by the user. | |
3053 */ | |
3054 | |
3055 Lisp_Object | |
3056 internal_plist_get (Lisp_Object plist, Lisp_Object property) | |
3057 { | |
3058 Lisp_Object tail; | |
3059 | |
3060 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
3061 { | |
3062 if (EQ (XCAR (tail), property)) | |
3063 return XCAR (XCDR (tail)); | |
3064 } | |
3065 | |
3066 return Qunbound; | |
3067 } | |
3068 | |
3069 /* Set PLIST's value for PROPERTY to VALUE. Analogous to | |
3070 internal_plist_get(). */ | |
3071 | |
3072 void | |
3073 internal_plist_put (Lisp_Object *plist, Lisp_Object property, | |
3074 Lisp_Object value) | |
3075 { | |
3076 Lisp_Object tail; | |
3077 | |
3078 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
3079 { | |
3080 if (EQ (XCAR (tail), property)) | |
3081 { | |
3082 XCAR (XCDR (tail)) = value; | |
3083 return; | |
3084 } | |
3085 } | |
3086 | |
3087 *plist = Fcons (property, Fcons (value, *plist)); | |
3088 } | |
3089 | |
3090 int | |
3091 internal_remprop (Lisp_Object *plist, Lisp_Object property) | |
3092 { | |
3093 Lisp_Object tail, prev; | |
3094 | |
3095 for (tail = *plist, prev = Qnil; | |
3096 !NILP (tail); | |
3097 tail = XCDR (XCDR (tail))) | |
3098 { | |
3099 if (EQ (XCAR (tail), property)) | |
3100 { | |
3101 if (NILP (prev)) | |
3102 *plist = XCDR (XCDR (tail)); | |
3103 else | |
3104 XCDR (XCDR (prev)) = XCDR (XCDR (tail)); | |
3105 return 1; | |
3106 } | |
3107 else | |
3108 prev = tail; | |
3109 } | |
3110 | |
3111 return 0; | |
3112 } | |
3113 | |
3114 /* Called on a malformed property list. BADPLACE should be some | |
3115 place where truncating will form a good list -- i.e. we shouldn't | |
3116 result in a list with an odd length. */ | |
3117 | |
3118 static Lisp_Object | |
578 | 3119 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 3120 { |
3121 if (ERRB_EQ (errb, ERROR_ME)) | |
3122 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace)); | |
3123 else | |
3124 { | |
3125 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
3126 { | |
3127 warn_when_safe_lispobj | |
3128 (Qlist, Qwarning, | |
771 | 3129 list2 (build_msg_string |
428 | 3130 ("Malformed property list -- list has been truncated"), |
3131 *plist)); | |
793 | 3132 /* #### WARNING: This is more dangerous than it seems; perhaps |
3133 not a good idea. It also violates the principle of least | |
3134 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
3135 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 3136 *badplace = Qnil; |
3137 } | |
3138 return Qunbound; | |
3139 } | |
3140 } | |
3141 | |
3142 /* Called on a circular property list. BADPLACE should be some place | |
3143 where truncating will result in an even-length list, as above. | |
3144 If doesn't particularly matter where we truncate -- anywhere we | |
3145 truncate along the entire list will break the circularity, because | |
3146 it will create a terminus and the list currently doesn't have one. | |
3147 */ | |
3148 | |
3149 static Lisp_Object | |
578 | 3150 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 3151 { |
3152 if (ERRB_EQ (errb, ERROR_ME)) | |
3153 return Fsignal (Qcircular_property_list, list1 (*plist)); | |
3154 else | |
3155 { | |
3156 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
3157 { | |
3158 warn_when_safe_lispobj | |
3159 (Qlist, Qwarning, | |
771 | 3160 list2 (build_msg_string |
428 | 3161 ("Circular property list -- list has been truncated"), |
3162 *plist)); | |
793 | 3163 /* #### WARNING: This is more dangerous than it seems; perhaps |
3164 not a good idea. It also violates the principle of least | |
3165 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
3166 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 3167 *badplace = Qnil; |
3168 } | |
3169 return Qunbound; | |
3170 } | |
3171 } | |
3172 | |
3173 /* Advance the tortoise pointer by two (one iteration of a property-list | |
3174 loop) and the hare pointer by four and verify that no malformations | |
3175 or circularities exist. If so, return zero and store a value into | |
3176 RETVAL that should be returned by the calling function. Otherwise, | |
3177 return 1. See external_plist_get(). | |
3178 */ | |
3179 | |
3180 static int | |
3181 advance_plist_pointers (Lisp_Object *plist, | |
3182 Lisp_Object **tortoise, Lisp_Object **hare, | |
578 | 3183 Error_Behavior errb, Lisp_Object *retval) |
428 | 3184 { |
3185 int i; | |
3186 Lisp_Object *tortsave = *tortoise; | |
3187 | |
3188 /* Note that our "fixing" may be more brutal than necessary, | |
3189 but it's the user's own problem, not ours, if they went in and | |
3190 manually fucked up a plist. */ | |
3191 | |
3192 for (i = 0; i < 2; i++) | |
3193 { | |
3194 /* This is a standard iteration of a defensive-loop-checking | |
3195 loop. We just do it twice because we want to advance past | |
3196 both the property and its value. | |
3197 | |
3198 If the pointer indirection is confusing you, remember that | |
3199 one level of indirection on the hare and tortoise pointers | |
3200 is only due to pass-by-reference for this function. The other | |
3201 level is so that the plist can be fixed in place. */ | |
3202 | |
3203 /* When we reach the end of a well-formed plist, **HARE is | |
3204 nil. In that case, we don't do anything at all except | |
3205 advance TORTOISE by one. Otherwise, we advance HARE | |
3206 by two (making sure it's OK to do so), then advance | |
3207 TORTOISE by one (it will always be OK to do so because | |
3208 the HARE is always ahead of the TORTOISE and will have | |
3209 already verified the path), then make sure TORTOISE and | |
3210 HARE don't contain the same non-nil object -- if the | |
3211 TORTOISE and the HARE ever meet, then obviously we're | |
3212 in a circularity, and if we're in a circularity, then | |
3213 the TORTOISE and the HARE can't cross paths without | |
3214 meeting, since the HARE only gains one step over the | |
3215 TORTOISE per iteration. */ | |
3216 | |
3217 if (!NILP (**hare)) | |
3218 { | |
3219 Lisp_Object *haresave = *hare; | |
3220 if (!CONSP (**hare)) | |
3221 { | |
3222 *retval = bad_bad_bunny (plist, haresave, errb); | |
3223 return 0; | |
3224 } | |
3225 *hare = &XCDR (**hare); | |
3226 /* In a non-plist, we'd check here for a nil value for | |
3227 **HARE, which is OK (it just means the list has an | |
3228 odd number of elements). In a plist, it's not OK | |
3229 for the list to have an odd number of elements. */ | |
3230 if (!CONSP (**hare)) | |
3231 { | |
3232 *retval = bad_bad_bunny (plist, haresave, errb); | |
3233 return 0; | |
3234 } | |
3235 *hare = &XCDR (**hare); | |
3236 } | |
3237 | |
3238 *tortoise = &XCDR (**tortoise); | |
3239 if (!NILP (**hare) && EQ (**tortoise, **hare)) | |
3240 { | |
3241 *retval = bad_bad_turtle (plist, tortsave, errb); | |
3242 return 0; | |
3243 } | |
3244 } | |
3245 | |
3246 return 1; | |
3247 } | |
3248 | |
3249 /* Return the value of PROPERTY from PLIST, or Qunbound if | |
3250 property is not on the list. | |
3251 | |
3252 PLIST is a Lisp-accessible property list, meaning that it | |
3253 has to be checked for malformations and circularities. | |
3254 | |
3255 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the | |
3256 function will never signal an error; and if ERRB is ERROR_ME_WARN, | |
3257 on finding a malformation or a circularity, it issues a warning and | |
3258 attempts to silently fix the problem. | |
3259 | |
3260 A pointer to PLIST is passed in so that PLIST can be successfully | |
3261 "fixed" even if the error is at the beginning of the plist. */ | |
3262 | |
3263 Lisp_Object | |
3264 external_plist_get (Lisp_Object *plist, Lisp_Object property, | |
578 | 3265 int laxp, Error_Behavior errb) |
428 | 3266 { |
3267 Lisp_Object *tortoise = plist; | |
3268 Lisp_Object *hare = plist; | |
3269 | |
3270 while (!NILP (*tortoise)) | |
3271 { | |
3272 Lisp_Object *tortsave = tortoise; | |
3273 Lisp_Object retval; | |
3274 | |
3275 /* We do the standard tortoise/hare march. We isolate the | |
3276 grungy stuff to do this in advance_plist_pointers(), though. | |
3277 To us, all this function does is advance the tortoise | |
3278 pointer by two and the hare pointer by four and make sure | |
3279 everything's OK. We first advance the pointers and then | |
3280 check if a property matched; this ensures that our | |
3281 check for a matching property is safe. */ | |
3282 | |
3283 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3284 return retval; | |
3285 | |
3286 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3287 : internal_equal (XCAR (*tortsave), property, 0)) | |
3288 return XCAR (XCDR (*tortsave)); | |
3289 } | |
3290 | |
3291 return Qunbound; | |
3292 } | |
3293 | |
3294 /* Set PLIST's value for PROPERTY to VALUE, given a possibly | |
3295 malformed or circular plist. Analogous to external_plist_get(). */ | |
3296 | |
3297 void | |
3298 external_plist_put (Lisp_Object *plist, Lisp_Object property, | |
578 | 3299 Lisp_Object value, int laxp, Error_Behavior errb) |
428 | 3300 { |
3301 Lisp_Object *tortoise = plist; | |
3302 Lisp_Object *hare = plist; | |
3303 | |
3304 while (!NILP (*tortoise)) | |
3305 { | |
3306 Lisp_Object *tortsave = tortoise; | |
3307 Lisp_Object retval; | |
3308 | |
3309 /* See above */ | |
3310 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3311 return; | |
3312 | |
3313 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3314 : internal_equal (XCAR (*tortsave), property, 0)) | |
3315 { | |
3316 XCAR (XCDR (*tortsave)) = value; | |
3317 return; | |
3318 } | |
3319 } | |
3320 | |
3321 *plist = Fcons (property, Fcons (value, *plist)); | |
3322 } | |
3323 | |
3324 int | |
3325 external_remprop (Lisp_Object *plist, Lisp_Object property, | |
578 | 3326 int laxp, Error_Behavior errb) |
428 | 3327 { |
3328 Lisp_Object *tortoise = plist; | |
3329 Lisp_Object *hare = plist; | |
3330 | |
3331 while (!NILP (*tortoise)) | |
3332 { | |
3333 Lisp_Object *tortsave = tortoise; | |
3334 Lisp_Object retval; | |
3335 | |
3336 /* See above */ | |
3337 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3338 return 0; | |
3339 | |
3340 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3341 : internal_equal (XCAR (*tortsave), property, 0)) | |
3342 { | |
3343 /* Now you see why it's so convenient to have that level | |
3344 of indirection. */ | |
3345 *tortsave = XCDR (XCDR (*tortsave)); | |
3346 return 1; | |
3347 } | |
3348 } | |
3349 | |
3350 return 0; | |
3351 } | |
3352 | |
3353 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /* | |
3354 Extract a value from a property list. | |
3355 PLIST is a property list, which is a list of the form | |
444 | 3356 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...). |
3357 PROPERTY is usually a symbol. | |
3358 This function returns the value corresponding to the PROPERTY, | |
3359 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 3360 */ |
444 | 3361 (plist, property, default_)) |
428 | 3362 { |
444 | 3363 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME); |
3364 return UNBOUNDP (value) ? default_ : value; | |
428 | 3365 } |
3366 | |
3367 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /* | |
444 | 3368 Change value in PLIST of PROPERTY to VALUE. |
3369 PLIST is a property list, which is a list of the form | |
3370 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
3371 PROPERTY is usually a symbol and VALUE is any object. | |
3372 If PROPERTY is already a property on the list, its value is set to VALUE, | |
3373 otherwise the new PROPERTY VALUE pair is added. | |
3374 The new plist is returned; use `(setq x (plist-put x property value))' | |
3375 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 3376 */ |
444 | 3377 (plist, property, value)) |
428 | 3378 { |
444 | 3379 external_plist_put (&plist, property, value, 0, ERROR_ME); |
428 | 3380 return plist; |
3381 } | |
3382 | |
3383 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /* | |
444 | 3384 Remove from PLIST the property PROPERTY and its value. |
3385 PLIST is a property list, which is a list of the form | |
3386 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
3387 PROPERTY is usually a symbol. | |
3388 The new plist is returned; use `(setq x (plist-remprop x property))' | |
3389 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 3390 */ |
444 | 3391 (plist, property)) |
428 | 3392 { |
444 | 3393 external_remprop (&plist, property, 0, ERROR_ME); |
428 | 3394 return plist; |
3395 } | |
3396 | |
3397 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /* | |
444 | 3398 Return t if PROPERTY has a value specified in PLIST. |
428 | 3399 */ |
444 | 3400 (plist, property)) |
428 | 3401 { |
444 | 3402 Lisp_Object value = Fplist_get (plist, property, Qunbound); |
3403 return UNBOUNDP (value) ? Qnil : Qt; | |
428 | 3404 } |
3405 | |
3406 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /* | |
3407 Given a plist, signal an error if there is anything wrong with it. | |
3408 This means that it's a malformed or circular plist. | |
3409 */ | |
3410 (plist)) | |
3411 { | |
3412 Lisp_Object *tortoise; | |
3413 Lisp_Object *hare; | |
3414 | |
3415 start_over: | |
3416 tortoise = &plist; | |
3417 hare = &plist; | |
3418 while (!NILP (*tortoise)) | |
3419 { | |
3420 Lisp_Object retval; | |
3421 | |
3422 /* See above */ | |
3423 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME, | |
3424 &retval)) | |
3425 goto start_over; | |
3426 } | |
3427 | |
3428 return Qnil; | |
3429 } | |
3430 | |
3431 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /* | |
3432 Given a plist, return non-nil if its format is correct. | |
3433 If it returns nil, `check-valid-plist' will signal an error when given | |
442 | 3434 the plist; that means it's a malformed or circular plist. |
428 | 3435 */ |
3436 (plist)) | |
3437 { | |
3438 Lisp_Object *tortoise; | |
3439 Lisp_Object *hare; | |
3440 | |
3441 tortoise = &plist; | |
3442 hare = &plist; | |
3443 while (!NILP (*tortoise)) | |
3444 { | |
3445 Lisp_Object retval; | |
3446 | |
3447 /* See above */ | |
3448 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT, | |
3449 &retval)) | |
3450 return Qnil; | |
3451 } | |
3452 | |
3453 return Qt; | |
3454 } | |
3455 | |
3456 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /* | |
3457 Destructively remove any duplicate entries from a plist. | |
3458 In such cases, the first entry applies. | |
3459 | |
3460 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3461 a nil value is removed. This feature is a virus that has infected | |
3462 old Lisp implementations, but should not be used except for backward | |
3463 compatibility. | |
3464 | |
3465 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
3466 return value may not be EQ to the passed-in value, so make sure to | |
3467 `setq' the value back into where it came from. | |
3468 */ | |
3469 (plist, nil_means_not_present)) | |
3470 { | |
3471 Lisp_Object head = plist; | |
3472 | |
3473 Fcheck_valid_plist (plist); | |
3474 | |
3475 while (!NILP (plist)) | |
3476 { | |
3477 Lisp_Object prop = Fcar (plist); | |
3478 Lisp_Object next = Fcdr (plist); | |
3479 | |
3480 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
3481 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
3482 { | |
3483 if (EQ (head, plist)) | |
3484 head = Fcdr (next); | |
3485 plist = Fcdr (next); | |
3486 continue; | |
3487 } | |
3488 /* external_remprop returns 1 if it removed any property. | |
3489 We have to loop till it didn't remove anything, in case | |
3490 the property occurs many times. */ | |
3491 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME)) | |
3492 DO_NOTHING; | |
3493 plist = Fcdr (next); | |
3494 } | |
3495 | |
3496 return head; | |
3497 } | |
3498 | |
3499 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /* | |
3500 Extract a value from a lax property list. | |
444 | 3501 LAX-PLIST is a lax property list, which is a list of the form |
3502 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3503 properties is done using `equal' instead of `eq'. | |
3504 PROPERTY is usually a symbol. | |
3505 This function returns the value corresponding to PROPERTY, | |
3506 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 3507 */ |
444 | 3508 (lax_plist, property, default_)) |
428 | 3509 { |
444 | 3510 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME); |
3511 return UNBOUNDP (value) ? default_ : value; | |
428 | 3512 } |
3513 | |
3514 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /* | |
444 | 3515 Change value in LAX-PLIST of PROPERTY to VALUE. |
3516 LAX-PLIST is a lax property list, which is a list of the form | |
3517 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3518 properties is done using `equal' instead of `eq'. | |
3519 PROPERTY is usually a symbol and VALUE is any object. | |
3520 If PROPERTY is already a property on the list, its value is set to | |
3521 VALUE, otherwise the new PROPERTY VALUE pair is added. | |
3522 The new plist is returned; use `(setq x (lax-plist-put x property value))' | |
3523 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 3524 */ |
444 | 3525 (lax_plist, property, value)) |
428 | 3526 { |
444 | 3527 external_plist_put (&lax_plist, property, value, 1, ERROR_ME); |
428 | 3528 return lax_plist; |
3529 } | |
3530 | |
3531 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /* | |
444 | 3532 Remove from LAX-PLIST the property PROPERTY and its value. |
3533 LAX-PLIST is a lax property list, which is a list of the form | |
3534 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3535 properties is done using `equal' instead of `eq'. | |
3536 PROPERTY is usually a symbol. | |
3537 The new plist is returned; use `(setq x (lax-plist-remprop x property))' | |
3538 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 3539 */ |
444 | 3540 (lax_plist, property)) |
428 | 3541 { |
444 | 3542 external_remprop (&lax_plist, property, 1, ERROR_ME); |
428 | 3543 return lax_plist; |
3544 } | |
3545 | |
3546 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /* | |
444 | 3547 Return t if PROPERTY has a value specified in LAX-PLIST. |
3548 LAX-PLIST is a lax property list, which is a list of the form | |
3549 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3550 properties is done using `equal' instead of `eq'. | |
428 | 3551 */ |
444 | 3552 (lax_plist, property)) |
428 | 3553 { |
444 | 3554 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt; |
428 | 3555 } |
3556 | |
3557 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /* | |
3558 Destructively remove any duplicate entries from a lax plist. | |
3559 In such cases, the first entry applies. | |
3560 | |
3561 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3562 a nil value is removed. This feature is a virus that has infected | |
3563 old Lisp implementations, but should not be used except for backward | |
3564 compatibility. | |
3565 | |
3566 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
3567 return value may not be EQ to the passed-in value, so make sure to | |
3568 `setq' the value back into where it came from. | |
3569 */ | |
3570 (lax_plist, nil_means_not_present)) | |
3571 { | |
3572 Lisp_Object head = lax_plist; | |
3573 | |
3574 Fcheck_valid_plist (lax_plist); | |
3575 | |
3576 while (!NILP (lax_plist)) | |
3577 { | |
3578 Lisp_Object prop = Fcar (lax_plist); | |
3579 Lisp_Object next = Fcdr (lax_plist); | |
3580 | |
3581 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
3582 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
3583 { | |
3584 if (EQ (head, lax_plist)) | |
3585 head = Fcdr (next); | |
3586 lax_plist = Fcdr (next); | |
3587 continue; | |
3588 } | |
3589 /* external_remprop returns 1 if it removed any property. | |
3590 We have to loop till it didn't remove anything, in case | |
3591 the property occurs many times. */ | |
3592 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME)) | |
3593 DO_NOTHING; | |
3594 lax_plist = Fcdr (next); | |
3595 } | |
3596 | |
3597 return head; | |
3598 } | |
3599 | |
3600 /* In C because the frame props stuff uses it */ | |
3601 | |
3602 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /* | |
3603 Convert association list ALIST into the equivalent property-list form. | |
3604 The plist is returned. This converts from | |
3605 | |
3606 \((a . 1) (b . 2) (c . 3)) | |
3607 | |
3608 into | |
3609 | |
3610 \(a 1 b 2 c 3) | |
3611 | |
3612 The original alist is destroyed in the process of constructing the plist. | |
3613 See also `alist-to-plist'. | |
3614 */ | |
3615 (alist)) | |
3616 { | |
3617 Lisp_Object head = alist; | |
3618 while (!NILP (alist)) | |
3619 { | |
3620 /* remember the alist element. */ | |
3621 Lisp_Object el = Fcar (alist); | |
3622 | |
3623 Fsetcar (alist, Fcar (el)); | |
3624 Fsetcar (el, Fcdr (el)); | |
3625 Fsetcdr (el, Fcdr (alist)); | |
3626 Fsetcdr (alist, el); | |
3627 alist = Fcdr (Fcdr (alist)); | |
3628 } | |
3629 | |
3630 return head; | |
3631 } | |
3632 | |
3633 DEFUN ("get", Fget, 2, 3, 0, /* | |
442 | 3634 Return the value of OBJECT's PROPERTY property. |
3635 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'. | |
428 | 3636 If there is no such property, return optional third arg DEFAULT |
442 | 3637 \(which defaults to `nil'). OBJECT can be a symbol, string, extent, |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3638 face, glyph, or process. See also `put', `remprop', `object-plist', and |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3639 `object-setplist'. |
428 | 3640 */ |
442 | 3641 (object, property, default_)) |
428 | 3642 { |
3643 /* Various places in emacs call Fget() and expect it not to quit, | |
3644 so don't quit. */ | |
442 | 3645 Lisp_Object val; |
3646 | |
3647 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop) | |
3648 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property); | |
428 | 3649 else |
563 | 3650 invalid_operation ("Object type has no properties", object); |
442 | 3651 |
3652 return UNBOUNDP (val) ? default_ : val; | |
428 | 3653 } |
3654 | |
3655 DEFUN ("put", Fput, 3, 3, 0, /* | |
442 | 3656 Set OBJECT's PROPERTY to VALUE. |
3657 It can be subsequently retrieved with `(get OBJECT PROPERTY)'. | |
3658 OBJECT can be a symbol, face, extent, or string. | |
428 | 3659 For a string, no properties currently have predefined meanings. |
3660 For the predefined properties for extents, see `set-extent-property'. | |
3661 For the predefined properties for faces, see `set-face-property'. | |
3662 See also `get', `remprop', and `object-plist'. | |
3663 */ | |
442 | 3664 (object, property, value)) |
428 | 3665 { |
1920 | 3666 /* This function cannot GC */ |
428 | 3667 CHECK_LISP_WRITEABLE (object); |
3668 | |
442 | 3669 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop) |
428 | 3670 { |
442 | 3671 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop |
3672 (object, property, value)) | |
563 | 3673 invalid_change ("Can't set property on object", property); |
428 | 3674 } |
3675 else | |
563 | 3676 invalid_change ("Object type has no settable properties", object); |
428 | 3677 |
3678 return value; | |
3679 } | |
3680 | |
3681 DEFUN ("remprop", Fremprop, 2, 2, 0, /* | |
442 | 3682 Remove, from OBJECT's property list, PROPERTY and its corresponding value. |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3683 OBJECT can be a symbol, string, extent, face, glyph, or process. |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3684 Return non-nil if the property list was actually modified (i.e. if PROPERTY |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3685 was present in the property list). See also `get', `put', `object-plist', |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3686 and `object-setplist'. |
428 | 3687 */ |
442 | 3688 (object, property)) |
428 | 3689 { |
442 | 3690 int ret = 0; |
3691 | |
428 | 3692 CHECK_LISP_WRITEABLE (object); |
3693 | |
442 | 3694 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop) |
428 | 3695 { |
442 | 3696 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property); |
3697 if (ret == -1) | |
563 | 3698 invalid_change ("Can't remove property from object", property); |
428 | 3699 } |
3700 else | |
563 | 3701 invalid_change ("Object type has no removable properties", object); |
442 | 3702 |
3703 return ret ? Qt : Qnil; | |
428 | 3704 } |
3705 | |
3706 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /* | |
442 | 3707 Return a property list of OBJECT's properties. |
3708 For a symbol, this is equivalent to `symbol-plist'. | |
3709 OBJECT can be a symbol, string, extent, face, or glyph. | |
3710 Do not modify the returned property list directly; | |
3711 this may or may not have the desired effects. Use `put' instead. | |
428 | 3712 */ |
3713 (object)) | |
3714 { | |
442 | 3715 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist) |
3716 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object); | |
428 | 3717 else |
563 | 3718 invalid_operation ("Object type has no properties", object); |
428 | 3719 |
3720 return Qnil; | |
3721 } | |
3722 | |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3723 DEFUN ("object-setplist", Fobject_setplist, 2, 2, 0, /* |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3724 Set OBJECT's property list to NEWPLIST, and return NEWPLIST. |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3725 For a symbol, this is equivalent to `setplist'. |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3726 |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3727 OBJECT can be a symbol or a process, other objects with visible plists do |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3728 not allow their modification with `object-setplist'. |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3729 */ |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3730 (object, newplist)) |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3731 { |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3732 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->setplist) |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3733 { |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3734 return XRECORD_LHEADER_IMPLEMENTATION (object)->setplist (object, |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3735 newplist); |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3736 } |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3737 |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3738 invalid_operation ("Not possible to set object's plist", object); |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3739 return Qnil; |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3740 } |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3741 |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3742 |
428 | 3743 |
853 | 3744 static Lisp_Object |
3745 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2, | |
3746 Lisp_Object depth) | |
3747 { | |
3748 return make_int (internal_equal (obj1, obj2, XINT (depth))); | |
3749 } | |
3750 | |
3751 int | |
3752 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
|
3753 const Ascbyte *warning_string, |
853 | 3754 int flags, |
3755 struct call_trapping_problems_result *p, | |
3756 int retval, | |
3757 Lisp_Object obj1, Lisp_Object obj2, | |
3758 int depth) | |
3759 { | |
3760 Lisp_Object glorp = | |
3761 va_call_trapping_problems (warning_class, warning_string, | |
3762 flags, p, | |
3763 (lisp_fn_t) tweaked_internal_equal, | |
3764 3, obj1, obj2, make_int (depth)); | |
3765 if (UNBOUNDP (glorp)) | |
3766 return retval; | |
3767 else | |
3768 return XINT (glorp); | |
3769 } | |
3770 | |
428 | 3771 int |
3772 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3773 { | |
3774 if (depth > 200) | |
563 | 3775 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3776 QUIT; |
3777 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
3778 return 1; | |
3779 /* Note that (equal 20 20.0) should be nil */ | |
3780 if (XTYPE (obj1) != XTYPE (obj2)) | |
3781 return 0; | |
3782 if (LRECORDP (obj1)) | |
3783 { | |
442 | 3784 const struct lrecord_implementation |
428 | 3785 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), |
3786 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3787 | |
3788 return (imp1 == imp2) && | |
3789 /* 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
|
3790 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 0)); |
428 | 3791 } |
3792 | |
3793 return 0; | |
3794 } | |
3795 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3796 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
|
3797 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3798 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
|
3799 ARRAY_STRING, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3800 ARRAY_VECTOR, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3801 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
|
3802 }; |
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 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
|
3805 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
|
3806 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3807 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
|
3808 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
|
3809 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
|
3810 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
|
3811 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
|
3812 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
|
3813 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
|
3814 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3815 |
801 | 3816 int |
3817 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3818 { | |
3819 if (depth > 200) | |
3820 stack_overflow ("Stack overflow in equalp", Qunbound); | |
3821 QUIT; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3822 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3823 /* 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
|
3824 of two equal fixnums or the same object seen twice. */ |
801 | 3825 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) |
3826 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
|
3827 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3828 /* 2. If both numbers, compare with `='. */ |
1983 | 3829 if (NUMBERP (obj1) && NUMBERP (obj2)) |
3830 { | |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
3831 return (0 == bytecode_arithcompare (obj1, obj2)); |
1983 | 3832 } |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3833 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3834 /* 3. If characters, compare case-insensitively. */ |
801 | 3835 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
|
3836 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
|
3837 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3838 /* 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
|
3839 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
|
3840 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3841 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
|
3842 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
|
3843 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
|
3844 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
|
3845 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3846 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
|
3847 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
|
3848 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
|
3849 /* 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
|
3850 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
|
3851 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3852 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
|
3853 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
|
3854 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
|
3855 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3856 return 1; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3857 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3858 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3859 /* 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
|
3860 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
|
3861 their contents, the equal() method will call internal_equal_0(). */ |
801 | 3862 if (XTYPE (obj1) != XTYPE (obj2)) |
3863 return 0; | |
3864 if (LRECORDP (obj1)) | |
3865 { | |
3866 const struct lrecord_implementation | |
3867 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), | |
3868 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3869 | |
3870 return (imp1 == imp2) && | |
3871 /* 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
|
3872 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 1)); |
801 | 3873 } |
3874 | |
3875 return 0; | |
3876 } | |
3877 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3878 int |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3879 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
|
3880 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3881 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3882 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
|
3883 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3884 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
|
3885 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3886 |
428 | 3887 /* Note that we may be calling sub-objects that will use |
3888 internal_equal() (instead of internal_old_equal()). Oh well. | |
3889 We will get an Ebola note if there's any possibility of confusion, | |
3890 but that seems unlikely. */ | |
3891 | |
3892 static int | |
3893 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3894 { | |
3895 if (depth > 200) | |
563 | 3896 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3897 QUIT; |
3898 if (HACKEQ_UNSAFE (obj1, obj2)) | |
3899 return 1; | |
3900 /* Note that (equal 20 20.0) should be nil */ | |
3901 if (XTYPE (obj1) != XTYPE (obj2)) | |
3902 return 0; | |
3903 | |
3904 return internal_equal (obj1, obj2, depth); | |
3905 } | |
3906 | |
3907 DEFUN ("equal", Fequal, 2, 2, 0, /* | |
3908 Return t if two Lisp objects have similar structure and contents. | |
3909 They must have the same data type. | |
3910 Conses are compared by comparing the cars and the cdrs. | |
3911 Vectors and strings are compared element by element. | |
3912 Numbers are compared by value. Symbols must match exactly. | |
3913 */ | |
444 | 3914 (object1, object2)) |
428 | 3915 { |
444 | 3916 return internal_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3917 } |
3918 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3919 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
|
3920 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
|
3921 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3922 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
|
3923 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
|
3924 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
|
3925 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3926 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
|
3927 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
|
3928 `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
|
3929 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3930 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
|
3931 `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
|
3932 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
|
3933 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
|
3934 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
|
3935 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
|
3936 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
|
3937 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
|
3938 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3939 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
|
3940 (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
|
3941 `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
|
3942 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
|
3943 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
|
3944 */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3945 (object1, object2)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3946 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3947 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
|
3948 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3949 |
428 | 3950 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* |
3951 Return t if two Lisp objects have similar structure and contents. | |
3952 They must have the same data type. | |
3953 \(Note, however, that an exception is made for characters and integers; | |
3954 this is known as the "char-int confoundance disease." See `eq' and | |
3955 `old-eq'.) | |
3956 This function is provided only for byte-code compatibility with v19. | |
3957 Do not use it. | |
3958 */ | |
444 | 3959 (object1, object2)) |
428 | 3960 { |
444 | 3961 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3962 } |
3963 | |
3964 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3965 static Lisp_Object replace_string_range_1 (Lisp_Object dest, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3966 Lisp_Object start, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3967 Lisp_Object end, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3968 const Ibyte *source, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3969 const Ibyte *source_limit, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3970 Lisp_Object item); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3971 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3972 /* Fill the substring of DEST beginning at START and ending before END with |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3973 the character ITEM. If DEST does not have sufficient space for END - |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3974 START characters at START, write as many as is possible without changing |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3975 the character length of DEST. Update the string modification flag and do |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3976 any sledgehammer checks we have turned on. |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3977 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3978 START must be a Lisp integer. END can be nil, indicating the length of the |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3979 string, or a Lisp integer. The condition (<= 0 START END (length DEST)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3980 must hold, or fill_string_range() will signal an error. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3981 static Lisp_Object |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3982 fill_string_range (Lisp_Object dest, Lisp_Object item, Lisp_Object start, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3983 Lisp_Object end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3984 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3985 return replace_string_range_1 (dest, start, end, NULL, NULL, item); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3986 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3987 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3988 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
|
3989 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
|
3990 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
|
3991 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3992 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
|
3993 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
|
3994 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
|
3995 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
|
3996 |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
3997 arguments: (SEQUENCE ITEM &key (START 0) (END (length SEQUENCE))) |
428 | 3998 */ |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
3999 (int nargs, Lisp_Object *args)) |
428 | 4000 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4001 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
|
4002 Lisp_Object item = args[1]; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4003 Elemcount starting = 0, ending = EMACS_INT_MAX, ii, len; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4004 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4005 PARSE_KEYWORDS (Qfill, nargs, args, 2, 2, (start, end), (start = Qzero), 0); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4006 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4007 CHECK_NATNUM (start); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4008 starting = XINT (start); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4009 |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4010 if (!NILP (end)) |
428 | 4011 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4012 CHECK_NATNUM (end); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4013 ending = XINT (end); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4014 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4015 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4016 retry: |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4017 if (STRINGP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4018 { |
428 | 4019 CHECK_CHAR_COERCE_INT (item); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4020 CHECK_LISP_WRITEABLE (sequence); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4021 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4022 fill_string_range (sequence, item, start, end); |
428 | 4023 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4024 else if (VECTORP (sequence)) |
428 | 4025 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4026 Lisp_Object *p = XVECTOR_DATA (sequence); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4027 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4028 CHECK_LISP_WRITEABLE (sequence); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4029 len = XVECTOR_LENGTH (sequence); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4030 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4031 check_sequence_range (sequence, start, end, make_int (len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4032 ending = min (ending, len); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4033 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4034 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
|
4035 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4036 p[ii] = item; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4037 } |
428 | 4038 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4039 else if (BIT_VECTORP (sequence)) |
428 | 4040 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4041 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence); |
428 | 4042 int bit; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4043 |
428 | 4044 CHECK_BIT (item); |
444 | 4045 bit = XINT (item); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4046 CHECK_LISP_WRITEABLE (sequence); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4047 len = bit_vector_length (v); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4048 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4049 check_sequence_range (sequence, start, end, make_int (len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4050 ending = min (ending, len); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4051 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4052 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
|
4053 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4054 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
|
4055 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4056 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4057 else if (LISTP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4058 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4059 Elemcount counting = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4060 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4061 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
|
4062 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4063 if (counting >= starting) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4064 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4065 if (counting < ending) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4066 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4067 XSETCAR (tail, item); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4068 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4069 else if (counting == ending) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4070 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4071 break; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4072 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4073 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4074 ++counting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4075 } |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4076 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
4077 if (counting < starting || (counting != ending && !NILP (end))) |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4078 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
4079 check_sequence_range (args[0], start, end, Flength (args[0])); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4080 } |
428 | 4081 } |
4082 else | |
4083 { | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4084 sequence = wrong_type_argument (Qsequencep, sequence); |
428 | 4085 goto retry; |
4086 } | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4087 return sequence; |
428 | 4088 } |
4089 | |
4090 Lisp_Object | |
4091 nconc2 (Lisp_Object arg1, Lisp_Object arg2) | |
4092 { | |
4093 Lisp_Object args[2]; | |
4094 struct gcpro gcpro1; | |
4095 args[0] = arg1; | |
4096 args[1] = arg2; | |
4097 | |
4098 GCPRO1 (args[0]); | |
4099 gcpro1.nvars = 2; | |
4100 | |
4101 RETURN_UNGCPRO (bytecode_nconc2 (args)); | |
4102 } | |
4103 | |
4104 Lisp_Object | |
4105 bytecode_nconc2 (Lisp_Object *args) | |
4106 { | |
4107 retry: | |
4108 | |
4109 if (CONSP (args[0])) | |
4110 { | |
4111 /* (setcdr (last args[0]) args[1]) */ | |
4112 Lisp_Object tortoise, hare; | |
665 | 4113 Elemcount count; |
428 | 4114 |
4115 for (hare = tortoise = args[0], count = 0; | |
4116 CONSP (XCDR (hare)); | |
4117 hare = XCDR (hare), count++) | |
4118 { | |
4119 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
4120 | |
4121 if (count & 1) | |
4122 tortoise = XCDR (tortoise); | |
4123 if (EQ (hare, tortoise)) | |
4124 signal_circular_list_error (args[0]); | |
4125 } | |
4126 XCDR (hare) = args[1]; | |
4127 return args[0]; | |
4128 } | |
4129 else if (NILP (args[0])) | |
4130 { | |
4131 return args[1]; | |
4132 } | |
4133 else | |
4134 { | |
4135 args[0] = wrong_type_argument (args[0], Qlistp); | |
4136 goto retry; | |
4137 } | |
4138 } | |
4139 | |
4140 DEFUN ("nconc", Fnconc, 0, MANY, 0, /* | |
4141 Concatenate any number of lists by altering them. | |
4142 Only the last argument is not altered, and need not be a list. | |
4143 Also see: `append'. | |
4144 If the first argument is nil, there is no way to modify it by side | |
4145 effect; therefore, write `(setq foo (nconc foo list))' to be sure of | |
4146 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
|
4147 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
4148 arguments: (&rest ARGS) |
428 | 4149 */ |
4150 (int nargs, Lisp_Object *args)) | |
4151 { | |
4152 int argnum = 0; | |
4153 struct gcpro gcpro1; | |
4154 | |
4155 /* The modus operandi in Emacs is "caller gc-protects args". | |
4156 However, nconc (particularly nconc2 ()) is called many times | |
4157 in Emacs on freshly created stuff (e.g. you see the idiom | |
4158 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those | |
4159 callers out by protecting the args ourselves to save them | |
4160 a lot of temporary-variable grief. */ | |
4161 | |
4162 GCPRO1 (args[0]); | |
4163 gcpro1.nvars = nargs; | |
4164 | |
4165 while (argnum < nargs) | |
4166 { | |
4167 Lisp_Object val; | |
4168 retry: | |
4169 val = args[argnum]; | |
4170 if (CONSP (val)) | |
4171 { | |
4172 /* `val' is the first cons, which will be our return value. */ | |
4173 /* `last_cons' will be the cons cell to mutate. */ | |
4174 Lisp_Object last_cons = val; | |
4175 Lisp_Object tortoise = val; | |
4176 | |
4177 for (argnum++; argnum < nargs; argnum++) | |
4178 { | |
4179 Lisp_Object next = args[argnum]; | |
4180 retry_next: | |
4181 if (CONSP (next) || argnum == nargs -1) | |
4182 { | |
4183 /* (setcdr (last val) next) */ | |
665 | 4184 Elemcount count; |
428 | 4185 |
4186 for (count = 0; | |
4187 CONSP (XCDR (last_cons)); | |
4188 last_cons = XCDR (last_cons), count++) | |
4189 { | |
4190 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
4191 | |
4192 if (count & 1) | |
4193 tortoise = XCDR (tortoise); | |
4194 if (EQ (last_cons, tortoise)) | |
4195 signal_circular_list_error (args[argnum-1]); | |
4196 } | |
4197 XCDR (last_cons) = next; | |
4198 } | |
4199 else if (NILP (next)) | |
4200 { | |
4201 continue; | |
4202 } | |
4203 else | |
4204 { | |
4205 next = wrong_type_argument (Qlistp, next); | |
4206 goto retry_next; | |
4207 } | |
4208 } | |
4209 RETURN_UNGCPRO (val); | |
4210 } | |
4211 else if (NILP (val)) | |
4212 argnum++; | |
4213 else if (argnum == nargs - 1) /* last arg? */ | |
4214 RETURN_UNGCPRO (val); | |
4215 else | |
4216 { | |
4217 args[argnum] = wrong_type_argument (Qlistp, val); | |
4218 goto retry; | |
4219 } | |
4220 } | |
4221 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */ | |
4222 } | |
4223 | |
4224 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4225 /* Replace the substring of DEST beginning at START and ending before END |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4226 with the text at SOURCE, which is END - START characters long and |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4227 SOURCE_LIMIT - SOURCE octets long. If DEST does not have sufficient |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4228 space for END - START characters at START, write as many as is possible |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4229 without changing the length of DEST. Update the string modification flag |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4230 and do any sledgehammer checks we have turned on in this build. |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4231 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4232 START must be a Lisp integer. END can be nil, indicating the length of the |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4233 string, or a Lisp integer. The condition (<= 0 START END (length DEST)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4234 must hold, or replace_string_range() will signal an error. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4235 static Lisp_Object |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4236 replace_string_range (Lisp_Object dest, Lisp_Object start, Lisp_Object end, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4237 const Ibyte *source, const Ibyte *source_limit) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4238 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4239 return replace_string_range_1 (dest, start, end, source, source_limit, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4240 Qnil); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4241 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4242 |
434 | 4243 /* 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
|
4244 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4245 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
|
4246 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
|
4247 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
|
4248 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
|
4249 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
|
4250 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
|
4251 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4252 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
|
4253 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
|
4254 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
|
4255 mapcarX. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4256 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4257 Otherwise, mapcarX signals an invalid state error (see |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4258 mapping_interaction_error(), above) if it encounters a non-cons, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4259 non-array when traversing SEQUENCES. Common Lisp specifies in |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4260 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
|
4261 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
|
4262 traversal operation. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4263 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4264 CALLER is a symbol describing the Lisp-visible function that was called, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4265 and any errors thrown because SEQUENCES was modified will reflect it. |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4266 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4267 If CALLER is Qsome, return the (possibly multiple) values given by |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4268 FUNCTION the first time it is non-nil, and abandon the iterations. |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4269 LISP_VALS must be the result of calling STORE_VOID_IN_LISP on the address |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4270 of a Lisp object, and the return value will be stored at that address. |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4271 If CALLER is Qevery, LISP_VALS must also reflect a pointer to a Lisp |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4272 object, and Qnil will be stored at that address if FUNCTION gives nil; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4273 otherwise it will be left alone. */ |
428 | 4274 |
4275 static void | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4276 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
|
4277 Lisp_Object function, int nsequences, Lisp_Object *sequences, |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4278 Lisp_Object caller) |
428 | 4279 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4280 Lisp_Object called, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4281 struct gcpro gcpro1, gcpro2; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4282 Ibyte *lisp_vals_staging, *cursor; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4283 int i, j; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4284 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4285 assert ((EQ (caller, Qsome) || EQ (caller, Qevery)) ? vals == NULL : 1); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4286 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4287 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
|
4288 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4289 for (i = 1; i <= nsequences; ++i) |
428 | 4290 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4291 args[i] = Qnil; |
428 | 4292 } |
4293 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4294 if (vals != NULL) |
428 | 4295 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4296 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
|
4297 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4298 gcpro2.nvars = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4299 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4300 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4301 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4302 GCPRO1 (args[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4303 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4304 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4305 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4306 /* 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
|
4307 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
|
4308 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
|
4309 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
|
4310 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
|
4311 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4312 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
|
4313 Lisp_Object *val = vals; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4314 for (i = 0; i < call_count; ++i) |
434 | 4315 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4316 *val++ = XCAR (lst); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4317 lst = XCDR (lst); |
428 | 4318 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4319 gcpro2.nvars = call_count; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4320 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4321 for (i = 0; i < call_count; ++i) |
428 | 4322 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4323 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
|
4324 vals[i] = IGNORE_MULTIPLE_VALUES (Ffuncall (nsequences + 1, args)); |
428 | 4325 } |
4326 } | |
4327 else | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4328 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4329 enum lrecord_type lisp_vals_type; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4330 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
|
4331 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
|
4332 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4333 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
|
4334 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4335 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4336 if (!EQ (caller, Qsome) && !EQ (caller, Qevery)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4337 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4338 assert (LRECORDP (lisp_vals)); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4339 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4340 lisp_vals_type |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4341 = (enum lrecord_type) XRECORD_LHEADER (lisp_vals)->type; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4342 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4343 if (lrecord_type_string == lisp_vals_type) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4344 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4345 lisp_vals_staging = cursor |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4346 = alloca_ibytes (call_count * MAX_ICHAR_LEN); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4347 } |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4348 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4349 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4350 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
|
4351 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4352 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
|
4353 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4354 switch (sequence_types[j]) |
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 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4357 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4358 if (!CONSP (sequences[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4359 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4360 /* This means FUNCTION has messed around with a cons |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4361 in one of the sequences, since we checked the |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4362 type (CHECK_SEQUENCE()) and the length and |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4363 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
|
4364 callers. */ |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4365 mapping_interaction_error (caller, sequences[j]); |
4995
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 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
|
4368 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
|
4369 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4370 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4371 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4372 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4373 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
|
4374 break; |
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 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4377 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4378 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
|
4379 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4380 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4381 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
|
4382 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4383 args[j + 1] |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4384 = 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
|
4385 i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4386 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4387 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4388 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4389 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4390 } |
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 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
|
4393 if (vals != NULL) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4394 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4395 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
|
4396 gcpro2.nvars += 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4397 } |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4398 else if (EQ (Qsome, caller)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4399 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4400 if (!NILP (IGNORE_MULTIPLE_VALUES (called))) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4401 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4402 Lisp_Object *result |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4403 = (Lisp_Object *) GET_VOID_FROM_LISP (lisp_vals); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4404 *result = called; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4405 UNGCPRO; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4406 return; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4407 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4408 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4409 else if (EQ (Qevery, caller)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4410 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4411 if (NILP (IGNORE_MULTIPLE_VALUES (called))) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4412 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4413 Lisp_Object *result |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4414 = (Lisp_Object *) GET_VOID_FROM_LISP (lisp_vals); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4415 *result = Qnil; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4416 UNGCPRO; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4417 return; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4418 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4419 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4420 else |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4421 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4422 called = IGNORE_MULTIPLE_VALUES (called); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4423 switch (lisp_vals_type) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4424 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4425 case lrecord_type_symbol: |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4426 /* Discard the result of funcall. */ |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4427 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4428 case lrecord_type_cons: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4429 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4430 if (!CONSP (lisp_vals)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4431 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4432 /* If FUNCTION has inserted a non-cons non-nil |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4433 cdr into the list before we've processed the |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4434 relevant part, error. */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4435 mapping_interaction_error (caller, lisp_vals); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4436 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4437 XSETCAR (lisp_vals, called); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4438 lisp_vals = XCDR (lisp_vals); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4439 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4440 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4441 case lrecord_type_vector: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4442 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4443 i < XVECTOR_LENGTH (lisp_vals) ? |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4444 (XVECTOR_DATA (lisp_vals)[i] = called) : |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4445 /* Let #'aset error. */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4446 Faset (lisp_vals, make_int (i), called); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4447 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4448 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4449 case lrecord_type_string: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4450 { |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4451 CHECK_CHAR_COERCE_INT (called); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4452 cursor += set_itext_ichar (cursor, XCHAR (called)); |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4453 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4454 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4455 case lrecord_type_bit_vector: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4456 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4457 (BITP (called) && |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4458 i < bit_vector_length (XBIT_VECTOR (lisp_vals))) ? |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4459 set_bit_vector_bit (XBIT_VECTOR (lisp_vals), i, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4460 XINT (called)) : |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4461 (void) Faset (lisp_vals, make_int (i), called); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4462 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4463 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4464 default: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4465 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4466 ABORT(); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4467 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4468 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4469 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4470 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4471 } |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4472 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4473 if (!EQ (caller, Qsome) && !EQ (caller, Qevery) && |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4474 lrecord_type_string == lisp_vals_type) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4475 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4476 replace_string_range (lisp_vals, Qzero, make_int (call_count), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4477 lisp_vals_staging, cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4478 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4479 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4480 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4481 UNGCPRO; |
428 | 4482 } |
4483 | |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4484 /* Given NSEQUENCES objects at the address pointed to by SEQUENCES, return |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4485 the length of the shortest sequence. Error if all are circular, or if any |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4486 one of them is not a sequence. */ |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4487 static Elemcount |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4488 shortest_length_among_sequences (int nsequences, Lisp_Object *sequences) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4489 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4490 Elemcount len = EMACS_INT_MAX; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4491 Lisp_Object length; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4492 int i; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4493 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4494 for (i = 0; i < nsequences; ++i) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4495 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4496 if (CONSP (sequences[i])) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4497 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4498 length = Flist_length (sequences[i]); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4499 if (!NILP (length)) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4500 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4501 len = min (len, XINT (length)); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4502 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4503 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4504 else |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4505 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4506 CHECK_SEQUENCE (sequences[i]); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4507 length = Flength (sequences[i]); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4508 len = min (len, XINT (length)); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4509 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4510 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4511 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4512 if (NILP (length)) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4513 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4514 signal_circular_list_error (sequences[0]); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4515 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4516 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4517 return len; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4518 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4519 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4520 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
|
4521 Call FUNCTION on each element of SEQUENCE, and concat results to a string. |
751 | 4522 Between each pair of results, insert SEPARATOR. |
4523 | |
4524 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR | |
4525 results in spaces between the values returned by FUNCTION. SEQUENCE itself | |
4526 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
|
4527 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4528 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
|
4529 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
|
4530 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
|
4531 `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
|
4532 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4533 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES) |
428 | 4534 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4535 (int nargs, Lisp_Object *args)) |
428 | 4536 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4537 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
|
4538 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
|
4539 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
|
4540 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
|
4541 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4542 EMACS_INT i, nargs0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4543 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4544 args[2] = sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4545 args[1] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4546 |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4547 len = shortest_length_among_sequences (nargs - 2, args + 2); |
428 | 4548 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4549 if (len == 0) return build_ascstring (""); |
428 | 4550 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4551 nargs0 = len + len - 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4552 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
|
4553 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4554 /* 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
|
4555 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
|
4556 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
|
4557 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
|
4558 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4559 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
|
4560 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4561 args0[i] = XCAR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4562 sequence = XCDR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4563 } |
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 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4566 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4567 mapcarX (len, args0, Qnil, function, nargs - 2, args + 2, Qmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4568 } |
428 | 4569 |
4570 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
|
4571 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
|
4572 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4573 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
|
4574 args0[i] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4575 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4576 return Fconcat (nargs0, args0); |
428 | 4577 } |
4578 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4579 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
|
4580 Call FUNCTION on each element of SEQUENCE; return a list of the results. |
434 | 4581 The result is a list of the same length as SEQUENCE. |
428 | 4582 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
|
4583 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4584 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
|
4585 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
|
4586 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
|
4587 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
|
4588 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4589 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4590 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4591 (int nargs, Lisp_Object *args)) |
428 | 4592 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4593 Lisp_Object function = args[0]; |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4594 Elemcount len = shortest_length_among_sequences (nargs - 1, args + 1); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4595 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4596 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4597 args0 = alloca_array (Lisp_Object, len); |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4598 mapcarX (len, args0, Qnil, function, nargs - 1, args + 1, QmapcarX); |
4995
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 return Flist ((int) len, args0); |
428 | 4601 } |
4602 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4603 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
|
4604 Call FUNCTION on each element of SEQUENCE; return a vector of the results. |
428 | 4605 The result is a vector of the same length as SEQUENCE. |
434 | 4606 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
|
4607 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4608 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
|
4609 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
|
4610 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
|
4611 `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
|
4612 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4613 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4614 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4615 (int nargs, Lisp_Object *args)) |
428 | 4616 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4617 Lisp_Object function = args[0]; |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4618 Elemcount len = shortest_length_among_sequences (nargs - 1, args + 1); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4619 Lisp_Object result = make_vector (len, Qnil); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4620 |
428 | 4621 struct gcpro gcpro1; |
4622 GCPRO1 (result); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4623 /* 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
|
4624 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
|
4625 mapcarX (len, XVECTOR_DATA (result), Qnil, function, nargs - 1, args +1, |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4626 Qmapvector); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4627 RETURN_UNGCPRO (result); |
428 | 4628 } |
4629 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4630 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
|
4631 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
|
4632 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4633 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
|
4634 together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4635 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4636 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
|
4637 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
|
4638 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
|
4639 `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
|
4640 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4641 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
|
4642 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4643 (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
|
4644 { |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4645 Elemcount len = shortest_length_among_sequences (nargs - 1, args + 1); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4646 Lisp_Object function = args[0], *result = alloca_array (Lisp_Object, len); |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4647 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4648 mapcarX (len, result, Qnil, function, nargs - 1, args + 1, Qmapcan); |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4649 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4650 /* #'nconc GCPROs its args in case of signals and error. */ |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4651 return Fnconc (len, result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4652 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4653 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4654 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
|
4655 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
|
4656 |
428 | 4657 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4658 This function is like `mapcar' but does not accumulate the results, | |
4659 which is more efficient if you do not use the results. | |
4660 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4661 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
|
4662 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
|
4663 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
|
4664 `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
|
4665 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4666 Return SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4667 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4668 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
|
4669 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4670 (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
|
4671 { |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4672 Elemcount len = shortest_length_among_sequences (nargs - 1, args + 1); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4673 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
|
4674 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4675 /* 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
|
4676 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
|
4677 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
|
4678 GCPRO1 (sequence); |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4679 mapcarX (len, NULL, Qnil, args[0], nargs - 1, args + 1, Qmapc); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4680 RETURN_UNGCPRO (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4681 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4682 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4683 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
|
4684 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
|
4685 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4686 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
|
4687 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
|
4688 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4689 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
|
4690 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
|
4691 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4692 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
|
4693 `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
|
4694 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
|
4695 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4696 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4697 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4698 (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
|
4699 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4700 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
|
4701 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
|
4702 Lisp_Object result = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4703 Lisp_Object *args0 = NULL; |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4704 Elemcount len = shortest_length_among_sequences (nargs - 2, args + 2); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4705 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4706 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4707 if (!NILP (type)) |
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 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
|
4710 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4711 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4712 mapcarX (len, args0, Qnil, function, nargs - 2, args + 2, Qmap); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4713 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4714 if (EQ (type, Qnil)) |
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 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4717 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4718 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4719 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
|
4720 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4721 result = Fvector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4722 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4723 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
|
4724 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4725 result = Fstring (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4726 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4727 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
|
4728 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4729 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4730 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4731 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
|
4732 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4733 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
|
4734 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4735 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4736 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4737 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4738 GCPRO1 (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4739 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
|
4740 UNGCPRO; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4741 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4742 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4743 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4744 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4745 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4746 DEFUN ("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
|
4747 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
|
4748 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4749 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
|
4750 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4751 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
|
4752 \(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
|
4753 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
|
4754 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
|
4755 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4756 Return RESULT-SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4757 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4758 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
|
4759 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4760 (int nargs, Lisp_Object *args)) |
428 | 4761 { |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4762 Elemcount len; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4763 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
|
4764 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
|
4765 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4766 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4767 args[1] = result_sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4768 |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4769 len = shortest_length_among_sequences (nargs - 1, args + 1); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4770 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4771 mapcarX (len, NULL, result_sequence, function, nargs - 2, args + 2, |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4772 Qmap_into); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4773 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4774 return result_sequence; |
428 | 4775 } |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4776 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4777 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
|
4778 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
|
4779 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4780 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
|
4781 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4782 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
|
4783 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
|
4784 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4785 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4786 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4787 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4788 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4789 Lisp_Object result = Qnil, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4790 result_ptr = STORE_VOID_IN_LISP ((void *) &result); |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4791 Elemcount len = shortest_length_among_sequences (nargs - 1, args + 1); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4792 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4793 mapcarX (len, NULL, result_ptr, args[0], nargs - 1, args +1, Qsome); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4794 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4795 return result; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4796 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4797 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4798 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
|
4799 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
|
4800 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4801 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
|
4802 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
|
4803 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4804 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
|
4805 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4806 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4807 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4808 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4809 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4810 Lisp_Object result = Qt, result_ptr = STORE_VOID_IN_LISP ((void *) &result); |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4811 Elemcount len = shortest_length_among_sequences (nargs - 1, args + 1); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4812 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4813 mapcarX (len, NULL, result_ptr, args[0], nargs - 1, args +1, Qevery); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4814 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4815 return result; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4816 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4817 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4818 /* 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
|
4819 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
|
4820 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
|
4821 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4822 CALLER is a symbol reflecting the Lisp-visible function that was called, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4823 and any errors thrown because SEQUENCES was modified will reflect it. |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4824 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4825 If CALLER is Qmapl, return LISTS[0]. Otherwise, return a list of the |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4826 return values from FUNCTION; if caller is Qmapcan, nconc them together. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4827 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4828 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
|
4829 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
|
4830 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
|
4831 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4832 static Lisp_Object |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4833 maplist (Lisp_Object function, int nlists, Lisp_Object *lists, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4834 Lisp_Object caller) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4835 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4836 Lisp_Object nconcing[2], accum = Qnil, *args, *tortoises, funcalled; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4837 Lisp_Object result = EQ (caller, Qmapl) ? lists[0] : Qnil; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4838 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4839 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
|
4840 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4841 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
|
4842 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4843 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
|
4844 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4845 args[i] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4846 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4847 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4848 tortoises = alloca_array (Lisp_Object, nlists); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4849 memcpy (tortoises, lists, nlists * sizeof (Lisp_Object)); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4850 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4851 if (EQ (caller, Qmapcon)) |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4852 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4853 nconcing[0] = Qnil; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4854 nconcing[1] = Qnil; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4855 GCPRO4 (args[0], nconcing[0], tortoises[0], result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4856 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4857 gcpro2.nvars = 2; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4858 gcpro3.nvars = nlists; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4859 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4860 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4861 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4862 GCPRO3 (args[0], tortoises[0], result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4863 gcpro1.nvars = 1; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4864 gcpro2.nvars = nlists; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4865 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4866 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4867 while (continuing) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4868 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4869 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
|
4870 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4871 if (CONSP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4872 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4873 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
|
4874 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
|
4875 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4876 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
|
4877 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4878 continuing = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4879 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4880 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4881 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4882 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4883 lists[j] = wrong_type_argument (Qlistp, lists[j]); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4884 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4885 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4886 if (!continuing) break; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4887 funcalled = IGNORE_MULTIPLE_VALUES (Ffuncall (nlists + 1, args)); |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4888 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4889 if (EQ (caller, Qmapl)) |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4890 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4891 DO_NOTHING; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4892 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4893 else if (EQ (caller, Qmapcon)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4894 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4895 nconcing[1] = funcalled; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4896 accum = bytecode_nconc2 (nconcing); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4897 if (NILP (result)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4898 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4899 result = accum; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4900 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4901 /* Only check a given stretch of result for well-formedness |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4902 once: */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4903 nconcing[0] = funcalled; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4904 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4905 else if (NILP (accum)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4906 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4907 accum = result = Fcons (funcalled, Qnil); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4908 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4909 else |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4910 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4911 /* Add to the end, avoiding the need to call nreverse |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4912 once we're done: */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4913 XSETCDR (accum, Fcons (funcalled, Qnil)); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4914 accum = XCDR (accum); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4915 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4916 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4917 if (++called_count > CIRCULAR_LIST_SUSPICION_LENGTH) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4918 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4919 if (called_count & 1) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4920 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4921 for (j = 0; j < nlists; ++j) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4922 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4923 tortoises[j] = XCDR (tortoises[j]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4924 if (EQ (lists[j], tortoises[j])) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4925 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4926 signal_circular_list_error (lists[j]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4927 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4928 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4929 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4930 else |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4931 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4932 for (j = 0; j < nlists; ++j) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4933 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4934 if (EQ (lists[j], tortoises[j])) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4935 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4936 signal_circular_list_error (lists[j]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4937 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4938 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4939 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4940 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4941 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4942 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4943 RETURN_UNGCPRO (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4944 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4945 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4946 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
|
4947 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
|
4948 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
|
4949 the elements themselves." |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4950 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4951 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
|
4952 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4953 (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
|
4954 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4955 return maplist (args[0], nargs - 1, args + 1, Qmaplist); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4956 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4957 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4958 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
|
4959 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
|
4960 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4961 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
|
4962 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4963 (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
|
4964 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4965 return maplist (args[0], nargs - 1, args + 1, Qmapl); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4966 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4967 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4968 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
|
4969 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
|
4970 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4971 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
|
4972 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
|
4973 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4974 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
|
4975 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4976 (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
|
4977 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4978 return maplist (args[0], nargs - 1, args + 1, Qmapcon); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4979 } |
428 | 4980 |
771 | 4981 /* Extra random functions */ |
442 | 4982 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4983 DEFUN ("reduce", Freduce, 2, MANY, 0, /* |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4984 Combine the elements of sequence using FUNCTION, a binary operation. |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4985 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4986 For example, `(reduce #'+ SEQUENCE)' returns the sum of all elements in |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4987 SEQUENCE, and `(reduce #'union SEQUENCE)' returns the union of all elements |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4988 in SEQUENCE. |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4989 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4990 Keywords supported: :start :end :from-end :initial-value :key |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4991 See `remove*' for the meaning of :start, :end, :from-end and :key. |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4992 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4993 :initial-value specifies an element (typically an identity element, such as |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4994 0) that is conceptually prepended to the sequence (or appended, when |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4995 :from-end is given). |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4996 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4997 If the sequence has one element, that element is returned directly. |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4998 If the sequence has no elements, :initial-value is returned if given; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
4999 otherwise, FUNCTION is called with no arguments, and its result returned. |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5000 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5001 arguments: (FUNCTION SEQUENCE &key (START 0) (END (length SEQUENCE)) FROM-END INITIAL-VALUE (KEY #'identity)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5002 */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5003 (int nargs, Lisp_Object *args)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5004 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5005 Lisp_Object function = args[0], sequence = args[1], accum = Qunbound; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5006 Elemcount starting, ending = EMACS_INT_MAX, ii = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5007 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5008 PARSE_KEYWORDS (Qreduce, nargs, args, 2, 5, |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5009 (start, end, from_end, initial_value, key), |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5010 (start = Qzero, initial_value = Qunbound), 0); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5011 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5012 CHECK_SEQUENCE (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5013 CHECK_NATNUM (start); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5014 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5015 CHECK_KEY_ARGUMENT (key); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5016 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5017 #define KEY(key, item) (EQ (Qidentity, key) ? item : \ |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5018 IGNORE_MULTIPLE_VALUES (call1 (key, item))) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5019 #define CALL2(function, accum, item) \ |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5020 IGNORE_MULTIPLE_VALUES (call2 (function, accum, item)) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5021 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5022 starting = XINT (start); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5023 if (!NILP (end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5024 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5025 CHECK_NATNUM (end); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5026 ending = XINT (end); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5027 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5028 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5029 if (!(starting <= ending)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5030 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5031 check_sequence_range (sequence, start, end, Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5032 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5033 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5034 if (VECTORP (sequence)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5035 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5036 Lisp_Vector *vv = XVECTOR (sequence); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5037 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5038 check_sequence_range (sequence, start, end, make_int (vv->size)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5039 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5040 ending = min (ending, vv->size); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5041 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5042 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5043 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5044 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5045 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5046 else if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5047 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5048 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5049 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5050 accum = KEY (key, vv->contents[starting]); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5051 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5052 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5053 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5054 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5055 accum = KEY (key, vv->contents[ending - 1]); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5056 ending--; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5057 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5058 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5059 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5060 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5061 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5062 for (ii = starting; ii < ending; ++ii) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5063 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5064 accum = CALL2 (function, accum, KEY (key, vv->contents[ii])); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5065 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5066 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5067 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5068 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5069 for (ii = ending - 1; ii >= starting; --ii) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5070 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5071 accum = CALL2 (function, KEY (key, vv->contents[ii]), accum); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5072 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5073 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5074 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5075 else if (BIT_VECTORP (sequence)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5076 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5077 Lisp_Bit_Vector *bv = XBIT_VECTOR (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5078 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5079 check_sequence_range (sequence, start, end, make_int (bv->size)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5080 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5081 ending = min (ending, bv->size); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5082 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5083 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5084 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5085 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5086 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5087 else if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5088 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5089 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5090 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5091 accum = KEY (key, make_int (bit_vector_bit (bv, starting))); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5092 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5093 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5094 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5095 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5096 accum = KEY (key, make_int (bit_vector_bit (bv, ending - 1))); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5097 ending--; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5098 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5099 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5100 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5101 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5102 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5103 for (ii = starting; ii < ending; ++ii) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5104 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5105 accum = CALL2 (function, accum, |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5106 KEY (key, make_int (bit_vector_bit (bv, ii)))); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5107 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5108 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5109 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5110 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5111 for (ii = ending - 1; ii >= starting; --ii) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5112 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5113 accum = CALL2 (function, KEY (key, |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5114 make_int (bit_vector_bit (bv, |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5115 ii))), |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5116 accum); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5117 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5118 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5119 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5120 else if (STRINGP (sequence)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5121 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5122 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5123 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5124 Bytecount byte_len = XSTRING_LENGTH (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5125 Bytecount cursor_offset = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5126 const Ibyte *startp = XSTRING_DATA (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5127 const Ibyte *cursor = startp; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5128 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5129 for (ii = 0; ii != starting && cursor_offset < byte_len; ++ii) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5130 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5131 INC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5132 cursor_offset = cursor - startp; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5133 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5134 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5135 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5136 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5137 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5138 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5139 else if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5140 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5141 accum = KEY (key, make_char (itext_ichar (cursor))); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5142 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5143 startp = XSTRING_DATA (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5144 cursor = startp + cursor_offset; |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5145 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5146 if (byte_len != XSTRING_LENGTH (sequence) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5147 || !valid_ibyteptr_p (cursor)) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5148 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5149 mapping_interaction_error (Qreduce, sequence); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5150 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5151 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5152 INC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5153 cursor_offset = cursor - startp; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5154 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5155 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5156 while (cursor_offset < byte_len && ii < ending) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5157 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5158 accum = CALL2 (function, accum, |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5159 KEY (key, make_char (itext_ichar (cursor)))); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5160 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5161 startp = XSTRING_DATA (sequence); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5162 cursor = startp + cursor_offset; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5163 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5164 if (byte_len != XSTRING_LENGTH (sequence) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5165 || !valid_ibyteptr_p (cursor)) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5166 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5167 mapping_interaction_error (Qreduce, sequence); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5168 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5169 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5170 INC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5171 cursor_offset = cursor - startp; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5172 ++ii; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5173 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5174 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5175 if (ii < starting || (ii < ending && !NILP (end))) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5176 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5177 check_sequence_range (sequence, start, end, Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5178 ABORT (); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5179 } |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5180 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5181 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5182 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5183 Elemcount len = string_char_length (sequence); |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5184 Bytecount cursor_offset, byte_len = XSTRING_LENGTH (sequence); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5185 const Ibyte *cursor; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5186 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5187 check_sequence_range (sequence, start, end, make_int (len)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5188 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5189 ending = min (ending, len); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5190 cursor = string_char_addr (sequence, ending - 1); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5191 cursor_offset = cursor - XSTRING_DATA (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5192 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5193 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5194 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5195 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5196 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5197 else if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5198 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5199 accum = KEY (key, make_char (itext_ichar (cursor))); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5200 ending--; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5201 if (ending > 0) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5202 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5203 cursor = XSTRING_DATA (sequence) + cursor_offset; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5204 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5205 if (!valid_ibyteptr_p (cursor)) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5206 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5207 mapping_interaction_error (Qreduce, sequence); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5208 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5209 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5210 DEC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5211 cursor_offset = cursor - XSTRING_DATA (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5212 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5213 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5214 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5215 for (ii = ending - 1; ii >= starting; --ii) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5216 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5217 accum = CALL2 (function, KEY (key, |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5218 make_char (itext_ichar (cursor))), |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5219 accum); |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5220 if (ii > 0) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5221 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5222 cursor = XSTRING_DATA (sequence) + cursor_offset; |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5223 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5224 if (byte_len != XSTRING_LENGTH (sequence) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5225 || !valid_ibyteptr_p (cursor)) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5226 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5227 mapping_interaction_error (Qreduce, sequence); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5228 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5229 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5230 DEC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5231 cursor_offset = cursor - XSTRING_DATA (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5232 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5233 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5234 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5235 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5236 else if (LISTP (sequence)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5237 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5238 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5239 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5240 struct gcpro gcpro1; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5241 Lisp_Object tailed = Qnil; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5242 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5243 GCPRO1 (tailed); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5244 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5245 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5246 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5247 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5248 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5249 else if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5250 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5251 ii = 0; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5252 EXTERNAL_LIST_LOOP_3 (elt, sequence, tail) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5253 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5254 /* KEY may amputate the list behind us; make sure what |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5255 remains to be processed is still reachable. */ |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5256 tailed = tail; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5257 if (ii == starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5258 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5259 accum = KEY (key, elt); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5260 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5261 break; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5262 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5263 ++ii; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5264 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5265 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5266 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5267 if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5268 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5269 ii = 0; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5270 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5271 EXTERNAL_LIST_LOOP_3 (elt, sequence, tail) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5272 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5273 /* KEY or FUNCTION may amputate the list behind us; make |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5274 sure what remains to be processed is still |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5275 reachable. */ |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5276 tailed = tail; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5277 if (ii >= starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5278 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5279 if (ii < ending) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5280 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5281 accum = CALL2 (function, accum, KEY (key, elt)); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5282 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5283 else if (ii == ending) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5284 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5285 break; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5286 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5287 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5288 ++ii; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5289 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5290 } |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5291 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5292 UNGCPRO; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5293 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5294 if (ii < starting || (ii < ending && !NILP (end))) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5295 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5296 check_sequence_range (sequence, start, end, Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5297 ABORT (); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5298 } |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5299 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5300 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5301 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5302 Boolint need_accum = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5303 Lisp_Object *subsequence = NULL; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5304 Elemcount counting = 0, len = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5305 struct gcpro gcpro1; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5306 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5307 len = XINT (Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5308 check_sequence_range (sequence, start, end, make_int (len)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5309 ending = min (ending, len); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5310 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5311 /* :from-end with a list; make an alloca copy of the relevant list |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5312 data, attempting to go backwards isn't worth the trouble. */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5313 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5314 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5315 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5316 if (ending - starting && starting < ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5317 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5318 subsequence = alloca_array (Lisp_Object, ending - starting); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5319 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5320 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5321 else if (ending - starting && starting < ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5322 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5323 subsequence = alloca_array (Lisp_Object, ending - starting); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5324 need_accum = 1; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5325 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5326 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5327 if (ending - starting && starting < ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5328 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5329 EXTERNAL_LIST_LOOP_3 (elt, sequence, tail) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5330 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5331 if (counting >= starting) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5332 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5333 if (counting < ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5334 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5335 subsequence[ii++] = elt; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5336 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5337 else if (counting == ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5338 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5339 break; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5340 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5341 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5342 ++counting; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5343 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5344 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5345 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5346 if (subsequence != NULL) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5347 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5348 len = ending - starting; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5349 /* If we could be sure that neither FUNCTION nor KEY modify |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5350 SEQUENCE, this wouldn't be necessary, since all the |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5351 elements of SUBSEQUENCE would definitely always be |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5352 reachable via SEQUENCE. */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5353 GCPRO1 (subsequence[0]); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5354 gcpro1.nvars = len; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5355 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5356 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5357 if (need_accum) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5358 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5359 accum = KEY (key, subsequence[len - 1]); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5360 --len; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5361 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5362 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5363 for (ii = len; ii != 0;) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5364 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5365 --ii; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5366 accum = CALL2 (function, KEY (key, subsequence[ii]), accum); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5367 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5368 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5369 if (subsequence != NULL) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5370 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5371 UNGCPRO; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5372 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5373 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5374 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5375 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5376 /* At this point, if ACCUM is unbound, SEQUENCE has no elements; we |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5377 need to return the result of calling FUNCTION with zero |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5378 arguments. */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5379 if (UNBOUNDP (accum)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5380 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5381 accum = IGNORE_MULTIPLE_VALUES (call0 (function)); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5382 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5383 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5384 return accum; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5385 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5386 |
442 | 5387 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /* |
5388 Destructively replace the list OLD with NEW. | |
5389 This is like (copy-sequence NEW) except that it reuses the | |
5390 conses in OLD as much as possible. If OLD and NEW are the same | |
5391 length, no consing will take place. | |
5392 */ | |
3025 | 5393 (old, new_)) |
442 | 5394 { |
2367 | 5395 Lisp_Object oldtail = old, prevoldtail = Qnil; |
5396 | |
3025 | 5397 EXTERNAL_LIST_LOOP_2 (elt, new_) |
442 | 5398 { |
5399 if (!NILP (oldtail)) | |
5400 { | |
5401 CHECK_CONS (oldtail); | |
2367 | 5402 XCAR (oldtail) = elt; |
442 | 5403 } |
5404 else if (!NILP (prevoldtail)) | |
5405 { | |
2367 | 5406 XCDR (prevoldtail) = Fcons (elt, Qnil); |
442 | 5407 prevoldtail = XCDR (prevoldtail); |
5408 } | |
5409 else | |
2367 | 5410 old = oldtail = Fcons (elt, Qnil); |
442 | 5411 |
5412 if (!NILP (oldtail)) | |
5413 { | |
5414 prevoldtail = oldtail; | |
5415 oldtail = XCDR (oldtail); | |
5416 } | |
5417 } | |
5418 | |
5419 if (!NILP (prevoldtail)) | |
5420 XCDR (prevoldtail) = Qnil; | |
5421 else | |
5422 old = Qnil; | |
5423 | |
5424 return old; | |
5425 } | |
5426 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5427 /* This function is the implementation of fill_string_range() and |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5428 replace_string_range(); see the comments for those functions. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5429 static Lisp_Object |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5430 replace_string_range_1 (Lisp_Object dest, Lisp_Object start, Lisp_Object end, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5431 const Ibyte *source, const Ibyte *source_limit, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5432 Lisp_Object item) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5433 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5434 Ibyte *destp = XSTRING_DATA (dest), *p = destp, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5435 *pend = p + XSTRING_LENGTH (dest), *pcursor, item_buf[MAX_ICHAR_LEN]; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5436 Bytecount prefix_bytecount, source_len = source_limit - source; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5437 Charcount ii = 0, starting = XINT (start), ending, len; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5438 Elemcount delta; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5439 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5440 while (ii < starting && p < pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5441 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5442 INC_IBYTEPTR (p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5443 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5444 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5445 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5446 pcursor = p; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5447 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5448 if (NILP (end)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5449 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5450 while (pcursor < pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5451 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5452 INC_IBYTEPTR (pcursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5453 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5454 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5455 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5456 ending = len = ii; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5457 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5458 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5459 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5460 ending = XINT (end); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5461 while (ii < ending && pcursor < pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5462 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5463 INC_IBYTEPTR (pcursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5464 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5465 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5466 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5467 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5468 if (pcursor == pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5469 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5470 /* We have the length, check it for our callers. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5471 check_sequence_range (dest, start, end, make_int (ii)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5472 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5473 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5474 if (!(p == pend || p == pcursor)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5475 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5476 prefix_bytecount = p - destp; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5477 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5478 if (!NILP (item)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5479 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5480 assert (source == NULL && source_limit == NULL); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5481 source_len = set_itext_ichar (item_buf, XCHAR (item)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5482 delta = (source_len * (ending - starting)) - (pcursor - p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5483 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5484 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5485 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5486 assert (source != NULL && source_limit != NULL); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5487 delta = source_len - (pcursor - p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5488 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5489 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5490 if (delta) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5491 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5492 resize_string (dest, prefix_bytecount, delta); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5493 destp = XSTRING_DATA (dest); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5494 pcursor = destp + prefix_bytecount + (pcursor - p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5495 p = destp + prefix_bytecount; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5496 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5497 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5498 if (CHARP (item)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5499 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5500 while (starting < ending) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5501 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5502 memcpy (p, item_buf, source_len); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5503 p += source_len; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5504 starting++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5505 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5506 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5507 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5508 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5509 while (starting < ending && source < source_limit) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5510 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5511 source_len = itext_copy_ichar (source, p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5512 p += source_len, source += source_len; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5513 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5514 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5515 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5516 init_string_ascii_begin (dest); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5517 bump_string_modiff (dest); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5518 sledgehammer_check_ascii_begin (dest); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5519 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5520 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5521 return dest; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5522 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5523 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5524 DEFUN ("replace", Freplace, 2, MANY, 0, /* |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5525 Replace the elements of SEQUENCE-ONE with the elements of SEQUENCE-TWO. |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5526 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5527 SEQUENCE-ONE is destructively modified, and returned. Its length is not |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5528 changed. |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5529 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5530 Keywords :start1 and :end1 specify a subsequence of SEQUENCE-ONE, and |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5531 :start2 and :end2 a subsequence of SEQUENCE-TWO. See `search' for more |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5532 information. |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5533 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5534 arguments: (SEQUENCE-ONE SEQUENCE-TWO &key (START1 0) (END1 (length SEQUENCE-ONE)) (START2 0) (END2 (length SEQUENCE-TWO))) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5535 */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5536 (int nargs, Lisp_Object *args)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5537 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5538 Lisp_Object sequence1 = args[0], sequence2 = args[1], |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5539 result = sequence1; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5540 Elemcount starting1, ending1 = EMACS_INT_MAX, starting2; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5541 Elemcount ending2 = EMACS_INT_MAX, counting = 0, startcounting; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5542 Boolint sequence1_listp, sequence2_listp, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5543 overwriting = EQ (sequence1, sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5544 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5545 PARSE_KEYWORDS (Qreplace, nargs, args, 2, 4, (start1, end1, start2, end2), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5546 (start1 = start2 = Qzero), 0); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5547 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5548 CHECK_SEQUENCE (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5549 CHECK_LISP_WRITEABLE (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5550 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5551 CHECK_SEQUENCE (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5552 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5553 CHECK_NATNUM (start1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5554 starting1 = XINT (start1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5555 CHECK_NATNUM (start2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5556 starting2 = XINT (start2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5557 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5558 if (!NILP (end1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5559 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5560 CHECK_NATNUM (end1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5561 ending1 = XINT (end1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5562 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5563 if (!(starting1 <= ending1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5564 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5565 args_out_of_range_3 (sequence1, start1, end1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5566 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5567 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5568 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5569 if (!NILP (end2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5570 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5571 CHECK_NATNUM (end2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5572 ending2 = XINT (end2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5573 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5574 if (!(starting2 <= ending2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5575 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5576 args_out_of_range_3 (sequence1, start2, end2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5577 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5578 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5579 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5580 sequence1_listp = LISTP (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5581 sequence2_listp = LISTP (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5582 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5583 overwriting = overwriting && starting2 <= starting1; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5584 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5585 if (sequence1_listp && !ZEROP (start1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5586 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5587 sequence1 = Fnthcdr (start1, sequence1); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5588 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5589 if (NILP (sequence1)) |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5590 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5591 check_sequence_range (args[0], start1, end1, Flength (args[0])); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5592 /* Give up early here. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5593 return result; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5594 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5595 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5596 ending1 -= starting1; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5597 starting1 = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5598 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5599 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5600 if (sequence2_listp && !ZEROP (start2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5601 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5602 sequence2 = Fnthcdr (start2, sequence2); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5603 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5604 if (NILP (sequence2)) |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5605 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5606 check_sequence_range (args[1], start1, end1, Flength (args[1])); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5607 /* Nothing available to replace sequence1's contents. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5608 return result; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5609 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5610 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5611 ending2 -= starting2; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5612 starting2 = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5613 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5614 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5615 if (overwriting) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5616 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5617 if (EQ (start1, start2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5618 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5619 return result; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5620 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5621 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5622 /* Our ranges may overlap. Save the data that might be overwritten. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5623 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5624 if (CONSP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5625 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5626 Elemcount len = XINT (Flength (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5627 Lisp_Object *subsequence |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5628 = alloca_array (Lisp_Object, min (ending2, len)); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5629 Elemcount ii = 0; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5630 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5631 LIST_LOOP_2 (elt, sequence2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5632 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5633 if (counting == ending2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5634 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5635 break; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5636 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5637 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5638 subsequence[ii++] = elt; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5639 counting++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5640 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5641 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5642 check_sequence_range (sequence1, start1, end1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5643 /* The XINT (start2) is intentional here; we |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5644 called #'length after doing (nthcdr |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5645 start2 sequence2). */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5646 make_int (XINT (start2) + len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5647 check_sequence_range (sequence2, start2, end2, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5648 make_int (XINT (start2) + len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5649 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5650 while (starting1 < ending1 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5651 && starting2 < ending2 && !NILP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5652 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5653 XSETCAR (sequence1, subsequence[starting2]); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5654 sequence1 = XCDR (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5655 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5656 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5657 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5658 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5659 else if (STRINGP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5660 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5661 Ibyte *p = XSTRING_DATA (sequence2), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5662 *pend = p + XSTRING_LENGTH (sequence2), *pcursor, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5663 *staging; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5664 Bytecount ii = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5665 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5666 while (ii < starting2 && p < pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5667 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5668 INC_IBYTEPTR (p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5669 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5670 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5671 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5672 pcursor = p; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5673 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5674 while (ii < ending2 && starting1 < ending1 && pcursor < pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5675 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5676 INC_IBYTEPTR (pcursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5677 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5678 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5679 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5680 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5681 if (pcursor == pend) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5682 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5683 check_sequence_range (sequence1, start1, end1, make_int (ii)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5684 check_sequence_range (sequence2, start2, end2, make_int (ii)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5685 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5686 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5687 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5688 assert ((pcursor - p) > 0); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5689 staging = alloca_ibytes (pcursor - p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5690 memcpy (staging, p, pcursor - p); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5691 replace_string_range (result, start1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5692 make_int (starting1), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5693 staging, staging + (pcursor - p)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5694 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5695 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5696 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5697 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5698 Elemcount seq_len = XINT (Flength (sequence2)), ii = 0, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5699 subseq_len = min (min (ending1 - starting1, seq_len - starting1), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5700 min (ending2 - starting2, seq_len - starting2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5701 Lisp_Object *subsequence = alloca_array (Lisp_Object, subseq_len); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5702 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5703 check_sequence_range (sequence1, start1, end1, make_int (seq_len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5704 check_sequence_range (sequence2, start2, end2, make_int (seq_len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5705 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5706 while (starting2 < ending2 && ii < seq_len) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5707 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5708 subsequence[ii] = Faref (sequence2, make_int (starting2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5709 ii++, starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5710 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5711 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5712 ii = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5713 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5714 while (starting1 < ending1 && ii < seq_len) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5715 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5716 Faset (sequence1, make_int (starting1), subsequence[ii]); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5717 ii++, starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5718 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5719 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5720 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5721 else if (sequence1_listp && sequence2_listp) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5722 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5723 Lisp_Object sequence1_tortoise = sequence1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5724 sequence2_tortoise = sequence2; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5725 Elemcount shortest_len = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5726 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5727 counting = startcounting = min (ending1, ending2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5728 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5729 while (counting-- > 0 && !NILP (sequence1) && !NILP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5730 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5731 XSETCAR (sequence1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5732 CONSP (sequence2) ? XCAR (sequence2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5733 : Fcar (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5734 sequence1 = CONSP (sequence1) ? XCDR (sequence1) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5735 : Fcdr (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5736 sequence2 = CONSP (sequence2) ? XCDR (sequence2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5737 : Fcdr (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5738 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5739 shortest_len++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5740 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5741 if (startcounting - counting > CIRCULAR_LIST_SUSPICION_LENGTH) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5742 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5743 if (counting & 1) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5744 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5745 sequence1_tortoise = XCDR (sequence1_tortoise); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5746 sequence2_tortoise = XCDR (sequence2_tortoise); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5747 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5748 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5749 if (EQ (sequence1, sequence1_tortoise)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5750 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5751 signal_circular_list_error (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5752 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5753 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5754 if (EQ (sequence2, sequence2_tortoise)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5755 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5756 signal_circular_list_error (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5757 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5758 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5759 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5760 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5761 if (NILP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5762 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5763 check_sequence_range (sequence1, start1, end1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5764 make_int (XINT (start1) + shortest_len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5765 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5766 else if (NILP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5767 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5768 check_sequence_range (sequence2, start2, end2, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5769 make_int (XINT (start2) + shortest_len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5770 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5771 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5772 else if (sequence1_listp) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5773 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5774 if (STRINGP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5775 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5776 Ibyte *s2_data = XSTRING_DATA (sequence2), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5777 *s2_end = s2_data + XSTRING_LENGTH (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5778 Elemcount char_count = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5779 Lisp_Object character; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5780 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5781 while (char_count < starting2 && s2_data < s2_end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5782 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5783 INC_IBYTEPTR (s2_data); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5784 char_count++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5785 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5786 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5787 while (starting1 < ending1 && starting2 < ending2 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5788 && s2_data < s2_end && !NILP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5789 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5790 character = make_char (itext_ichar (s2_data)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5791 CONSP (sequence1) ? |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5792 XSETCAR (sequence1, character) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5793 : Fsetcar (sequence1, character); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5794 sequence1 = XCDR (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5795 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5796 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5797 char_count++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5798 INC_IBYTEPTR (s2_data); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5799 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5800 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5801 if (NILP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5802 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5803 check_sequence_range (sequence1, start1, end1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5804 make_int (XINT (start1) + starting1)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5805 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5806 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5807 if (s2_data == s2_end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5808 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5809 check_sequence_range (sequence2, start2, end2, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5810 make_int (char_count)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5811 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5812 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5813 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5814 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5815 Elemcount len2 = XINT (Flength (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5816 check_sequence_range (sequence2, start2, end2, make_int (len2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5817 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5818 ending2 = min (ending2, len2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5819 while (starting2 < ending2 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5820 && starting1 < ending1 && !NILP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5821 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5822 CHECK_CONS (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5823 XSETCAR (sequence1, Faref (sequence2, make_int (starting2))); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5824 sequence1 = XCDR (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5825 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5826 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5827 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5828 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5829 if (NILP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5830 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5831 check_sequence_range (sequence1, start1, end1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5832 make_int (XINT (start1) + starting1)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5833 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5834 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5835 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5836 else if (sequence2_listp) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5837 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5838 if (STRINGP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5839 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5840 Elemcount ii = 0, count, len = string_char_length (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5841 Ibyte *staging, *cursor; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5842 Lisp_Object obj; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5843 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5844 check_sequence_range (sequence1, start1, end1, make_int (len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5845 ending1 = min (ending1, len); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5846 count = ending1 - starting1; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5847 staging = cursor = alloca_ibytes (count * MAX_ICHAR_LEN); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5848 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5849 while (ii < count && !NILP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5850 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5851 obj = CONSP (sequence2) ? XCAR (sequence2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5852 : Fcar (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5853 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5854 CHECK_CHAR_COERCE_INT (obj); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5855 cursor += set_itext_ichar (cursor, XCHAR (obj)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5856 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5857 sequence2 = XCDR (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5858 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5859 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5860 if (NILP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5861 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5862 check_sequence_range (sequence2, start2, end2, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5863 make_int (XINT (start2) + ii)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5864 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5865 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5866 replace_string_range (result, start1, make_int (XINT (start1) + ii), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5867 staging, cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5868 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5869 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5870 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5871 Elemcount len = XINT (Flength (sequence1)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5872 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5873 check_sequence_range (sequence1, start2, end1, make_int (len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5874 ending1 = min (ending2, min (ending1, len)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5875 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5876 while (starting1 < ending1 && !NILP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5877 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5878 Faset (sequence1, make_int (starting1), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5879 CONSP (sequence2) ? XCAR (sequence2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5880 : Fcar (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5881 sequence2 = XCDR (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5882 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5883 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5884 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5885 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5886 if (NILP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5887 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5888 check_sequence_range (sequence2, start2, end2, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5889 make_int (XINT (start2) + starting2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5890 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5891 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5892 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5893 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5894 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5895 if (STRINGP (sequence1) && STRINGP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5896 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5897 Ibyte *p2 = XSTRING_DATA (sequence2), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5898 *p2end = p2 + XSTRING_LENGTH (sequence2), *p2cursor; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5899 Charcount ii = 0, len1 = string_char_length (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5900 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5901 while (ii < starting2 && p2 < p2end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5902 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5903 INC_IBYTEPTR (p2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5904 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5905 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5906 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5907 p2cursor = p2; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5908 ending1 = min (ending1, len1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5909 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5910 while (ii < ending2 && starting1 < ending1 && p2cursor < p2end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5911 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5912 INC_IBYTEPTR (p2cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5913 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5914 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5915 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5916 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5917 if (p2cursor == p2end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5918 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5919 check_sequence_range (sequence2, start2, end2, make_int (ii)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5920 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5921 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5922 /* This isn't great; any error message won't necessarily reflect |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5923 the END1 that was supplied to #'replace. */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5924 replace_string_range (result, start1, make_int (starting1), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5925 p2, p2cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5926 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5927 else if (STRINGP (sequence1)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5928 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5929 Ibyte *staging, *cursor; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5930 Elemcount count, len1 = string_char_length (sequence1); |
5262
75bcb5bef459
Replace a doubled semi-colon with a single semi-colon, fns.c, for VS6's sake.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
5931 Elemcount len2 = XINT (Flength (sequence2)), ii = 0; |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5932 Lisp_Object obj; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5933 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5934 check_sequence_range (sequence1, start1, end1, make_int (len1)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5935 check_sequence_range (sequence2, start2, end2, make_int (len2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5936 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5937 ending1 = min (ending1, len1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5938 ending2 = min (ending2, len2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5939 count = min (ending1 - starting1, ending2 - starting2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5940 staging = cursor = alloca_ibytes (count * MAX_ICHAR_LEN); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5941 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5942 ii = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5943 while (ii < count) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5944 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5945 obj = Faref (sequence2, make_int (starting2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5946 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5947 CHECK_CHAR_COERCE_INT (obj); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5948 cursor += set_itext_ichar (cursor, XCHAR (obj)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5949 starting2++, ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5950 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5951 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5952 replace_string_range (result, start1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5953 make_int (XINT (start1) + count), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5954 staging, cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5955 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5956 else if (STRINGP (sequence2)) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5957 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5958 Ibyte *p2 = XSTRING_DATA (sequence2), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5959 *p2end = p2 + XSTRING_LENGTH (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5960 Elemcount len1 = XINT (Flength (sequence1)), ii = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5961 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5962 check_sequence_range (sequence1, start1, end1, make_int (len1)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5963 ending1 = min (ending1, len1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5964 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5965 while (ii < starting2 && p2 < p2end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5966 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5967 INC_IBYTEPTR (p2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5968 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5969 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5970 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5971 while (p2 < p2end && starting1 < ending1 && starting2 < ending2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5972 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5973 Faset (sequence1, make_int (starting1), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5974 make_char (itext_ichar (p2))); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5975 INC_IBYTEPTR (p2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5976 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5977 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5978 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5979 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5980 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5981 if (p2 == p2end) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5982 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5983 check_sequence_range (sequence2, start2, end2, make_int (ii)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5984 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5985 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5986 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5987 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5988 Elemcount len1 = XINT (Flength (sequence1)), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5989 len2 = XINT (Flength (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5990 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5991 check_sequence_range (sequence1, start1, end1, make_int (len1)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5992 check_sequence_range (sequence2, start2, end2, make_int (len2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5993 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5994 ending1 = min (ending1, len1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5995 ending2 = min (ending2, len2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5996 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5997 while (starting1 < ending1 && starting2 < ending2) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5998 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5999 Faset (sequence1, make_int (starting1), |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6000 Faref (sequence2, make_int (starting2))); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6001 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6002 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6003 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6004 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6005 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6006 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6007 return result; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6008 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6009 |
771 | 6010 Lisp_Object |
2367 | 6011 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string) |
771 | 6012 { |
6013 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
|
6014 build_ascstring (ascii_string)), |
771 | 6015 Qnil); |
6016 } | |
6017 | |
6018 Lisp_Object | |
2367 | 6019 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol) |
771 | 6020 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
6021 return Fintern (concat2 (build_ascstring (ascii_string), |
771 | 6022 Fsymbol_name (symbol)), |
6023 Qnil); | |
6024 } | |
6025 | |
442 | 6026 |
428 | 6027 /* #### this function doesn't belong in this file! */ |
6028 | |
442 | 6029 #ifdef HAVE_GETLOADAVG |
6030 #ifdef HAVE_SYS_LOADAVG_H | |
6031 #include <sys/loadavg.h> | |
6032 #endif | |
6033 #else | |
6034 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */ | |
6035 #endif | |
6036 | |
428 | 6037 DEFUN ("load-average", Fload_average, 0, 1, 0, /* |
6038 Return list of 1 minute, 5 minute and 15 minute load averages. | |
6039 Each of the three load averages is multiplied by 100, | |
6040 then converted to integer. | |
6041 | |
6042 When USE-FLOATS is non-nil, floats will be used instead of integers. | |
6043 These floats are not multiplied by 100. | |
6044 | |
6045 If the 5-minute or 15-minute load averages are not available, return a | |
6046 shortened list, containing only those averages which are available. | |
6047 | |
6048 On some systems, this won't work due to permissions on /dev/kmem, | |
6049 in which case you can't use this. | |
6050 */ | |
6051 (use_floats)) | |
6052 { | |
6053 double load_ave[3]; | |
6054 int loads = getloadavg (load_ave, countof (load_ave)); | |
6055 Lisp_Object ret = Qnil; | |
6056 | |
6057 if (loads == -2) | |
563 | 6058 signal_error (Qunimplemented, |
6059 "load-average not implemented for this operating system", | |
6060 Qunbound); | |
428 | 6061 else if (loads < 0) |
563 | 6062 invalid_operation ("Could not get load-average", lisp_strerror (errno)); |
428 | 6063 |
6064 while (loads-- > 0) | |
6065 { | |
6066 Lisp_Object load = (NILP (use_floats) ? | |
6067 make_int ((int) (100.0 * load_ave[loads])) | |
6068 : make_float (load_ave[loads])); | |
6069 ret = Fcons (load, ret); | |
6070 } | |
6071 return ret; | |
6072 } | |
6073 | |
6074 | |
6075 Lisp_Object Vfeatures; | |
6076 | |
6077 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /* | |
6078 Return non-nil if feature FEXP is present in this Emacs. | |
6079 Use this to conditionalize execution of lisp code based on the | |
6080 presence or absence of emacs or environment extensions. | |
6081 FEXP can be a symbol, a number, or a list. | |
6082 If it is a symbol, that symbol is looked up in the `features' variable, | |
6083 and non-nil will be returned if found. | |
6084 If it is a number, the function will return non-nil if this Emacs | |
6085 has an equal or greater version number than FEXP. | |
6086 If it is a list whose car is the symbol `and', it will return | |
6087 non-nil if all the features in its cdr are non-nil. | |
6088 If it is a list whose car is the symbol `or', it will return non-nil | |
6089 if any of the features in its cdr are non-nil. | |
6090 If it is a list whose car is the symbol `not', it will return | |
6091 non-nil if the feature is not present. | |
6092 | |
6093 Examples: | |
6094 | |
6095 (featurep 'xemacs) | |
6096 => ; Non-nil on XEmacs. | |
6097 | |
6098 (featurep '(and xemacs gnus)) | |
6099 => ; Non-nil on XEmacs with Gnus loaded. | |
6100 | |
6101 (featurep '(or tty-frames (and emacs 19.30))) | |
6102 => ; Non-nil if this Emacs supports TTY frames. | |
6103 | |
6104 (featurep '(or (and xemacs 19.15) (and emacs 19.34))) | |
6105 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later. | |
6106 | |
442 | 6107 (featurep '(and xemacs 21.02)) |
6108 => ; Non-nil on XEmacs 21.2 and later. | |
6109 | |
428 | 6110 NOTE: The advanced arguments of this function (anything other than a |
6111 symbol) are not yet supported by FSF Emacs. If you feel they are useful | |
6112 for supporting multiple Emacs variants, lobby Richard Stallman at | |
442 | 6113 <bug-gnu-emacs@gnu.org>. |
428 | 6114 */ |
6115 (fexp)) | |
6116 { | |
6117 #ifndef FEATUREP_SYNTAX | |
6118 CHECK_SYMBOL (fexp); | |
6119 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
6120 #else /* FEATUREP_SYNTAX */ | |
6121 static double featurep_emacs_version; | |
6122 | |
6123 /* Brute force translation from Erik Naggum's lisp function. */ | |
6124 if (SYMBOLP (fexp)) | |
6125 { | |
6126 /* Original definition */ | |
6127 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
6128 } | |
6129 else if (INTP (fexp) || FLOATP (fexp)) | |
6130 { | |
6131 double d = extract_float (fexp); | |
6132 | |
6133 if (featurep_emacs_version == 0.0) | |
6134 { | |
6135 featurep_emacs_version = XINT (Vemacs_major_version) + | |
6136 (XINT (Vemacs_minor_version) / 100.0); | |
6137 } | |
6138 return featurep_emacs_version >= d ? Qt : Qnil; | |
6139 } | |
6140 else if (CONSP (fexp)) | |
6141 { | |
6142 Lisp_Object tem = XCAR (fexp); | |
6143 if (EQ (tem, Qnot)) | |
6144 { | |
6145 Lisp_Object negate; | |
6146 | |
6147 tem = XCDR (fexp); | |
6148 negate = Fcar (tem); | |
6149 if (!NILP (tem)) | |
6150 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil; | |
6151 else | |
6152 return Fsignal (Qinvalid_read_syntax, list1 (tem)); | |
6153 } | |
6154 else if (EQ (tem, Qand)) | |
6155 { | |
6156 tem = XCDR (fexp); | |
6157 /* Use Fcar/Fcdr for error-checking. */ | |
6158 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem)))) | |
6159 { | |
6160 tem = Fcdr (tem); | |
6161 } | |
6162 return NILP (tem) ? Qt : Qnil; | |
6163 } | |
6164 else if (EQ (tem, Qor)) | |
6165 { | |
6166 tem = XCDR (fexp); | |
6167 /* Use Fcar/Fcdr for error-checking. */ | |
6168 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem)))) | |
6169 { | |
6170 tem = Fcdr (tem); | |
6171 } | |
6172 return NILP (tem) ? Qnil : Qt; | |
6173 } | |
6174 else | |
6175 { | |
6176 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp))); | |
6177 } | |
6178 } | |
6179 else | |
6180 { | |
6181 return Fsignal (Qinvalid_read_syntax, list1 (fexp)); | |
6182 } | |
6183 } | |
6184 #endif /* FEATUREP_SYNTAX */ | |
6185 | |
6186 DEFUN ("provide", Fprovide, 1, 1, 0, /* | |
6187 Announce that FEATURE is a feature of the current Emacs. | |
6188 This function updates the value of the variable `features'. | |
6189 */ | |
6190 (feature)) | |
6191 { | |
6192 Lisp_Object tem; | |
6193 CHECK_SYMBOL (feature); | |
6194 if (!NILP (Vautoload_queue)) | |
6195 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); | |
6196 tem = Fmemq (feature, Vfeatures); | |
6197 if (NILP (tem)) | |
6198 Vfeatures = Fcons (feature, Vfeatures); | |
6199 LOADHIST_ATTACH (Fcons (Qprovide, feature)); | |
6200 return feature; | |
6201 } | |
6202 | |
1067 | 6203 DEFUN ("require", Frequire, 1, 3, 0, /* |
3842 | 6204 Ensure that FEATURE is present in the Lisp environment. |
6205 FEATURE is a symbol naming a collection of resources (functions, etc). | |
6206 Optional FILENAME is a library from which to load resources; it defaults to | |
6207 the print name of FEATURE. | |
6208 Optional NOERROR, if non-nil, causes require to return nil rather than signal | |
6209 `file-error' if loading the library fails. | |
6210 | |
6211 If feature FEATURE is present in `features', update `load-history' to reflect | |
6212 the require and return FEATURE. Otherwise, try to load it from a library. | |
6213 The normal messages at start and end of loading are suppressed. | |
6214 If the library is successfully loaded and it calls `(provide FEATURE)', add | |
6215 FEATURE to `features', update `load-history' and return FEATURE. | |
6216 If the load succeeds but FEATURE is not provided by the library, signal | |
6217 `invalid-state'. | |
6218 | |
6219 The byte-compiler treats top-level calls to `require' specially, by evaluating | |
6220 them at compile time (and then compiling them normally). Thus a library may | |
6221 request that definitions that should be inlined such as macros and defsubsts | |
6222 be loaded into its compilation environment. Achieving this in other contexts | |
6223 requires an explicit \(eval-and-compile ...\) block. | |
428 | 6224 */ |
1067 | 6225 (feature, filename, noerror)) |
428 | 6226 { |
6227 Lisp_Object tem; | |
6228 CHECK_SYMBOL (feature); | |
6229 tem = Fmemq (feature, Vfeatures); | |
6230 LOADHIST_ATTACH (Fcons (Qrequire, feature)); | |
6231 if (!NILP (tem)) | |
6232 return feature; | |
6233 else | |
6234 { | |
6235 int speccount = specpdl_depth (); | |
6236 | |
6237 /* Value saved here is to be restored into Vautoload_queue */ | |
6238 record_unwind_protect (un_autoload, Vautoload_queue); | |
6239 Vautoload_queue = Qt; | |
6240 | |
1067 | 6241 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename, |
1261 | 6242 noerror, Qrequire, Qnil); |
1067 | 6243 /* If load failed entirely, return nil. */ |
6244 if (NILP (tem)) | |
6245 return unbind_to_1 (speccount, Qnil); | |
428 | 6246 |
6247 tem = Fmemq (feature, Vfeatures); | |
6248 if (NILP (tem)) | |
563 | 6249 invalid_state ("Required feature was not provided", feature); |
428 | 6250 |
6251 /* Once loading finishes, don't undo it. */ | |
6252 Vautoload_queue = Qt; | |
771 | 6253 return unbind_to_1 (speccount, feature); |
428 | 6254 } |
6255 } | |
6256 | |
6257 /* base64 encode/decode functions. | |
6258 | |
6259 Originally based on code from GNU recode. Ported to FSF Emacs by | |
6260 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and | |
6261 subsequently heavily hacked by Hrvoje Niksic. */ | |
6262 | |
6263 #define MIME_LINE_LENGTH 72 | |
6264 | |
6265 #define IS_ASCII(Character) \ | |
6266 ((Character) < 128) | |
6267 #define IS_BASE64(Character) \ | |
6268 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | |
6269 | |
6270 /* 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
|
6271 static Ascbyte base64_value_to_char[64] = |
428 | 6272 { |
6273 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */ | |
6274 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */ | |
6275 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */ | |
6276 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */ | |
6277 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */ | |
6278 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */ | |
6279 '8', '9', '+', '/' /* 60-63 */ | |
6280 }; | |
6281 | |
6282 /* Table of base64 values for first 128 characters. */ | |
6283 static short base64_char_to_value[128] = | |
6284 { | |
6285 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */ | |
6286 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */ | |
6287 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */ | |
6288 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */ | |
6289 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */ | |
6290 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */ | |
6291 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */ | |
6292 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */ | |
6293 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */ | |
6294 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */ | |
6295 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */ | |
6296 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */ | |
6297 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */ | |
6298 }; | |
6299 | |
6300 /* The following diagram shows the logical steps by which three octets | |
6301 get transformed into four base64 characters. | |
6302 | |
6303 .--------. .--------. .--------. | |
6304 |aaaaaabb| |bbbbcccc| |ccdddddd| | |
6305 `--------' `--------' `--------' | |
6306 6 2 4 4 2 6 | |
6307 .--------+--------+--------+--------. | |
6308 |00aaaaaa|00bbbbbb|00cccccc|00dddddd| | |
6309 `--------+--------+--------+--------' | |
6310 | |
6311 .--------+--------+--------+--------. | |
6312 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD| | |
6313 `--------+--------+--------+--------' | |
6314 | |
6315 The octets are divided into 6 bit chunks, which are then encoded into | |
6316 base64 characters. */ | |
6317 | |
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
|
6318 static DECLARE_DOESNT_RETURN (base64_conversion_error (const Ascbyte *, |
2268 | 6319 Lisp_Object)); |
6320 | |
575 | 6321 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
|
6322 base64_conversion_error (const Ascbyte *reason, Lisp_Object frob) |
563 | 6323 { |
6324 signal_error (Qbase64_conversion_error, reason, frob); | |
6325 } | |
6326 | |
6327 #define ADVANCE_INPUT(c, stream) \ | |
867 | 6328 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \ |
563 | 6329 ((ec > 255) ? \ |
6330 (base64_conversion_error ("Non-ascii character in base64 input", \ | |
6331 make_char (ec)), 0) \ | |
867 | 6332 : (c = (Ibyte)ec), 1)) |
665 | 6333 |
6334 static Bytebpos | |
867 | 6335 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break) |
428 | 6336 { |
6337 EMACS_INT counter = 0; | |
867 | 6338 Ibyte *e = to; |
6339 Ichar ec; | |
428 | 6340 unsigned int value; |
6341 | |
6342 while (1) | |
6343 { | |
1204 | 6344 Ibyte c = 0; |
428 | 6345 if (!ADVANCE_INPUT (c, istream)) |
6346 break; | |
6347 | |
6348 /* Wrap line every 76 characters. */ | |
6349 if (line_break) | |
6350 { | |
6351 if (counter < MIME_LINE_LENGTH / 4) | |
6352 counter++; | |
6353 else | |
6354 { | |
6355 *e++ = '\n'; | |
6356 counter = 1; | |
6357 } | |
6358 } | |
6359 | |
6360 /* Process first byte of a triplet. */ | |
6361 *e++ = base64_value_to_char[0x3f & c >> 2]; | |
6362 value = (0x03 & c) << 4; | |
6363 | |
6364 /* Process second byte of a triplet. */ | |
6365 if (!ADVANCE_INPUT (c, istream)) | |
6366 { | |
6367 *e++ = base64_value_to_char[value]; | |
6368 *e++ = '='; | |
6369 *e++ = '='; | |
6370 break; | |
6371 } | |
6372 | |
6373 *e++ = base64_value_to_char[value | (0x0f & c >> 4)]; | |
6374 value = (0x0f & c) << 2; | |
6375 | |
6376 /* Process third byte of a triplet. */ | |
6377 if (!ADVANCE_INPUT (c, istream)) | |
6378 { | |
6379 *e++ = base64_value_to_char[value]; | |
6380 *e++ = '='; | |
6381 break; | |
6382 } | |
6383 | |
6384 *e++ = base64_value_to_char[value | (0x03 & c >> 6)]; | |
6385 *e++ = base64_value_to_char[0x3f & c]; | |
6386 } | |
6387 | |
6388 return e - to; | |
6389 } | |
6390 #undef ADVANCE_INPUT | |
6391 | |
6392 /* Get next character from the stream, except that non-base64 | |
6393 characters are ignored. This is in accordance with rfc2045. EC | |
867 | 6394 should be an Ichar, so that it can hold -1 as the value for EOF. */ |
428 | 6395 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \ |
867 | 6396 ec = Lstream_get_ichar (stream); \ |
428 | 6397 ++streampos; \ |
6398 /* IS_BASE64 may not be called with negative arguments so check for \ | |
6399 EOF first. */ \ | |
6400 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \ | |
6401 break; \ | |
6402 } while (1) | |
6403 | |
6404 #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
|
6405 pos += set_itext_ichar (pos, (Ichar)((Binbyte)(val))); \ |
428 | 6406 ++ccnt; \ |
6407 } while (0) | |
6408 | |
665 | 6409 static Bytebpos |
867 | 6410 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr) |
428 | 6411 { |
6412 Charcount ccnt = 0; | |
867 | 6413 Ibyte *e = to; |
428 | 6414 EMACS_INT streampos = 0; |
6415 | |
6416 while (1) | |
6417 { | |
867 | 6418 Ichar ec; |
428 | 6419 unsigned long value; |
6420 | |
6421 /* Process first byte of a quadruplet. */ | |
6422 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6423 if (ec < 0) | |
6424 break; | |
6425 if (ec == '=') | |
563 | 6426 base64_conversion_error ("Illegal `=' character while decoding base64", |
6427 make_int (streampos)); | |
428 | 6428 value = base64_char_to_value[ec] << 18; |
6429 | |
6430 /* Process second byte of a quadruplet. */ | |
6431 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6432 if (ec < 0) | |
563 | 6433 base64_conversion_error ("Premature EOF while decoding base64", |
6434 Qunbound); | |
428 | 6435 if (ec == '=') |
563 | 6436 base64_conversion_error ("Illegal `=' character while decoding base64", |
6437 make_int (streampos)); | |
428 | 6438 value |= base64_char_to_value[ec] << 12; |
6439 STORE_BYTE (e, value >> 16, ccnt); | |
6440 | |
6441 /* Process third byte of a quadruplet. */ | |
6442 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6443 if (ec < 0) | |
563 | 6444 base64_conversion_error ("Premature EOF while decoding base64", |
6445 Qunbound); | |
428 | 6446 |
6447 if (ec == '=') | |
6448 { | |
6449 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6450 if (ec < 0) | |
563 | 6451 base64_conversion_error ("Premature EOF while decoding base64", |
6452 Qunbound); | |
428 | 6453 if (ec != '=') |
563 | 6454 base64_conversion_error |
6455 ("Padding `=' expected but not found while decoding base64", | |
6456 make_int (streampos)); | |
428 | 6457 continue; |
6458 } | |
6459 | |
6460 value |= base64_char_to_value[ec] << 6; | |
6461 STORE_BYTE (e, 0xff & value >> 8, ccnt); | |
6462 | |
6463 /* Process fourth byte of a quadruplet. */ | |
6464 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6465 if (ec < 0) | |
563 | 6466 base64_conversion_error ("Premature EOF while decoding base64", |
6467 Qunbound); | |
428 | 6468 if (ec == '=') |
6469 continue; | |
6470 | |
6471 value |= base64_char_to_value[ec]; | |
6472 STORE_BYTE (e, 0xff & value, ccnt); | |
6473 } | |
6474 | |
6475 *ccptr = ccnt; | |
6476 return e - to; | |
6477 } | |
6478 #undef ADVANCE_INPUT | |
6479 #undef ADVANCE_INPUT_IGNORE_NONBASE64 | |
6480 #undef STORE_BYTE | |
6481 | |
6482 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /* | |
444 | 6483 Base64-encode the region between START and END. |
428 | 6484 Return the length of the encoded text. |
6485 Optional third argument NO-LINE-BREAK means do not break long lines | |
6486 into shorter lines. | |
6487 */ | |
444 | 6488 (start, end, no_line_break)) |
428 | 6489 { |
867 | 6490 Ibyte *encoded; |
665 | 6491 Bytebpos encoded_length; |
428 | 6492 Charcount allength, length; |
6493 struct buffer *buf = current_buffer; | |
665 | 6494 Charbpos begv, zv, old_pt = BUF_PT (buf); |
428 | 6495 Lisp_Object input; |
851 | 6496 int speccount = specpdl_depth (); |
428 | 6497 |
444 | 6498 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 6499 barf_if_buffer_read_only (buf, begv, zv); |
6500 | |
6501 /* We need to allocate enough room for encoding the text. | |
6502 We need 33 1/3% more space, plus a newline every 76 | |
6503 characters, and then we round up. */ | |
6504 length = zv - begv; | |
6505 allength = length + length/3 + 1; | |
6506 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
6507 | |
6508 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
867 | 6509 /* We needn't multiply allength with MAX_ICHAR_LEN because all the |
428 | 6510 base64 characters will be single-byte. */ |
867 | 6511 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 6512 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
6513 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
6514 assert (encoded_length <= allength); |
428 | 6515 Lstream_delete (XLSTREAM (input)); |
6516 | |
6517 /* Now we have encoded the region, so we insert the new contents | |
6518 and delete the old. (Insert first in order to preserve markers.) */ | |
6519 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0); | |
851 | 6520 unbind_to (speccount); |
428 | 6521 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0); |
6522 | |
6523 /* Simulate FSF Emacs implementation of this function: if point was | |
6524 in the region, place it at the beginning. */ | |
6525 if (old_pt >= begv && old_pt < zv) | |
6526 BUF_SET_PT (buf, begv); | |
6527 | |
6528 /* We return the length of the encoded text. */ | |
6529 return make_int (encoded_length); | |
6530 } | |
6531 | |
6532 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /* | |
6533 Base64 encode STRING and return the result. | |
444 | 6534 Optional argument NO-LINE-BREAK means do not break long lines |
6535 into shorter lines. | |
428 | 6536 */ |
6537 (string, no_line_break)) | |
6538 { | |
6539 Charcount allength, length; | |
665 | 6540 Bytebpos encoded_length; |
867 | 6541 Ibyte *encoded; |
428 | 6542 Lisp_Object input, result; |
6543 int speccount = specpdl_depth(); | |
6544 | |
6545 CHECK_STRING (string); | |
6546 | |
826 | 6547 length = string_char_length (string); |
428 | 6548 allength = length + length/3 + 1; |
6549 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
6550 | |
6551 input = make_lisp_string_input_stream (string, 0, -1); | |
867 | 6552 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 6553 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
6554 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
6555 assert (encoded_length <= allength); |
428 | 6556 Lstream_delete (XLSTREAM (input)); |
6557 result = make_string (encoded, encoded_length); | |
851 | 6558 unbind_to (speccount); |
428 | 6559 return result; |
6560 } | |
6561 | |
6562 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /* | |
444 | 6563 Base64-decode the region between START and END. |
428 | 6564 Return the length of the decoded text. |
6565 If the region can't be decoded, return nil and don't modify the buffer. | |
6566 Characters out of the base64 alphabet are ignored. | |
6567 */ | |
444 | 6568 (start, end)) |
428 | 6569 { |
6570 struct buffer *buf = current_buffer; | |
665 | 6571 Charbpos begv, zv, old_pt = BUF_PT (buf); |
867 | 6572 Ibyte *decoded; |
665 | 6573 Bytebpos decoded_length; |
428 | 6574 Charcount length, cc_decoded_length; |
6575 Lisp_Object input; | |
6576 int speccount = specpdl_depth(); | |
6577 | |
444 | 6578 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 6579 barf_if_buffer_read_only (buf, begv, zv); |
6580 | |
6581 length = zv - begv; | |
6582 | |
6583 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
6584 /* We need to allocate enough room for decoding the text. */ | |
867 | 6585 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 6586 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
|
6587 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 6588 Lstream_delete (XLSTREAM (input)); |
6589 | |
6590 /* Now we have decoded the region, so we insert the new contents | |
6591 and delete the old. (Insert first in order to preserve markers.) */ | |
6592 BUF_SET_PT (buf, begv); | |
6593 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0); | |
851 | 6594 unbind_to (speccount); |
428 | 6595 buffer_delete_range (buf, begv + cc_decoded_length, |
6596 zv + cc_decoded_length, 0); | |
6597 | |
6598 /* Simulate FSF Emacs implementation of this function: if point was | |
6599 in the region, place it at the beginning. */ | |
6600 if (old_pt >= begv && old_pt < zv) | |
6601 BUF_SET_PT (buf, begv); | |
6602 | |
6603 return make_int (cc_decoded_length); | |
6604 } | |
6605 | |
6606 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /* | |
6607 Base64-decode STRING and return the result. | |
6608 Characters out of the base64 alphabet are ignored. | |
6609 */ | |
6610 (string)) | |
6611 { | |
867 | 6612 Ibyte *decoded; |
665 | 6613 Bytebpos decoded_length; |
428 | 6614 Charcount length, cc_decoded_length; |
6615 Lisp_Object input, result; | |
6616 int speccount = specpdl_depth(); | |
6617 | |
6618 CHECK_STRING (string); | |
6619 | |
826 | 6620 length = string_char_length (string); |
428 | 6621 /* We need to allocate enough room for decoding the text. */ |
867 | 6622 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 6623 |
6624 input = make_lisp_string_input_stream (string, 0, -1); | |
6625 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, | |
6626 &cc_decoded_length); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
6627 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 6628 Lstream_delete (XLSTREAM (input)); |
6629 | |
6630 result = make_string (decoded, decoded_length); | |
851 | 6631 unbind_to (speccount); |
428 | 6632 return result; |
6633 } | |
6634 | |
6635 Lisp_Object Qyes_or_no_p; | |
6636 | |
6637 void | |
6638 syms_of_fns (void) | |
6639 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
6640 INIT_LISP_OBJECT (bit_vector); |
442 | 6641 |
563 | 6642 DEFSYMBOL (Qstring_lessp); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6643 DEFSYMBOL (Qsort); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6644 DEFSYMBOL (Qmerge); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6645 DEFSYMBOL (Qfill); |
563 | 6646 DEFSYMBOL (Qidentity); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6647 DEFSYMBOL (Qvector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6648 DEFSYMBOL (Qarray); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6649 DEFSYMBOL (Qstring); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6650 DEFSYMBOL (Qlist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6651 DEFSYMBOL (Qbit_vector); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6652 defsymbol (&QsortX, "sort*"); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6653 DEFSYMBOL (Qreduce); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6654 DEFSYMBOL (Qreplace); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6655 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6656 DEFSYMBOL (Qmapconcat); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6657 defsymbol (&QmapcarX, "mapcar*"); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6658 DEFSYMBOL (Qmapvector); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6659 DEFSYMBOL (Qmapcan); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6660 DEFSYMBOL (Qmapc); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6661 DEFSYMBOL (Qmap); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6662 DEFSYMBOL (Qmap_into); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6663 DEFSYMBOL (Qsome); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6664 DEFSYMBOL (Qevery); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6665 DEFSYMBOL (Qmaplist); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6666 DEFSYMBOL (Qmapl); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6667 DEFSYMBOL (Qmapcon); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6668 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6669 DEFKEYWORD (Q_from_end); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6670 DEFKEYWORD (Q_initial_value); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6671 DEFKEYWORD (Q_start1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6672 DEFKEYWORD (Q_start2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6673 DEFKEYWORD (Q_end1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6674 DEFKEYWORD (Q_end2); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6675 |
563 | 6676 DEFSYMBOL (Qyes_or_no_p); |
6677 | |
6678 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error); | |
428 | 6679 |
6680 DEFSUBR (Fidentity); | |
6681 DEFSUBR (Frandom); | |
6682 DEFSUBR (Flength); | |
6683 DEFSUBR (Fsafe_length); | |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
6684 DEFSUBR (Flist_length); |
428 | 6685 DEFSUBR (Fstring_equal); |
801 | 6686 DEFSUBR (Fcompare_strings); |
428 | 6687 DEFSUBR (Fstring_lessp); |
6688 DEFSUBR (Fstring_modified_tick); | |
6689 DEFSUBR (Fappend); | |
6690 DEFSUBR (Fconcat); | |
6691 DEFSUBR (Fvconcat); | |
6692 DEFSUBR (Fbvconcat); | |
6693 DEFSUBR (Fcopy_list); | |
6694 DEFSUBR (Fcopy_sequence); | |
6695 DEFSUBR (Fcopy_alist); | |
6696 DEFSUBR (Fcopy_tree); | |
6697 DEFSUBR (Fsubseq); | |
6698 DEFSUBR (Fnthcdr); | |
6699 DEFSUBR (Fnth); | |
6700 DEFSUBR (Felt); | |
6701 DEFSUBR (Flast); | |
6702 DEFSUBR (Fbutlast); | |
6703 DEFSUBR (Fnbutlast); | |
6704 DEFSUBR (Fmember); | |
6705 DEFSUBR (Fold_member); | |
6706 DEFSUBR (Fmemq); | |
6707 DEFSUBR (Fold_memq); | |
6708 DEFSUBR (Fassoc); | |
6709 DEFSUBR (Fold_assoc); | |
6710 DEFSUBR (Fassq); | |
6711 DEFSUBR (Fold_assq); | |
6712 DEFSUBR (Frassoc); | |
6713 DEFSUBR (Fold_rassoc); | |
6714 DEFSUBR (Frassq); | |
6715 DEFSUBR (Fold_rassq); | |
6716 DEFSUBR (Fdelete); | |
6717 DEFSUBR (Fold_delete); | |
6718 DEFSUBR (Fdelq); | |
6719 DEFSUBR (Fold_delq); | |
6720 DEFSUBR (Fremassoc); | |
6721 DEFSUBR (Fremassq); | |
6722 DEFSUBR (Fremrassoc); | |
6723 DEFSUBR (Fremrassq); | |
6724 DEFSUBR (Fnreverse); | |
6725 DEFSUBR (Freverse); | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6726 DEFSUBR (FsortX); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6727 Ffset (intern ("sort"), QsortX); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6728 DEFSUBR (Fmerge); |
428 | 6729 DEFSUBR (Fplists_eq); |
6730 DEFSUBR (Fplists_equal); | |
6731 DEFSUBR (Flax_plists_eq); | |
6732 DEFSUBR (Flax_plists_equal); | |
6733 DEFSUBR (Fplist_get); | |
6734 DEFSUBR (Fplist_put); | |
6735 DEFSUBR (Fplist_remprop); | |
6736 DEFSUBR (Fplist_member); | |
6737 DEFSUBR (Fcheck_valid_plist); | |
6738 DEFSUBR (Fvalid_plist_p); | |
6739 DEFSUBR (Fcanonicalize_plist); | |
6740 DEFSUBR (Flax_plist_get); | |
6741 DEFSUBR (Flax_plist_put); | |
6742 DEFSUBR (Flax_plist_remprop); | |
6743 DEFSUBR (Flax_plist_member); | |
6744 DEFSUBR (Fcanonicalize_lax_plist); | |
6745 DEFSUBR (Fdestructive_alist_to_plist); | |
6746 DEFSUBR (Fget); | |
6747 DEFSUBR (Fput); | |
6748 DEFSUBR (Fremprop); | |
6749 DEFSUBR (Fobject_plist); | |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
6750 DEFSUBR (Fobject_setplist); |
428 | 6751 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
|
6752 DEFSUBR (Fequalp); |
428 | 6753 DEFSUBR (Fold_equal); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6754 DEFSUBR (Ffill); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6755 Ffset (intern ("fillarray"), Qfill); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6756 |
428 | 6757 DEFSUBR (Fnconc); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6758 DEFSUBR (FmapcarX); |
428 | 6759 DEFSUBR (Fmapvector); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6760 DEFSUBR (Fmapcan); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6761 DEFSUBR (Fmapc); |
428 | 6762 DEFSUBR (Fmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6763 DEFSUBR (Fmap); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6764 DEFSUBR (Fmap_into); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
6765 DEFSUBR (Fsome); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
6766 DEFSUBR (Fevery); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6767 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
|
6768 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
|
6769 DEFSUBR (Fmaplist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6770 DEFSUBR (Fmapl); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6771 DEFSUBR (Fmapcon); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6772 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6773 DEFSUBR (Freduce); |
442 | 6774 DEFSUBR (Freplace_list); |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6775 DEFSUBR (Freplace); |
428 | 6776 DEFSUBR (Fload_average); |
6777 DEFSUBR (Ffeaturep); | |
6778 DEFSUBR (Frequire); | |
6779 DEFSUBR (Fprovide); | |
6780 DEFSUBR (Fbase64_encode_region); | |
6781 DEFSUBR (Fbase64_encode_string); | |
6782 DEFSUBR (Fbase64_decode_region); | |
6783 DEFSUBR (Fbase64_decode_string); | |
771 | 6784 |
5224
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
6785 DEFSUBR (Fsubstring_no_properties); |
771 | 6786 DEFSUBR (Fsplit_string_by_char); |
6787 DEFSUBR (Fsplit_path); /* #### */ | |
6788 } | |
6789 | |
6790 void | |
6791 vars_of_fns (void) | |
6792 { | |
6793 DEFVAR_LISP ("path-separator", &Vpath_separator /* | |
6794 The directory separator in search paths, as a string. | |
6795 */ ); | |
6796 { | |
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
|
6797 Ascbyte c = SEPCHAR; |
867 | 6798 Vpath_separator = make_string ((Ibyte *) &c, 1); |
771 | 6799 } |
428 | 6800 } |
6801 | |
6802 void | |
6803 init_provide_once (void) | |
6804 { | |
6805 DEFVAR_LISP ("features", &Vfeatures /* | |
6806 A list of symbols which are the features of the executing emacs. | |
6807 Used by `featurep' and `require', and altered by `provide'. | |
6808 */ ); | |
6809 Vfeatures = Qnil; | |
6810 | |
6811 Fprovide (intern ("base64")); | |
6812 } |