Mercurial > hg > xemacs-beta
annotate src/fns.c @ 5299:28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
src/ChangeLog addition:
2010-11-06 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (Flist_length): Error if LIST is dotted in this function;
document this behaviour.
tests/ChangeLog addition:
2010-11-06 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el (malformed-list): Check that #'mapcar,
#'map and #'list-length throw this error when appropriate.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 06 Nov 2010 14:51:13 +0000 |
parents | 99de5fd48e87 |
children | 9f738305f80f |
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. |
5299
28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
Aidan Kehoe <kehoea@parhasard.net>
parents:
5285
diff
changeset
|
348 Error if LIST is dotted. |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
349 */ |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
350 (list)) |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
351 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
352 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
|
353 Elemcount len; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
354 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
359 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
|
360 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
|
361 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
362 |
5299
28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
Aidan Kehoe <kehoea@parhasard.net>
parents:
5285
diff
changeset
|
363 if (!LISTP (hare)) |
28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
Aidan Kehoe <kehoea@parhasard.net>
parents:
5285
diff
changeset
|
364 { |
28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
Aidan Kehoe <kehoea@parhasard.net>
parents:
5285
diff
changeset
|
365 signal_malformed_list_error (list); |
28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
Aidan Kehoe <kehoea@parhasard.net>
parents:
5285
diff
changeset
|
366 } |
28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
Aidan Kehoe <kehoea@parhasard.net>
parents:
5285
diff
changeset
|
367 |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
368 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
|
369 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
370 |
428 | 371 /*** string functions. ***/ |
372 | |
373 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /* | |
374 Return t if two strings have identical contents. | |
375 Case is significant. Text properties are ignored. | |
376 \(Under XEmacs, `equal' also ignores text properties and extents in | |
377 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20 | |
378 `equal' is the same as in XEmacs, in that respect.) | |
379 Symbols are also allowed; their print names are used instead. | |
380 */ | |
444 | 381 (string1, string2)) |
428 | 382 { |
383 Bytecount len; | |
793 | 384 Lisp_Object p1, p2; |
428 | 385 |
444 | 386 if (SYMBOLP (string1)) |
387 p1 = XSYMBOL (string1)->name; | |
428 | 388 else |
389 { | |
444 | 390 CHECK_STRING (string1); |
793 | 391 p1 = string1; |
428 | 392 } |
393 | |
444 | 394 if (SYMBOLP (string2)) |
395 p2 = XSYMBOL (string2)->name; | |
428 | 396 else |
397 { | |
444 | 398 CHECK_STRING (string2); |
793 | 399 p2 = string2; |
428 | 400 } |
401 | |
793 | 402 return (((len = XSTRING_LENGTH (p1)) == XSTRING_LENGTH (p2)) && |
403 !memcmp (XSTRING_DATA (p1), XSTRING_DATA (p2), len)) ? Qt : Qnil; | |
428 | 404 } |
405 | |
801 | 406 DEFUN ("compare-strings", Fcompare_strings, 6, 7, 0, /* |
407 Compare the contents of two strings, maybe ignoring case. | |
408 In string STR1, skip the first START1 characters and stop at END1. | |
409 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
|
410 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
|
411 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
|
412 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
|
413 |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
414 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
|
415 Case is significant by default. |
801 | 416 |
417 The value is t if the strings (or specified portions) match. | |
418 If string STR1 is less, the value is a negative number N; | |
419 - 1 - N is the number of characters that match at the beginning. | |
420 If string STR1 is greater, the value is a positive number N; | |
421 N - 1 is the number of characters that match at the beginning. | |
422 */ | |
423 (str1, start1, end1, str2, start2, end2, ignore_case)) | |
424 { | |
425 Charcount ccstart1, ccend1, ccstart2, ccend2; | |
426 Bytecount bstart1, blen1, bstart2, blen2; | |
427 Charcount matching; | |
428 int res; | |
429 | |
430 CHECK_STRING (str1); | |
431 CHECK_STRING (str2); | |
432 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
|
433 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 434 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
|
435 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 436 |
437 bstart1 = string_index_char_to_byte (str1, ccstart1); | |
438 blen1 = string_offset_char_to_byte_len (str1, bstart1, ccend1 - ccstart1); | |
439 bstart2 = string_index_char_to_byte (str2, ccstart2); | |
440 blen2 = string_offset_char_to_byte_len (str2, bstart2, ccend2 - ccstart2); | |
441 | |
442 res = ((NILP (ignore_case) ? qxetextcmp_matching : qxetextcasecmp_matching) | |
443 (XSTRING_DATA (str1) + bstart1, blen1, | |
444 XSTRING_DATA (str2) + bstart2, blen2, | |
445 &matching)); | |
446 | |
447 if (!res) | |
448 return Qt; | |
449 else if (res > 0) | |
450 return make_int (1 + matching); | |
451 else | |
452 return make_int (-1 - matching); | |
453 } | |
454 | |
428 | 455 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /* |
456 Return t if first arg string is less than second in lexicographic order. | |
771 | 457 Comparison is simply done on a character-by-character basis using the |
458 numeric value of a character. (Note that this may not produce | |
459 particularly meaningful results under Mule if characters from | |
460 different charsets are being compared.) | |
428 | 461 |
462 Symbols are also allowed; their print names are used instead. | |
463 | |
771 | 464 Currently we don't do proper language-specific collation or handle |
465 multiple character sets. This may be changed when Unicode support | |
466 is implemented. | |
428 | 467 */ |
444 | 468 (string1, string2)) |
428 | 469 { |
793 | 470 Lisp_Object p1, p2; |
428 | 471 Charcount end, len2; |
472 int i; | |
473 | |
444 | 474 if (SYMBOLP (string1)) |
475 p1 = XSYMBOL (string1)->name; | |
793 | 476 else |
477 { | |
444 | 478 CHECK_STRING (string1); |
793 | 479 p1 = string1; |
428 | 480 } |
481 | |
444 | 482 if (SYMBOLP (string2)) |
483 p2 = XSYMBOL (string2)->name; | |
428 | 484 else |
485 { | |
444 | 486 CHECK_STRING (string2); |
793 | 487 p2 = string2; |
428 | 488 } |
489 | |
826 | 490 end = string_char_length (p1); |
491 len2 = string_char_length (p2); | |
428 | 492 if (end > len2) |
493 end = len2; | |
494 | |
495 { | |
867 | 496 Ibyte *ptr1 = XSTRING_DATA (p1); |
497 Ibyte *ptr2 = XSTRING_DATA (p2); | |
428 | 498 |
499 /* #### It is not really necessary to do this: We could compare | |
500 byte-by-byte and still get a reasonable comparison, since this | |
501 would compare characters with a charset in the same way. With | |
502 a little rearrangement of the leading bytes, we could make most | |
503 inter-charset comparisons work out the same, too; even if some | |
504 don't, this is not a big deal because inter-charset comparisons | |
505 aren't really well-defined anyway. */ | |
506 for (i = 0; i < end; i++) | |
507 { | |
867 | 508 if (itext_ichar (ptr1) != itext_ichar (ptr2)) |
509 return itext_ichar (ptr1) < itext_ichar (ptr2) ? Qt : Qnil; | |
510 INC_IBYTEPTR (ptr1); | |
511 INC_IBYTEPTR (ptr2); | |
428 | 512 } |
513 } | |
514 /* Can't do i < len2 because then comparison between "foo" and "foo^@" | |
515 won't work right in I18N2 case */ | |
516 return end < len2 ? Qt : Qnil; | |
517 } | |
518 | |
519 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /* | |
520 Return STRING's tick counter, incremented for each change to the string. | |
521 Each string has a tick counter which is incremented each time the contents | |
522 of the string are changed (e.g. with `aset'). It wraps around occasionally. | |
523 */ | |
524 (string)) | |
525 { | |
526 CHECK_STRING (string); | |
793 | 527 if (CONSP (XSTRING_PLIST (string)) && INTP (XCAR (XSTRING_PLIST (string)))) |
528 return XCAR (XSTRING_PLIST (string)); | |
428 | 529 else |
530 return Qzero; | |
531 } | |
532 | |
533 void | |
534 bump_string_modiff (Lisp_Object str) | |
535 { | |
793 | 536 Lisp_Object *ptr = &XSTRING_PLIST (str); |
428 | 537 |
538 #ifdef I18N3 | |
539 /* #### remove the `string-translatable' property from the string, | |
540 if there is one. */ | |
541 #endif | |
542 /* skip over extent info if it's there */ | |
543 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
544 ptr = &XCDR (*ptr); | |
545 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
793 | 546 XCAR (*ptr) = make_int (1+XINT (XCAR (*ptr))); |
428 | 547 else |
548 *ptr = Fcons (make_int (1), *ptr); | |
549 } | |
550 | |
551 | |
552 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector }; | |
553 static Lisp_Object concat (int nargs, Lisp_Object *args, | |
554 enum concat_target_type target_type, | |
555 int last_special); | |
556 | |
557 Lisp_Object | |
444 | 558 concat2 (Lisp_Object string1, Lisp_Object string2) |
428 | 559 { |
560 Lisp_Object args[2]; | |
444 | 561 args[0] = string1; |
562 args[1] = string2; | |
428 | 563 return concat (2, args, c_string, 0); |
564 } | |
565 | |
566 Lisp_Object | |
444 | 567 concat3 (Lisp_Object string1, Lisp_Object string2, Lisp_Object string3) |
428 | 568 { |
569 Lisp_Object args[3]; | |
444 | 570 args[0] = string1; |
571 args[1] = string2; | |
572 args[2] = string3; | |
428 | 573 return concat (3, args, c_string, 0); |
574 } | |
575 | |
576 Lisp_Object | |
444 | 577 vconcat2 (Lisp_Object vec1, Lisp_Object vec2) |
428 | 578 { |
579 Lisp_Object args[2]; | |
444 | 580 args[0] = vec1; |
581 args[1] = vec2; | |
428 | 582 return concat (2, args, c_vector, 0); |
583 } | |
584 | |
585 Lisp_Object | |
444 | 586 vconcat3 (Lisp_Object vec1, Lisp_Object vec2, Lisp_Object vec3) |
428 | 587 { |
588 Lisp_Object args[3]; | |
444 | 589 args[0] = vec1; |
590 args[1] = vec2; | |
591 args[2] = vec3; | |
428 | 592 return concat (3, args, c_vector, 0); |
593 } | |
594 | |
595 DEFUN ("append", Fappend, 0, MANY, 0, /* | |
596 Concatenate all the arguments and make the result a list. | |
597 The result is a list whose elements are the elements of all the arguments. | |
598 Each argument may be a list, vector, bit vector, or string. | |
599 The last argument is not copied, just used as the tail of the new list. | |
600 Also see: `nconc'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
601 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
602 arguments: (&rest ARGS) |
428 | 603 */ |
604 (int nargs, Lisp_Object *args)) | |
605 { | |
606 return concat (nargs, args, c_cons, 1); | |
607 } | |
608 | |
609 DEFUN ("concat", Fconcat, 0, MANY, 0, /* | |
610 Concatenate all the arguments and make the result a string. | |
611 The result is a string whose elements are the elements of all the arguments. | |
612 Each argument may be a string or a list or vector of characters. | |
613 | |
614 As of XEmacs 21.0, this function does NOT accept individual integers | |
615 as arguments. Old code that relies on, for example, (concat "foo" 50) | |
616 returning "foo50" will fail. To fix such code, either apply | |
617 `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
|
618 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
619 arguments: (&rest ARGS) |
428 | 620 */ |
621 (int nargs, Lisp_Object *args)) | |
622 { | |
623 return concat (nargs, args, c_string, 0); | |
624 } | |
625 | |
626 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /* | |
627 Concatenate all the arguments and make the result a vector. | |
628 The result is a vector whose elements are the elements of all the arguments. | |
629 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
|
630 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
631 arguments: (&rest ARGS) |
428 | 632 */ |
633 (int nargs, Lisp_Object *args)) | |
634 { | |
635 return concat (nargs, args, c_vector, 0); | |
636 } | |
637 | |
638 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /* | |
639 Concatenate all the arguments and make the result a bit vector. | |
640 The result is a bit vector whose elements are the elements of all the | |
641 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
|
642 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
643 arguments: (&rest ARGS) |
428 | 644 */ |
645 (int nargs, Lisp_Object *args)) | |
646 { | |
647 return concat (nargs, args, c_bit_vector, 0); | |
648 } | |
649 | |
650 /* Copy a (possibly dotted) list. LIST must be a cons. | |
651 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */ | |
652 static Lisp_Object | |
653 copy_list (Lisp_Object list) | |
654 { | |
655 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list)); | |
656 Lisp_Object last = list_copy; | |
657 Lisp_Object hare, tortoise; | |
665 | 658 Elemcount len; |
428 | 659 |
660 for (tortoise = hare = XCDR (list), len = 1; | |
661 CONSP (hare); | |
662 hare = XCDR (hare), len++) | |
663 { | |
664 XCDR (last) = Fcons (XCAR (hare), XCDR (hare)); | |
665 last = XCDR (last); | |
666 | |
667 if (len < CIRCULAR_LIST_SUSPICION_LENGTH) | |
668 continue; | |
669 if (len & 1) | |
670 tortoise = XCDR (tortoise); | |
671 if (EQ (tortoise, hare)) | |
672 signal_circular_list_error (list); | |
673 } | |
674 | |
675 return list_copy; | |
676 } | |
677 | |
678 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /* | |
679 Return a copy of list LIST, which may be a dotted list. | |
680 The elements of LIST are not copied; they are shared | |
681 with the original. | |
682 */ | |
683 (list)) | |
684 { | |
685 again: | |
686 if (NILP (list)) return list; | |
687 if (CONSP (list)) return copy_list (list); | |
688 | |
689 list = wrong_type_argument (Qlistp, list); | |
690 goto again; | |
691 } | |
692 | |
693 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /* | |
694 Return a copy of list, vector, bit vector or string SEQUENCE. | |
695 The elements of a list or vector are not copied; they are shared | |
696 with the original. SEQUENCE may be a dotted list. | |
697 */ | |
698 (sequence)) | |
699 { | |
700 again: | |
701 if (NILP (sequence)) return sequence; | |
702 if (CONSP (sequence)) return copy_list (sequence); | |
703 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0); | |
704 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0); | |
705 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0); | |
706 | |
707 check_losing_bytecode ("copy-sequence", sequence); | |
708 sequence = wrong_type_argument (Qsequencep, sequence); | |
709 goto again; | |
710 } | |
711 | |
712 struct merge_string_extents_struct | |
713 { | |
714 Lisp_Object string; | |
715 Bytecount entry_offset; | |
716 Bytecount entry_length; | |
717 }; | |
718 | |
719 static Lisp_Object | |
720 concat (int nargs, Lisp_Object *args, | |
721 enum concat_target_type target_type, | |
722 int last_special) | |
723 { | |
724 Lisp_Object val; | |
725 Lisp_Object tail = Qnil; | |
726 int toindex; | |
727 int argnum; | |
728 Lisp_Object last_tail; | |
729 Lisp_Object prev; | |
730 struct merge_string_extents_struct *args_mse = 0; | |
867 | 731 Ibyte *string_result = 0; |
732 Ibyte *string_result_ptr = 0; | |
428 | 733 struct gcpro gcpro1; |
851 | 734 int sdep = specpdl_depth (); |
428 | 735 |
736 /* The modus operandi in Emacs is "caller gc-protects args". | |
737 However, concat is called many times in Emacs on freshly | |
738 created stuff. So we help those callers out by protecting | |
739 the args ourselves to save them a lot of temporary-variable | |
740 grief. */ | |
741 | |
742 GCPRO1 (args[0]); | |
743 gcpro1.nvars = nargs; | |
744 | |
745 #ifdef I18N3 | |
746 /* #### if the result is a string and any of the strings have a string | |
747 for the `string-translatable' property, then concat should also | |
748 concat the args but use the `string-translatable' strings, and store | |
749 the result in the returned string's `string-translatable' property. */ | |
750 #endif | |
751 if (target_type == c_string) | |
752 args_mse = alloca_array (struct merge_string_extents_struct, nargs); | |
753 | |
754 /* In append, the last arg isn't treated like the others */ | |
755 if (last_special && nargs > 0) | |
756 { | |
757 nargs--; | |
758 last_tail = args[nargs]; | |
759 } | |
760 else | |
761 last_tail = Qnil; | |
762 | |
763 /* Check and coerce the arguments. */ | |
764 for (argnum = 0; argnum < nargs; argnum++) | |
765 { | |
766 Lisp_Object seq = args[argnum]; | |
767 if (LISTP (seq)) | |
768 ; | |
769 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq)) | |
770 ; | |
771 #ifdef LOSING_BYTECODE | |
772 else if (COMPILED_FUNCTIONP (seq)) | |
773 /* Urk! We allow this, for "compatibility"... */ | |
774 ; | |
775 #endif | |
776 #if 0 /* removed for XEmacs 21 */ | |
777 else if (INTP (seq)) | |
778 /* This is too revolting to think about but maintains | |
779 compatibility with FSF (and lots and lots of old code). */ | |
780 args[argnum] = Fnumber_to_string (seq); | |
781 #endif | |
782 else | |
783 { | |
784 check_losing_bytecode ("concat", seq); | |
785 args[argnum] = wrong_type_argument (Qsequencep, seq); | |
786 } | |
787 | |
788 if (args_mse) | |
789 { | |
790 if (STRINGP (seq)) | |
791 args_mse[argnum].string = seq; | |
792 else | |
793 args_mse[argnum].string = Qnil; | |
794 } | |
795 } | |
796 | |
797 { | |
798 /* Charcount is a misnomer here as we might be dealing with the | |
799 length of a vector or list, but emphasizes that we're not dealing | |
800 with Bytecounts in strings */ | |
801 Charcount total_length; | |
802 | |
803 for (argnum = 0, total_length = 0; argnum < nargs; argnum++) | |
804 { | |
805 #ifdef LOSING_BYTECODE | |
806 Charcount thislen = length_with_bytecode_hack (args[argnum]); | |
807 #else | |
808 Charcount thislen = XINT (Flength (args[argnum])); | |
809 #endif | |
810 total_length += thislen; | |
811 } | |
812 | |
813 switch (target_type) | |
814 { | |
815 case c_cons: | |
816 if (total_length == 0) | |
851 | 817 { |
818 unbind_to (sdep); | |
819 /* In append, if all but last arg are nil, return last arg */ | |
820 RETURN_UNGCPRO (last_tail); | |
821 } | |
428 | 822 val = Fmake_list (make_int (total_length), Qnil); |
823 break; | |
824 case c_vector: | |
825 val = make_vector (total_length, Qnil); | |
826 break; | |
827 case c_bit_vector: | |
828 val = make_bit_vector (total_length, Qzero); | |
829 break; | |
830 case c_string: | |
831 /* We don't make the string yet because we don't know the | |
832 actual number of bytes. This loop was formerly written | |
833 to call Fmake_string() here and then call set_string_char() | |
834 for each char. This seems logical enough but is waaaaaaaay | |
835 slow -- set_string_char() has to scan the whole string up | |
836 to the place where the substitution is called for in order | |
837 to find the place to change, and may have to do some | |
838 realloc()ing in order to make the char fit properly. | |
839 O(N^2) yuckage. */ | |
840 val = Qnil; | |
851 | 841 string_result = |
867 | 842 (Ibyte *) MALLOC_OR_ALLOCA (total_length * MAX_ICHAR_LEN); |
428 | 843 string_result_ptr = string_result; |
844 break; | |
845 default: | |
442 | 846 val = Qnil; |
2500 | 847 ABORT (); |
428 | 848 } |
849 } | |
850 | |
851 | |
852 if (CONSP (val)) | |
853 tail = val, toindex = -1; /* -1 in toindex is flag we are | |
854 making a list */ | |
855 else | |
856 toindex = 0; | |
857 | |
858 prev = Qnil; | |
859 | |
860 for (argnum = 0; argnum < nargs; argnum++) | |
861 { | |
862 Charcount thisleni = 0; | |
863 Charcount thisindex = 0; | |
864 Lisp_Object seq = args[argnum]; | |
867 | 865 Ibyte *string_source_ptr = 0; |
866 Ibyte *string_prev_result_ptr = string_result_ptr; | |
428 | 867 |
868 if (!CONSP (seq)) | |
869 { | |
870 #ifdef LOSING_BYTECODE | |
871 thisleni = length_with_bytecode_hack (seq); | |
872 #else | |
873 thisleni = XINT (Flength (seq)); | |
874 #endif | |
875 } | |
876 if (STRINGP (seq)) | |
877 string_source_ptr = XSTRING_DATA (seq); | |
878 | |
879 while (1) | |
880 { | |
881 Lisp_Object elt; | |
882 | |
883 /* We've come to the end of this arg, so exit. */ | |
884 if (NILP (seq)) | |
885 break; | |
886 | |
887 /* Fetch next element of `seq' arg into `elt' */ | |
888 if (CONSP (seq)) | |
889 { | |
890 elt = XCAR (seq); | |
891 seq = XCDR (seq); | |
892 } | |
893 else | |
894 { | |
895 if (thisindex >= thisleni) | |
896 break; | |
897 | |
898 if (STRINGP (seq)) | |
899 { | |
867 | 900 elt = make_char (itext_ichar (string_source_ptr)); |
901 INC_IBYTEPTR (string_source_ptr); | |
428 | 902 } |
903 else if (VECTORP (seq)) | |
904 elt = XVECTOR_DATA (seq)[thisindex]; | |
905 else if (BIT_VECTORP (seq)) | |
906 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq), | |
907 thisindex)); | |
908 else | |
909 elt = Felt (seq, make_int (thisindex)); | |
910 thisindex++; | |
911 } | |
912 | |
913 /* Store into result */ | |
914 if (toindex < 0) | |
915 { | |
916 /* toindex negative means we are making a list */ | |
917 XCAR (tail) = elt; | |
918 prev = tail; | |
919 tail = XCDR (tail); | |
920 } | |
921 else if (VECTORP (val)) | |
922 XVECTOR_DATA (val)[toindex++] = elt; | |
923 else if (BIT_VECTORP (val)) | |
924 { | |
925 CHECK_BIT (elt); | |
926 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt)); | |
927 } | |
928 else | |
929 { | |
930 CHECK_CHAR_COERCE_INT (elt); | |
867 | 931 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
|
932 XCHAR (elt)); |
428 | 933 } |
934 } | |
935 if (args_mse) | |
936 { | |
937 args_mse[argnum].entry_offset = | |
938 string_prev_result_ptr - string_result; | |
939 args_mse[argnum].entry_length = | |
940 string_result_ptr - string_prev_result_ptr; | |
941 } | |
942 } | |
943 | |
944 /* Now we finally make the string. */ | |
945 if (target_type == c_string) | |
946 { | |
947 val = make_string (string_result, string_result_ptr - string_result); | |
948 for (argnum = 0; argnum < nargs; argnum++) | |
949 { | |
950 if (STRINGP (args_mse[argnum].string)) | |
951 copy_string_extents (val, args_mse[argnum].string, | |
952 args_mse[argnum].entry_offset, 0, | |
953 args_mse[argnum].entry_length); | |
954 } | |
955 } | |
956 | |
957 if (!NILP (prev)) | |
958 XCDR (prev) = last_tail; | |
959 | |
851 | 960 unbind_to (sdep); |
428 | 961 RETURN_UNGCPRO (val); |
962 } | |
963 | |
964 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /* | |
965 Return a copy of ALIST. | |
966 This is an alist which represents the same mapping from objects to objects, | |
967 but does not share the alist structure with ALIST. | |
968 The objects mapped (cars and cdrs of elements of the alist) | |
969 are shared, however. | |
970 Elements of ALIST that are not conses are also shared. | |
971 */ | |
972 (alist)) | |
973 { | |
974 Lisp_Object tail; | |
975 | |
976 if (NILP (alist)) | |
977 return alist; | |
978 CHECK_CONS (alist); | |
979 | |
980 alist = concat (1, &alist, c_cons, 0); | |
981 for (tail = alist; CONSP (tail); tail = XCDR (tail)) | |
982 { | |
983 Lisp_Object car = XCAR (tail); | |
984 | |
985 if (CONSP (car)) | |
986 XCAR (tail) = Fcons (XCAR (car), XCDR (car)); | |
987 } | |
988 return alist; | |
989 } | |
990 | |
991 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /* | |
992 Return a copy of a list and substructures. | |
993 The argument is copied, and any lists contained within it are copied | |
994 recursively. Circularities and shared substructures are not preserved. | |
995 Second arg VECP causes vectors to be copied, too. Strings and bit vectors | |
996 are not copied. | |
997 */ | |
998 (arg, vecp)) | |
999 { | |
454 | 1000 return safe_copy_tree (arg, vecp, 0); |
1001 } | |
1002 | |
1003 Lisp_Object | |
1004 safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth) | |
1005 { | |
1006 if (depth > 200) | |
563 | 1007 stack_overflow ("Stack overflow in copy-tree", arg); |
454 | 1008 |
428 | 1009 if (CONSP (arg)) |
1010 { | |
1011 Lisp_Object rest; | |
1012 rest = arg = Fcopy_sequence (arg); | |
1013 while (CONSP (rest)) | |
1014 { | |
1015 Lisp_Object elt = XCAR (rest); | |
1016 QUIT; | |
1017 if (CONSP (elt) || VECTORP (elt)) | |
454 | 1018 XCAR (rest) = safe_copy_tree (elt, vecp, depth + 1); |
428 | 1019 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */ |
454 | 1020 XCDR (rest) = safe_copy_tree (XCDR (rest), vecp, depth +1); |
428 | 1021 rest = XCDR (rest); |
1022 } | |
1023 } | |
1024 else if (VECTORP (arg) && ! NILP (vecp)) | |
1025 { | |
1026 int i = XVECTOR_LENGTH (arg); | |
1027 int j; | |
1028 arg = Fcopy_sequence (arg); | |
1029 for (j = 0; j < i; j++) | |
1030 { | |
1031 Lisp_Object elt = XVECTOR_DATA (arg) [j]; | |
1032 QUIT; | |
1033 if (CONSP (elt) || VECTORP (elt)) | |
454 | 1034 XVECTOR_DATA (arg) [j] = safe_copy_tree (elt, vecp, depth + 1); |
428 | 1035 } |
1036 } | |
1037 return arg; | |
1038 } | |
1039 | |
1040 DEFUN ("subseq", Fsubseq, 2, 3, 0, /* | |
442 | 1041 Return the subsequence of SEQUENCE starting at START and ending before END. |
1042 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
|
1043 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1044 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
|
1045 Common Lisp. |
442 | 1046 The returned subsequence is always of the same type as SEQUENCE. |
1047 If SEQUENCE is a string, relevant parts of the string-extent-data | |
1048 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
|
1049 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1050 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
|
1051 not copy extent data. |
428 | 1052 */ |
442 | 1053 (sequence, start, end)) |
428 | 1054 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1055 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
|
1056 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
|
1057 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1058 CHECK_SEQUENCE (sequence); |
442 | 1059 CHECK_INT (start); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1060 ss = XINT (start); |
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 (!NILP (end)) |
428 | 1063 { |
442 | 1064 CHECK_INT (end); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1065 ee = XINT (end); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1066 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1067 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1068 if (STRINGP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1069 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1070 Bytecount bstart, blen; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1071 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1072 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
|
1073 GB_HISTORICAL_STRING_BEHAVIOR); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1074 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
|
1075 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
|
1076 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1077 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
|
1078 /* 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
|
1079 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
|
1080 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1081 else if (CONSP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1082 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1083 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
|
1084 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1085 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
|
1086 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1087 len = XINT (Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1088 if (ss < 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 ss = len + ss; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1091 start = make_integer (ss); |
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 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1094 if (ee < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1095 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1096 ee = len + ee; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1097 end = make_integer (ee); |
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 else |
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 ee = min (ee, len); |
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 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1105 if (0 != ss) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1106 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1107 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
|
1108 } |
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 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
|
1111 { |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
1112 result = result_tail = Fcons (Fcar (sequence), Qnil); |
442 | 1113 sequence = Fcdr (sequence); |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1114 ii = ss + 1; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1115 |
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 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
|
1118 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1119 if (!(ii < ee)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1120 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1121 break; |
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 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
|
1125 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
|
1126 ii++; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1127 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1128 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1129 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1130 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1131 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
|
1132 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1133 /* 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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 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
|
1139 } |
442 | 1140 } |
1141 else | |
1142 { | |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1143 len = XINT (Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1144 if (ss < 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 ss = len + ss; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1147 start = make_integer (ss); |
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 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1150 if (ee < 0) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1151 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1152 ee = len + ee; |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1153 end = make_integer (ee); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1154 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1155 else |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1156 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1157 ee = min (len, ee); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1158 } |
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 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
|
1161 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1162 if (VECTORP (sequence)) |
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 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
|
1165 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1166 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
|
1167 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1168 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
|
1169 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1170 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
|
1171 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1172 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
|
1173 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
|
1174 } |
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 else if (NILP (sequence)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1177 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1178 DO_NOTHING; |
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 else |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1181 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1182 /* 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
|
1183 ABORT (); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1184 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1185 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1186 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
1187 return result; |
428 | 1188 } |
1189 | |
5224
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1195 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
|
1196 */ |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1197 (string, start, end)) |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1198 { |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1199 Charcount ccstart, ccend; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1200 Bytecount bstart, blen; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1201 Lisp_Object val; |
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 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
|
1204 GB_HISTORICAL_STRING_BEHAVIOR); |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1205 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
|
1206 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
|
1207 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
|
1208 |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1209 return val; |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1210 } |
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
1211 |
771 | 1212 /* 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
|
1213 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
|
1214 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1215 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
|
1216 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
|
1217 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
|
1218 |
771 | 1219 static Lisp_Object |
867 | 1220 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
|
1221 Ichar sepchar, int unescape, Ichar escapechar) |
771 | 1222 { |
1223 Lisp_Object result = Qnil; | |
867 | 1224 const Ibyte *end = string + size; |
771 | 1225 |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1226 if (unescape) |
771 | 1227 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1228 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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
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 (1) |
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 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
|
1238 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
|
1239 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
|
1240 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1241 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
|
1242 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1243 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
|
1244 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1245 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
|
1246 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1247 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
|
1248 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1249 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1250 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1251 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1252 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
|
1253 /* 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
|
1254 && !previous_escaped) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1255 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1256 ++deleting_escapes; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1257 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
|
1258 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1259 else |
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 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
|
1262 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1263 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1264 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
|
1265 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1266 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1267 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
|
1268 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1269 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
|
1270 > 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
|
1271 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1272 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
|
1273 ((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
|
1274 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
|
1275 } |
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 cursor = string; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1278 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
|
1279 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
|
1280 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1281 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
|
1282 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1283 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
|
1284 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1285 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
|
1286 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1287 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
|
1288 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
|
1289 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
|
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 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
|
1293 && (pchar == escapechar); |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1294 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1295 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
|
1296 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1297 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1298 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
|
1299 unescape_cursor |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1300 - 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
|
1301 result); |
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 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1304 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1305 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
|
1306 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1307 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
|
1308 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1309 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1310 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
|
1311 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1312 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1313 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1314 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1315 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1316 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1317 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1318 while (1) |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1319 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1320 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
|
1321 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
|
1322 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1323 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
|
1324 break; |
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 (p); |
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 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
|
1328 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
|
1329 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1330 string = p; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1331 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
|
1332 } |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1333 else |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1334 break; |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1335 } |
771 | 1336 } |
1337 return Fnreverse (result); | |
1338 } | |
1339 | |
1340 /* The same as the above, except PATH is an external C string (it is | |
1341 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR | |
1342 (':' or whatever). */ | |
1343 Lisp_Object | |
1344 split_external_path (const Extbyte *path) | |
1345 { | |
1346 Bytecount newlen; | |
867 | 1347 Ibyte *newpath; |
771 | 1348 if (!path) |
1349 return Qnil; | |
1350 | |
1351 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name); | |
1352 | |
1353 /* #### Does this make sense? It certainly does for | |
1354 split_env_path(), but it looks dubious here. Does any code | |
1355 depend on split_external_path("") returning nil instead of an empty | |
1356 string? */ | |
1357 if (!newlen) | |
1358 return Qnil; | |
1359 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1360 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR, 0, 0); |
771 | 1361 } |
1362 | |
1363 Lisp_Object | |
867 | 1364 split_env_path (const CIbyte *evarname, const Ibyte *default_) |
771 | 1365 { |
867 | 1366 const Ibyte *path = 0; |
771 | 1367 if (evarname) |
1368 path = egetenv (evarname); | |
1369 if (!path) | |
1370 path = default_; | |
1371 if (!path) | |
1372 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
|
1373 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR, 0, 0); |
771 | 1374 } |
1375 | |
1376 /* Ben thinks this function should not exist or be exported to Lisp. | |
1377 We use it to define split-path-string in subr.el (not!). */ | |
1378 | |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1379 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 3, 0, /* |
771 | 1380 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
|
1381 |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1382 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
|
1383 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
|
1384 will be necessary for a single ESCAPE-CHAR to appear in the output string. |
771 | 1385 */ |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1386 (string, sepchar, escape_char)) |
771 | 1387 { |
5035
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1388 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
|
1389 |
771 | 1390 CHECK_STRING (string); |
1391 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
|
1392 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
|
1393 { |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1394 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
|
1395 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
|
1396 } |
867 | 1397 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
|
1398 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
|
1399 XCHAR (sepchar), |
b1e48555be7d
Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5034
diff
changeset
|
1400 !NILP (escape_char), escape_ichar); |
771 | 1401 } |
1402 | |
1403 /* #### This was supposed to be in subr.el, but is used VERY early in | |
1404 the bootstrap process, so it goes here. Damn. */ | |
1405 | |
1406 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /* | |
1407 Explode a search path into a list of strings. | |
1408 The path components are separated with the characters specified | |
1409 with `path-separator'. | |
1410 */ | |
1411 (path)) | |
1412 { | |
1413 CHECK_STRING (path); | |
1414 | |
1415 while (!STRINGP (Vpath_separator) | |
826 | 1416 || (string_char_length (Vpath_separator) != 1)) |
771 | 1417 Vpath_separator = signal_continuable_error |
1418 (Qinvalid_state, | |
1419 "`path-separator' should be set to a single-character string", | |
1420 Vpath_separator); | |
1421 | |
867 | 1422 return (split_string_by_ichar_1 |
771 | 1423 (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
|
1424 itext_ichar (XSTRING_DATA (Vpath_separator)), 0, 0)); |
771 | 1425 } |
1426 | |
428 | 1427 |
1428 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* | |
1429 Take cdr N times on LIST, and return the result. | |
1430 */ | |
1431 (n, list)) | |
1432 { | |
1920 | 1433 /* This function can GC */ |
647 | 1434 REGISTER EMACS_INT i; |
428 | 1435 REGISTER Lisp_Object tail = list; |
1436 CHECK_NATNUM (n); | |
1437 for (i = XINT (n); i; i--) | |
1438 { | |
1439 if (CONSP (tail)) | |
1440 tail = XCDR (tail); | |
1441 else if (NILP (tail)) | |
1442 return Qnil; | |
1443 else | |
1444 { | |
1445 tail = wrong_type_argument (Qlistp, tail); | |
1446 i++; | |
1447 } | |
1448 } | |
1449 return tail; | |
1450 } | |
1451 | |
1452 DEFUN ("nth", Fnth, 2, 2, 0, /* | |
1453 Return the Nth element of LIST. | |
1454 N counts from zero. If LIST is not that long, nil is returned. | |
1455 */ | |
1456 (n, list)) | |
1457 { | |
1920 | 1458 /* This function can GC */ |
428 | 1459 return Fcar (Fnthcdr (n, list)); |
1460 } | |
1461 | |
1462 DEFUN ("elt", Felt, 2, 2, 0, /* | |
1463 Return element of SEQUENCE at index N. | |
1464 */ | |
1465 (sequence, n)) | |
1466 { | |
1920 | 1467 /* This function can GC */ |
428 | 1468 retry: |
1469 CHECK_INT_COERCE_CHAR (n); /* yuck! */ | |
1470 if (LISTP (sequence)) | |
1471 { | |
1472 Lisp_Object tem = Fnthcdr (n, sequence); | |
1473 /* #### Utterly, completely, fucking disgusting. | |
1474 * #### The whole point of "elt" is that it operates on | |
1475 * #### sequences, and does error- (bounds-) checking. | |
1476 */ | |
1477 if (CONSP (tem)) | |
1478 return XCAR (tem); | |
1479 else | |
1480 #if 1 | |
1481 /* This is The Way It Has Always Been. */ | |
1482 return Qnil; | |
1483 #else | |
1484 /* This is The Way Mly and Cltl2 say It Should Be. */ | |
1485 args_out_of_range (sequence, n); | |
1486 #endif | |
1487 } | |
1488 else if (STRINGP (sequence) || | |
1489 VECTORP (sequence) || | |
1490 BIT_VECTORP (sequence)) | |
1491 return Faref (sequence, n); | |
1492 #ifdef LOSING_BYTECODE | |
1493 else if (COMPILED_FUNCTIONP (sequence)) | |
1494 { | |
1495 EMACS_INT idx = XINT (n); | |
1496 if (idx < 0) | |
1497 { | |
1498 lose: | |
1499 args_out_of_range (sequence, n); | |
1500 } | |
1501 /* Utter perversity */ | |
1502 { | |
1503 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence); | |
1504 switch (idx) | |
1505 { | |
1506 case COMPILED_ARGLIST: | |
1507 return compiled_function_arglist (f); | |
1508 case COMPILED_INSTRUCTIONS: | |
1509 return compiled_function_instructions (f); | |
1510 case COMPILED_CONSTANTS: | |
1511 return compiled_function_constants (f); | |
1512 case COMPILED_STACK_DEPTH: | |
1513 return compiled_function_stack_depth (f); | |
1514 case COMPILED_DOC_STRING: | |
1515 return compiled_function_documentation (f); | |
1516 case COMPILED_DOMAIN: | |
1517 return compiled_function_domain (f); | |
1518 case COMPILED_INTERACTIVE: | |
1519 if (f->flags.interactivep) | |
1520 return compiled_function_interactive (f); | |
1521 /* if we return nil, can't tell interactive with no args | |
1522 from noninteractive. */ | |
1523 goto lose; | |
1524 default: | |
1525 goto lose; | |
1526 } | |
1527 } | |
1528 } | |
1529 #endif /* LOSING_BYTECODE */ | |
1530 else | |
1531 { | |
1532 check_losing_bytecode ("elt", sequence); | |
1533 sequence = wrong_type_argument (Qsequencep, sequence); | |
1534 goto retry; | |
1535 } | |
1536 } | |
1537 | |
1538 DEFUN ("last", Flast, 1, 2, 0, /* | |
1539 Return the tail of list LIST, of length N (default 1). | |
1540 LIST may be a dotted list, but not a circular list. | |
1541 Optional argument N must be a non-negative integer. | |
1542 If N is zero, then the atom that terminates the list is returned. | |
1543 If N is greater than the length of LIST, then LIST itself is returned. | |
1544 */ | |
1545 (list, n)) | |
1546 { | |
1547 EMACS_INT int_n, count; | |
1548 Lisp_Object retval, tortoise, hare; | |
1549 | |
1550 CHECK_LIST (list); | |
1551 | |
1552 if (NILP (n)) | |
1553 int_n = 1; | |
1554 else | |
1555 { | |
1556 CHECK_NATNUM (n); | |
1557 int_n = XINT (n); | |
1558 } | |
1559 | |
1560 for (retval = tortoise = hare = list, count = 0; | |
1561 CONSP (hare); | |
1562 hare = XCDR (hare), | |
1563 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0), | |
1564 count++) | |
1565 { | |
1566 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
1567 | |
1568 if (count & 1) | |
1569 tortoise = XCDR (tortoise); | |
1570 if (EQ (hare, tortoise)) | |
1571 signal_circular_list_error (list); | |
1572 } | |
1573 | |
1574 return retval; | |
1575 } | |
1576 | |
1577 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /* | |
1578 Modify LIST to remove the last N (default 1) elements. | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1579 |
428 | 1580 If LIST has N or fewer elements, nil is returned and LIST is unmodified. |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1581 Otherwise, LIST may be dotted, but not circular. |
428 | 1582 */ |
1583 (list, n)) | |
1584 { | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1585 Elemcount int_n = 1; |
428 | 1586 |
1587 CHECK_LIST (list); | |
1588 | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1589 if (!NILP (n)) |
428 | 1590 { |
1591 CHECK_NATNUM (n); | |
1592 int_n = XINT (n); | |
1593 } | |
1594 | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1595 if (CONSP (list)) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1596 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1597 Lisp_Object last_cons = list; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1598 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1599 EXTERNAL_LIST_LOOP_3 (elt, list, tail) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1600 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1601 if (int_n-- < 0) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1602 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1603 last_cons = XCDR (last_cons); |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1604 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1605 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1606 if (!CONSP (XCDR (tail))) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1607 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1608 break; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1609 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1610 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1611 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1612 if (int_n >= 0) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1613 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1614 return Qnil; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1615 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1616 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1617 XCDR (last_cons) = Qnil; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1618 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1619 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1620 return list; |
428 | 1621 } |
1622 | |
1623 DEFUN ("butlast", Fbutlast, 1, 2, 0, /* | |
1624 Return a copy of LIST with the last N (default 1) elements removed. | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1625 |
428 | 1626 If LIST has N or fewer elements, nil is returned. |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1627 Otherwise, LIST may be dotted, but not circular, and `(butlast LIST 0)' |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1628 converts a dotted into a true list. |
428 | 1629 */ |
1630 (list, n)) | |
1631 { | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1632 Lisp_Object retval = Qnil, retval_tail = Qnil; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1633 Elemcount int_n = 1; |
428 | 1634 |
1635 CHECK_LIST (list); | |
1636 | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1637 if (!NILP (n)) |
428 | 1638 { |
1639 CHECK_NATNUM (n); | |
1640 int_n = XINT (n); | |
1641 } | |
1642 | |
5285
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1643 if (CONSP (list)) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1644 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1645 Lisp_Object tail = list; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1646 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1647 EXTERNAL_LIST_LOOP_3 (elt, list, list_tail) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1648 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1649 if (--int_n < 0) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1650 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1651 if (NILP (retval_tail)) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1652 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1653 retval = retval_tail = Fcons (XCAR (tail), Qnil); |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1654 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1655 else |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1656 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1657 XSETCDR (retval_tail, Fcons (XCAR (tail), Qnil)); |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1658 retval_tail = XCDR (retval_tail); |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1659 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1660 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1661 tail = XCDR (tail); |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1662 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1663 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1664 if (!CONSP (XCDR (list_tail))) |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1665 { |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1666 break; |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1667 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1668 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1669 } |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1670 |
99de5fd48e87
Tighten up Common Lisp compatibility, #'butlast, #'nbutlast, #'tailp, #'ldiff
Aidan Kehoe <kehoea@parhasard.net>
parents:
5283
diff
changeset
|
1671 return retval; |
428 | 1672 } |
1673 | |
1674 DEFUN ("member", Fmember, 2, 2, 0, /* | |
1675 Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | |
1676 The value is actually the tail of LIST whose car is ELT. | |
1677 */ | |
1678 (elt, list)) | |
1679 { | |
1680 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1681 { | |
1682 if (internal_equal (elt, list_elt, 0)) | |
1683 return tail; | |
1684 } | |
1685 return Qnil; | |
1686 } | |
1687 | |
1688 DEFUN ("old-member", Fold_member, 2, 2, 0, /* | |
1689 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'. | |
1690 The value is actually the tail of LIST whose car is ELT. | |
1691 This function is provided only for byte-code compatibility with v19. | |
1692 Do not use it. | |
1693 */ | |
1694 (elt, list)) | |
1695 { | |
1696 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1697 { | |
1698 if (internal_old_equal (elt, list_elt, 0)) | |
1699 return tail; | |
1700 } | |
1701 return Qnil; | |
1702 } | |
1703 | |
1704 DEFUN ("memq", Fmemq, 2, 2, 0, /* | |
1705 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. | |
1706 The value is actually the tail of LIST whose car is ELT. | |
1707 */ | |
1708 (elt, list)) | |
1709 { | |
1710 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1711 { | |
1712 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1713 return tail; | |
1714 } | |
1715 return Qnil; | |
1716 } | |
1717 | |
1718 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /* | |
1719 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'. | |
1720 The value is actually the tail of LIST whose car is ELT. | |
1721 This function is provided only for byte-code compatibility with v19. | |
1722 Do not use it. | |
1723 */ | |
1724 (elt, list)) | |
1725 { | |
1726 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1727 { | |
1728 if (HACKEQ_UNSAFE (elt, list_elt)) | |
1729 return tail; | |
1730 } | |
1731 return Qnil; | |
1732 } | |
1733 | |
1734 Lisp_Object | |
1735 memq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1736 { | |
1737 LIST_LOOP_3 (list_elt, list, tail) | |
1738 { | |
1739 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1740 return tail; | |
1741 } | |
1742 return Qnil; | |
1743 } | |
1744 | |
1745 DEFUN ("assoc", Fassoc, 2, 2, 0, /* | |
444 | 1746 Return non-nil if KEY is `equal' to the car of an element of ALIST. |
1747 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1748 */ |
444 | 1749 (key, alist)) |
428 | 1750 { |
1751 /* This function can GC. */ | |
444 | 1752 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1753 { |
1754 if (internal_equal (key, elt_car, 0)) | |
1755 return elt; | |
1756 } | |
1757 return Qnil; | |
1758 } | |
1759 | |
1760 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /* | |
444 | 1761 Return non-nil if KEY is `old-equal' to the car of an element of ALIST. |
1762 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1763 */ |
444 | 1764 (key, alist)) |
428 | 1765 { |
1766 /* This function can GC. */ | |
444 | 1767 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1768 { |
1769 if (internal_old_equal (key, elt_car, 0)) | |
1770 return elt; | |
1771 } | |
1772 return Qnil; | |
1773 } | |
1774 | |
1775 Lisp_Object | |
444 | 1776 assoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1777 { |
1778 int speccount = specpdl_depth (); | |
1779 specbind (Qinhibit_quit, Qt); | |
771 | 1780 return unbind_to_1 (speccount, Fassoc (key, alist)); |
428 | 1781 } |
1782 | |
1783 DEFUN ("assq", Fassq, 2, 2, 0, /* | |
444 | 1784 Return non-nil if KEY is `eq' to the car of an element of ALIST. |
1785 The value is actually the element of ALIST whose car is KEY. | |
1786 Elements of ALIST that are not conses are ignored. | |
428 | 1787 */ |
444 | 1788 (key, alist)) |
428 | 1789 { |
444 | 1790 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1791 { |
1792 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1793 return elt; | |
1794 } | |
1795 return Qnil; | |
1796 } | |
1797 | |
1798 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /* | |
444 | 1799 Return non-nil if KEY is `old-eq' to the car of an element of ALIST. |
1800 The value is actually the element of ALIST whose car is KEY. | |
1801 Elements of ALIST that are not conses are ignored. | |
428 | 1802 This function is provided only for byte-code compatibility with v19. |
1803 Do not use it. | |
1804 */ | |
444 | 1805 (key, alist)) |
428 | 1806 { |
444 | 1807 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1808 { |
1809 if (HACKEQ_UNSAFE (key, elt_car)) | |
1810 return elt; | |
1811 } | |
1812 return Qnil; | |
1813 } | |
1814 | |
1815 /* Like Fassq but never report an error and do not allow quits. | |
1816 Use only on lists known never to be circular. */ | |
1817 | |
1818 Lisp_Object | |
444 | 1819 assq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1820 { |
1821 /* This cannot GC. */ | |
444 | 1822 LIST_LOOP_2 (elt, alist) |
428 | 1823 { |
1824 Lisp_Object elt_car = XCAR (elt); | |
1825 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1826 return elt; | |
1827 } | |
1828 return Qnil; | |
1829 } | |
1830 | |
1831 DEFUN ("rassoc", Frassoc, 2, 2, 0, /* | |
444 | 1832 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST. |
1833 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1834 */ |
444 | 1835 (value, alist)) |
428 | 1836 { |
444 | 1837 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1838 { |
444 | 1839 if (internal_equal (value, elt_cdr, 0)) |
428 | 1840 return elt; |
1841 } | |
1842 return Qnil; | |
1843 } | |
1844 | |
1845 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /* | |
444 | 1846 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST. |
1847 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1848 */ |
444 | 1849 (value, alist)) |
428 | 1850 { |
444 | 1851 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1852 { |
444 | 1853 if (internal_old_equal (value, elt_cdr, 0)) |
428 | 1854 return elt; |
1855 } | |
1856 return Qnil; | |
1857 } | |
1858 | |
1859 DEFUN ("rassq", Frassq, 2, 2, 0, /* | |
444 | 1860 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST. |
1861 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1862 */ |
444 | 1863 (value, alist)) |
428 | 1864 { |
444 | 1865 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1866 { |
444 | 1867 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1868 return elt; |
1869 } | |
1870 return Qnil; | |
1871 } | |
1872 | |
1873 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /* | |
444 | 1874 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST. |
1875 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1876 */ |
444 | 1877 (value, alist)) |
428 | 1878 { |
444 | 1879 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1880 { |
444 | 1881 if (HACKEQ_UNSAFE (value, elt_cdr)) |
428 | 1882 return elt; |
1883 } | |
1884 return Qnil; | |
1885 } | |
1886 | |
444 | 1887 /* Like Frassq, but caller must ensure that ALIST is properly |
428 | 1888 nil-terminated and ebola-free. */ |
1889 Lisp_Object | |
444 | 1890 rassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1891 { |
444 | 1892 LIST_LOOP_2 (elt, alist) |
428 | 1893 { |
1894 Lisp_Object elt_cdr = XCDR (elt); | |
444 | 1895 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1896 return elt; |
1897 } | |
1898 return Qnil; | |
1899 } | |
1900 | |
1901 | |
1902 DEFUN ("delete", Fdelete, 2, 2, 0, /* | |
1903 Delete by side effect any occurrences of ELT as a member of LIST. | |
1904 The modified LIST is returned. Comparison is done with `equal'. | |
1905 If the first member of LIST is ELT, there is no way to remove it by side | |
1906 effect; therefore, write `(setq foo (delete element foo))' to be sure | |
1907 of changing the value of `foo'. | |
1908 Also see: `remove'. | |
1909 */ | |
1910 (elt, list)) | |
1911 { | |
1912 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1913 (internal_equal (elt, list_elt, 0))); | |
1914 return list; | |
1915 } | |
1916 | |
1917 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /* | |
1918 Delete by side effect any occurrences of ELT as a member of LIST. | |
1919 The modified LIST is returned. Comparison is done with `old-equal'. | |
1920 If the first member of LIST is ELT, there is no way to remove it by side | |
1921 effect; therefore, write `(setq foo (old-delete element foo))' to be sure | |
1922 of changing the value of `foo'. | |
1923 */ | |
1924 (elt, list)) | |
1925 { | |
1926 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1927 (internal_old_equal (elt, list_elt, 0))); | |
1928 return list; | |
1929 } | |
1930 | |
1931 DEFUN ("delq", Fdelq, 2, 2, 0, /* | |
1932 Delete by side effect any occurrences of ELT as a member of LIST. | |
1933 The modified LIST is returned. Comparison is done with `eq'. | |
1934 If the first member of LIST is ELT, there is no way to remove it by side | |
1935 effect; therefore, write `(setq foo (delq element foo))' to be sure of | |
1936 changing the value of `foo'. | |
1937 */ | |
1938 (elt, list)) | |
1939 { | |
1940 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1941 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1942 return list; | |
1943 } | |
1944 | |
1945 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /* | |
1946 Delete by side effect any occurrences of ELT as a member of LIST. | |
1947 The modified LIST is returned. Comparison is done with `old-eq'. | |
1948 If the first member of LIST is ELT, there is no way to remove it by side | |
1949 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of | |
1950 changing the value of `foo'. | |
1951 */ | |
1952 (elt, list)) | |
1953 { | |
1954 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1955 (HACKEQ_UNSAFE (elt, list_elt))); | |
1956 return list; | |
1957 } | |
1958 | |
1959 /* Like Fdelq, but caller must ensure that LIST is properly | |
1960 nil-terminated and ebola-free. */ | |
1961 | |
1962 Lisp_Object | |
1963 delq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1964 { | |
1965 LIST_LOOP_DELETE_IF (list_elt, list, | |
1966 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1967 return list; | |
1968 } | |
1969 | |
1970 /* Be VERY careful with this. This is like delq_no_quit() but | |
1971 also calls free_cons() on the removed conses. You must be SURE | |
1972 that no pointers to the freed conses remain around (e.g. | |
1973 someone else is pointing to part of the list). This function | |
1974 is useful on internal lists that are used frequently and where | |
1975 the actual list doesn't escape beyond known code bounds. */ | |
1976 | |
1977 Lisp_Object | |
1978 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list) | |
1979 { | |
1980 REGISTER Lisp_Object tail = list; | |
1981 REGISTER Lisp_Object prev = Qnil; | |
1982 | |
1983 while (!NILP (tail)) | |
1984 { | |
1985 REGISTER Lisp_Object tem = XCAR (tail); | |
1986 if (EQ (elt, tem)) | |
1987 { | |
1988 Lisp_Object cons_to_free = tail; | |
1989 if (NILP (prev)) | |
1990 list = XCDR (tail); | |
1991 else | |
1992 XCDR (prev) = XCDR (tail); | |
1993 tail = XCDR (tail); | |
853 | 1994 free_cons (cons_to_free); |
428 | 1995 } |
1996 else | |
1997 { | |
1998 prev = tail; | |
1999 tail = XCDR (tail); | |
2000 } | |
2001 } | |
2002 return list; | |
2003 } | |
2004 | |
2005 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /* | |
444 | 2006 Delete by side effect any elements of ALIST whose car is `equal' to KEY. |
2007 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 2008 that is `equal' to KEY, there is no way to remove it by side effect; |
2009 therefore, write `(setq foo (remassoc key foo))' to be sure of changing | |
2010 the value of `foo'. | |
2011 */ | |
444 | 2012 (key, alist)) |
428 | 2013 { |
444 | 2014 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2015 (CONSP (elt) && |
2016 internal_equal (key, XCAR (elt), 0))); | |
444 | 2017 return alist; |
428 | 2018 } |
2019 | |
2020 Lisp_Object | |
444 | 2021 remassoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 2022 { |
2023 int speccount = specpdl_depth (); | |
2024 specbind (Qinhibit_quit, Qt); | |
771 | 2025 return unbind_to_1 (speccount, Fremassoc (key, alist)); |
428 | 2026 } |
2027 | |
2028 DEFUN ("remassq", Fremassq, 2, 2, 0, /* | |
444 | 2029 Delete by side effect any elements of ALIST whose car is `eq' to KEY. |
2030 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 2031 that is `eq' to KEY, there is no way to remove it by side effect; |
2032 therefore, write `(setq foo (remassq key foo))' to be sure of changing | |
2033 the value of `foo'. | |
2034 */ | |
444 | 2035 (key, alist)) |
428 | 2036 { |
444 | 2037 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2038 (CONSP (elt) && |
2039 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 2040 return alist; |
428 | 2041 } |
2042 | |
2043 /* no quit, no errors; be careful */ | |
2044 | |
2045 Lisp_Object | |
444 | 2046 remassq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 2047 { |
444 | 2048 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2049 (CONSP (elt) && |
2050 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 2051 return alist; |
428 | 2052 } |
2053 | |
2054 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /* | |
444 | 2055 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE. |
2056 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 2057 that is `equal' to VALUE, there is no way to remove it by side effect; |
2058 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing | |
2059 the value of `foo'. | |
2060 */ | |
444 | 2061 (value, alist)) |
428 | 2062 { |
444 | 2063 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2064 (CONSP (elt) && |
2065 internal_equal (value, XCDR (elt), 0))); | |
444 | 2066 return alist; |
428 | 2067 } |
2068 | |
2069 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /* | |
444 | 2070 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE. |
2071 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 2072 that is `eq' to VALUE, there is no way to remove it by side effect; |
2073 therefore, write `(setq foo (remrassq value foo))' to be sure of changing | |
2074 the value of `foo'. | |
2075 */ | |
444 | 2076 (value, alist)) |
428 | 2077 { |
444 | 2078 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2079 (CONSP (elt) && |
2080 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 2081 return alist; |
428 | 2082 } |
2083 | |
2084 /* Like Fremrassq, fast and unsafe; be careful */ | |
2085 Lisp_Object | |
444 | 2086 remrassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 2087 { |
444 | 2088 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 2089 (CONSP (elt) && |
2090 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 2091 return alist; |
428 | 2092 } |
2093 | |
2094 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /* | |
2095 Reverse LIST by destructively modifying cdr pointers. | |
2096 Return the beginning of the reversed list. | |
2097 Also see: `reverse'. | |
2098 */ | |
2099 (list)) | |
2100 { | |
2101 struct gcpro gcpro1, gcpro2; | |
1849 | 2102 Lisp_Object prev = Qnil; |
2103 Lisp_Object tail = list; | |
428 | 2104 |
2105 /* We gcpro our args; see `nconc' */ | |
2106 GCPRO2 (prev, tail); | |
2107 while (!NILP (tail)) | |
2108 { | |
2109 REGISTER Lisp_Object next; | |
2110 CONCHECK_CONS (tail); | |
2111 next = XCDR (tail); | |
2112 XCDR (tail) = prev; | |
2113 prev = tail; | |
2114 tail = next; | |
2115 } | |
2116 UNGCPRO; | |
2117 return prev; | |
2118 } | |
2119 | |
2120 DEFUN ("reverse", Freverse, 1, 1, 0, /* | |
2121 Reverse LIST, copying. Return the beginning of the reversed list. | |
2122 See also the function `nreverse', which is used more often. | |
2123 */ | |
2124 (list)) | |
2125 { | |
2126 Lisp_Object reversed_list = Qnil; | |
2127 EXTERNAL_LIST_LOOP_2 (elt, list) | |
2128 { | |
2129 reversed_list = Fcons (elt, reversed_list); | |
2130 } | |
2131 return reversed_list; | |
2132 } | |
2133 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2134 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2135 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
|
2136 Lisp_Object pred, Lisp_Object key_func) |
428 | 2137 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2138 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2139 Lisp_Object args[3]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2140 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2141 /* 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
|
2142 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
|
2143 args[0] = key_func; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2144 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2145 args[2] = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2146 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2147 GCPRO1 (args[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2148 gcpro1.nvars = countof (args); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2149 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2150 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
|
2151 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2152 args[1] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2153 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
|
2154 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2155 args[0] = pred; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2156 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2157 args[2] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2158 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2159 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args))); |
428 | 2160 } |
2161 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2162 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2163 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
|
2164 Lisp_Object pred, Lisp_Object UNUSED (key_func)) |
428 | 2165 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2166 struct gcpro gcpro1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2167 Lisp_Object args[3]; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2168 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2169 /* 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
|
2170 inline it here. */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2171 args[0] = pred; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2172 args[1] = obj1; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2173 args[2] = obj2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2174 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2175 GCPRO1 (args[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2176 gcpro1.nvars = countof (args); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2177 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2178 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args))); |
428 | 2179 } |
2180 | |
2181 Lisp_Object | |
2182 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
|
2183 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
|
2184 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2185 Lisp_Object predicate, Lisp_Object key_func) |
428 | 2186 { |
2187 Lisp_Object value; | |
2188 Lisp_Object tail; | |
2189 Lisp_Object tem; | |
2190 Lisp_Object l1, l2; | |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2191 Lisp_Object tortoises[2]; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2192 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
5283
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2193 int l1_count = 0, l2_count = 0; |
428 | 2194 |
2195 l1 = org_l1; | |
2196 l2 = org_l2; | |
2197 tail = Qnil; | |
2198 value = Qnil; | |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2199 tortoises[0] = org_l1; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2200 tortoises[1] = org_l2; |
428 | 2201 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2202 if (NULL == c_predicate) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2203 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2204 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
|
2205 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
|
2206 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2207 |
428 | 2208 /* It is sufficient to protect org_l1 and org_l2. |
2209 When l1 and l2 are updated, we copy the new values | |
2210 back into the org_ vars. */ | |
2211 | |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2212 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
|
2213 gcpro5.nvars = 2; |
428 | 2214 |
2215 while (1) | |
2216 { | |
2217 if (NILP (l1)) | |
2218 { | |
2219 UNGCPRO; | |
2220 if (NILP (tail)) | |
2221 return l2; | |
2222 Fsetcdr (tail, l2); | |
2223 return value; | |
2224 } | |
2225 if (NILP (l2)) | |
2226 { | |
2227 UNGCPRO; | |
2228 if (NILP (tail)) | |
2229 return l1; | |
2230 Fsetcdr (tail, l1); | |
2231 return value; | |
2232 } | |
2233 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2234 if (NILP (c_predicate (Fcar (l2), Fcar (l1), predicate, key_func))) |
428 | 2235 { |
2236 tem = l1; | |
2237 l1 = Fcdr (l1); | |
2238 org_l1 = l1; | |
5283
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2239 |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2240 if (l1_count++ > CIRCULAR_LIST_SUSPICION_LENGTH) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2241 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2242 if (l1_count & 1) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2243 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2244 if (!CONSP (tortoises[0])) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2245 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2246 mapping_interaction_error (Qmerge, tortoises[0]); |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2247 } |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2248 |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2249 tortoises[0] = XCDR (tortoises[0]); |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2250 } |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2251 |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2252 if (EQ (org_l1, tortoises[0])) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2253 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2254 signal_circular_list_error (org_l1); |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2255 } |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2256 } |
428 | 2257 } |
2258 else | |
2259 { | |
2260 tem = l2; | |
2261 l2 = Fcdr (l2); | |
2262 org_l2 = l2; | |
5283
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2263 |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2264 if (l2_count++ > CIRCULAR_LIST_SUSPICION_LENGTH) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2265 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2266 if (l2_count & 1) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2267 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2268 if (!CONSP (tortoises[1])) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2269 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2270 mapping_interaction_error (Qmerge, tortoises[1]); |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2271 } |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2272 |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2273 tortoises[1] = XCDR (tortoises[1]); |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2274 } |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2275 |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2276 if (EQ (org_l2, tortoises[1])) |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2277 { |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2278 signal_circular_list_error (org_l2); |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2279 } |
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2280 } |
428 | 2281 } |
5283
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2282 |
428 | 2283 if (NILP (tail)) |
2284 value = tem; | |
2285 else | |
2286 Fsetcdr (tail, tem); | |
5283
be436ac36ba4
Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2287 |
428 | 2288 tail = tem; |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2289 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2290 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2291 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2292 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2293 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
|
2294 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
|
2295 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
|
2296 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
|
2297 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2298 Lisp_Object 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
|
2299 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2300 Elemcount ii, fronting, backing; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2301 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
|
2302 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
|
2303 struct gcpro gcpro1, gcpro2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2304 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2305 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
|
2306 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2307 if (0 == dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2308 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2309 return; |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2312 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
|
2313 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2314 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
|
2315 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2316 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
|
2317 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2318 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
|
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2322 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
|
2323 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2324 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
|
2325 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2326 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
|
2327 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2328 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
|
2329 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2330 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2331 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2332 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
|
2333 gcpro1.nvars = front_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2334 gcpro2.nvars = back_len; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2335 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2336 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
|
2337 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2338 if (fronting >= front_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2339 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2340 while (ii < dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2341 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2342 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
|
2343 ++ii, ++backing; |
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 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2347 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2348 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2349 if (backing >= back_len) |
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 while (ii < dest_len) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2352 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2353 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
|
2354 ++ii, ++fronting; |
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 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2357 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2358 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2359 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2360 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
|
2361 predicate, key_func))) |
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 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
|
2364 ++fronting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2365 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2366 else |
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 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
|
2369 ++backing; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2370 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2371 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2372 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2373 UNGCPRO; |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2376 static Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2377 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
|
2378 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
|
2379 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
|
2380 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2381 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2382 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2383 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
|
2384 Boolint reverse_order) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2385 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2386 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
|
2387 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
|
2388 Elemcount array_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2389 int looped = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2390 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2391 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
|
2392 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2393 while (1) |
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 if (NILP (list)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2396 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2397 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2398 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2399 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2400 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2401 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
|
2402 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2403 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2404 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
|
2405 return value; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2406 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2407 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2408 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
|
2409 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2410 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2411 if (NILP (tail)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2412 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2413 return list; |
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 Fsetcdr (tail, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2417 return value; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2418 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2419 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2420 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2421 if (reverse_order ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2422 !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
|
2423 key_func)) : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2424 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
|
2425 key_func))) |
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 if (NILP (tail)) |
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 value = tail = list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2430 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2431 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2432 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2433 Fsetcdr (tail, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2434 tail = XCDR (tail); |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2437 list = Fcdr (list); |
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 else |
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 if (NILP (tail)) |
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 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
|
2444 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2445 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2446 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2447 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
|
2448 tail = XCDR (tail); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2449 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2450 ++array_index; |
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 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2453 if (++looped > CIRCULAR_LIST_SUSPICION_LENGTH) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2454 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2455 if (looped & 1) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2456 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2457 tortoise = XCDR (tortoise); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2458 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2459 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2460 if (EQ (list, tortoise)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2461 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2462 signal_circular_list_error (list); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2463 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2464 } |
5182
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2468 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2469 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
|
2470 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
|
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 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2477 Elemcount output_index = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2478 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2479 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
|
2480 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2481 if (NILP (list_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2482 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2483 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
|
2484 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2485 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
|
2486 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
|
2487 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2488 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2489 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2490 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2491 if (NILP (list_two)) |
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 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
|
2494 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2495 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
|
2496 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
|
2497 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2498 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2499 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2500 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2501 if (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
|
2502 key_func))) |
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 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
|
2505 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
|
2506 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2507 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2508 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2509 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
|
2510 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
|
2511 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2512 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2513 ++output_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2514 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2515 /* 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
|
2516 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2517 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2518 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2519 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2520 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
|
2521 Lisp_Object list, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2522 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
|
2523 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
|
2524 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2525 Lisp_Object, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2526 Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2527 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
|
2528 Boolint reverse_order) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2529 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2530 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
|
2531 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2532 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
|
2533 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2534 if (NILP (list)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2535 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2536 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
|
2537 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
2538 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
|
2539 } |
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 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
|
2542 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2543 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
|
2544 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2545 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2546 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2547 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2548 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2549 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
|
2550 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2551 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
|
2552 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2553 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
|
2554 list = Fcdr (list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2555 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2556 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2557 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2558 } |
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 if (reverse_order ? |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2561 !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
|
2562 key_func)) : |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2563 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
|
2564 key_func))) |
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 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
|
2567 list = XCDR (list); |
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 else |
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 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
|
2572 ++array_index; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2573 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2574 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2575 ++output_index; |
428 | 2576 } |
2577 } | |
2578 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2579 #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
|
2580 do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2581 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
|
2582 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
|
2583 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2584 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
|
2585 INC_IBYTEPTR (strdata); \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2586 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2587 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2588 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2589 #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
|
2590 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
|
2591 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
|
2592 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2593 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
|
2594 } \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2595 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2596 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2597 /* 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
|
2598 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2599 #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
|
2600 do { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2601 if (NILP (key)) \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2602 { \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2603 key = Qidentity; \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2604 } \ |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2605 \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2606 if (!EQ (key, Qidentity)) \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2607 { \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2608 key = indirect_function (key, 1); \ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2609 } \ |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2610 } while (0) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2611 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2612 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
|
2613 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
|
2614 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2615 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
|
2616 predicate on the elements. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2617 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2618 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
|
2619 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
|
2620 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2621 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
|
2622 */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2623 (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
|
2624 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2625 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
|
2626 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
|
2627 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
|
2628 Lisp_Object); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2629 |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
2630 PARSE_KEYWORDS (Fmerge, nargs, args, 1, (key), NULL); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2631 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2632 CHECK_SEQUENCE (sequence_one); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2633 CHECK_SEQUENCE (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2634 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2635 CHECK_KEY_ARGUMENT (key); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2636 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2637 c_predicate = EQ (key, Qidentity) ? |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2638 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
|
2639 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2640 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
|
2641 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2642 if (NILP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2643 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2644 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
|
2645 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2646 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
|
2647 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2648 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
|
2649 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
|
2650 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
|
2651 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2652 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
|
2653 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2654 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
|
2655 predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2656 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2657 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2658 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2659 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
|
2660 Elemcount array_length, i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2661 Boolint reverse_order = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2662 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2663 if (!CONSP (sequence_one)) |
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 /* 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
|
2666 swap = sequence_one; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2667 sequence_one = sequence_two; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2668 sequence_two = swap; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2669 reverse_order = 1; |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2672 if (VECTORP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2673 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2674 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
|
2675 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
|
2676 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2677 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
|
2678 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2679 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
|
2680 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
|
2681 /* 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
|
2682 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
|
2683 array_length); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2684 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2685 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2686 else |
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 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
|
2689 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
|
2690 /* 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
|
2691 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
|
2692 } |
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 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
|
2695 array_storage, array_length, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2696 c_predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2697 predicate, key, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2698 reverse_order); |
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 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2701 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2702 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2703 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
|
2704 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
|
2705 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
|
2706 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
|
2707 *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
|
2708 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
|
2709 || 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
|
2710 Ibyte *strdata = NULL; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2711 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
|
2712 struct gcpro gcpro1; |
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 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
|
2715 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
|
2716 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2717 output[i] = Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2718 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2719 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2720 GCPRO1 (output[0]); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2721 gcpro1.nvars = output_len; |
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 if (VECTORP (sequence_one)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2724 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2725 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
|
2726 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2727 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
|
2728 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2729 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
|
2730 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
|
2731 i, sequence_one_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2732 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2733 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
|
2734 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2735 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
|
2736 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
|
2737 i, sequence_one_len); |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2740 if (VECTORP (sequence_two)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2741 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2742 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
|
2743 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2744 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
|
2745 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2746 strdata = XSTRING_DATA (sequence_two); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2747 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
|
2748 i, sequence_two_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2749 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2750 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
|
2751 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2752 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
|
2753 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
|
2754 i, sequence_two_len); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2755 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2756 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2757 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
|
2758 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2759 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
|
2760 sequence_one, sequence_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2761 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2762 key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2763 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2764 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
|
2765 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2766 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
|
2767 sequence_one, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2768 sequence_two_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2769 sequence_two_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2770 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2771 key, 0); |
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 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
|
2774 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2775 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
|
2776 sequence_two, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2777 sequence_one_storage, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2778 sequence_one_len, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2779 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2780 key, 1); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2781 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2782 else |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2783 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2784 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
|
2785 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
|
2786 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
|
2787 c_predicate, predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2788 key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2789 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2790 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2791 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
|
2792 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2793 if (do_coerce) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2794 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2795 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
|
2796 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2797 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2798 UNGCPRO; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2799 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2800 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2801 return result; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2802 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2803 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2804 /* 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
|
2805 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
|
2806 Lisp_Object |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2807 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
|
2808 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
|
2809 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2810 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
|
2811 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2812 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
|
2813 Lisp_Object back, tem; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2814 Lisp_Object front = list; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2815 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
|
2816 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2817 if (XINT (len) < 2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2818 return list; |
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 if (NULL == c_predicate) |
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 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
|
2823 c_merge_predicate_key; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2824 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2825 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2826 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
|
2827 tem = Fnthcdr (len, list); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2828 back = Fcdr (tem); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2829 Fsetcdr (tem, Qnil); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2830 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2831 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
|
2832 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
|
2833 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
|
2834 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2835 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
|
2836 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2837 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2838 static void |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2839 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
|
2840 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
|
2841 Lisp_Object, Lisp_Object), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2842 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
|
2843 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2844 Elemcount split; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2845 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2846 if (array_len < 2) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2847 return; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2848 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2849 split = array_len / 2; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2850 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2851 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
|
2852 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
|
2853 key_func); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2854 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
|
2855 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
|
2856 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2857 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2858 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
|
2859 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
|
2860 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
|
2861 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2862 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
|
2863 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
|
2864 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2865 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
|
2866 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
|
2867 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2868 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
|
2869 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
|
2870 same guarantees. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2871 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2872 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
|
2873 */ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2874 (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
|
2875 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2876 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
|
2877 Lisp_Object *sequence_carray; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2878 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
|
2879 Lisp_Object); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2880 Elemcount sequence_len, i; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2881 |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
2882 PARSE_KEYWORDS (FsortX, nargs, args, 1, (key), NULL); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2883 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2884 CHECK_SEQUENCE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2885 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2886 CHECK_KEY_ARGUMENT (key); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2887 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2888 c_predicate = EQ (key, Qidentity) ? |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
2889 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
|
2890 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2891 if (LISTP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2892 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2893 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
|
2894 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2895 else if (VECTORP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2896 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2897 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
|
2898 c_predicate, predicate, key); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2899 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2900 else if (STRINGP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2901 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2902 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
|
2903 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2904 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
|
2905 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2906 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
|
2907 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2908 /* 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
|
2909 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
|
2910 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2911 strdata = XSTRING_DATA (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2912 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2913 CHECK_LISP_WRITEABLE (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2914 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
|
2915 { |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
2916 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
|
2917 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2918 |
5184
039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
2919 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
|
2920 bump_string_modiff (sequence); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2921 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
|
2922 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2923 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
|
2924 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2925 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
|
2926 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
|
2927 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2928 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
|
2929 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2930 /* 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
|
2931 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
|
2932 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2933 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
|
2934 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2935 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
|
2936 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2937 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2938 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2939 return sequence; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
2940 } |
428 | 2941 |
2942 /************************************************************************/ | |
2943 /* property-list functions */ | |
2944 /************************************************************************/ | |
2945 | |
2946 /* For properties of text, we need to do order-insensitive comparison of | |
2947 plists. That is, we need to compare two plists such that they are the | |
2948 same if they have the same set of keys, and equivalent values. | |
2949 So (a 1 b 2) would be equal to (b 2 a 1). | |
2950 | |
2951 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc. | |
2952 LAXP means use `equal' for comparisons. | |
2953 */ | |
2954 int | |
2955 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
|
2956 int laxp, int depth, int foldcase) |
428 | 2957 { |
438 | 2958 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */ |
428 | 2959 int la, lb, m, i, fill; |
2960 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
|
2961 Boolbyte *flags; |
428 | 2962 Lisp_Object rest; |
2963 | |
2964 if (NILP (a) && NILP (b)) | |
2965 return 0; | |
2966 | |
2967 Fcheck_valid_plist (a); | |
2968 Fcheck_valid_plist (b); | |
2969 | |
2970 la = XINT (Flength (a)); | |
2971 lb = XINT (Flength (b)); | |
2972 m = (la > lb ? la : lb); | |
2973 fill = 0; | |
2974 keys = alloca_array (Lisp_Object, m); | |
2975 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
|
2976 flags = alloca_array (Boolbyte, m); |
428 | 2977 |
2978 /* First extract the pairs from A. */ | |
2979 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2980 { | |
2981 Lisp_Object k = XCAR (rest); | |
2982 Lisp_Object v = XCAR (XCDR (rest)); | |
2983 /* Maybe be Ebolified. */ | |
2984 if (nil_means_not_present && NILP (v)) continue; | |
2985 keys [fill] = k; | |
2986 vals [fill] = v; | |
2987 flags[fill] = 0; | |
2988 fill++; | |
2989 } | |
2990 /* Now iterate over B, and stop if we find something that's not in A, | |
2991 or that doesn't match. As we match, mark them. */ | |
2992 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2993 { | |
2994 Lisp_Object k = XCAR (rest); | |
2995 Lisp_Object v = XCAR (XCDR (rest)); | |
2996 /* Maybe be Ebolified. */ | |
2997 if (nil_means_not_present && NILP (v)) continue; | |
2998 for (i = 0; i < fill; i++) | |
2999 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3000 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
|
3001 internal_equal_0 (k, keys [i], depth, foldcase)) |
428 | 3002 { |
434 | 3003 if (eqp |
3004 /* We narrowly escaped being Ebolified here. */ | |
3005 ? !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
|
3006 : !internal_equal_0 (v, vals [i], depth, foldcase)) |
428 | 3007 /* a property in B has a different value than in A */ |
3008 goto MISMATCH; | |
3009 flags [i] = 1; | |
3010 break; | |
3011 } | |
3012 } | |
3013 if (i == fill) | |
3014 /* there are some properties in B that are not in A */ | |
3015 goto MISMATCH; | |
3016 } | |
3017 /* Now check to see that all the properties in A were also in B */ | |
3018 for (i = 0; i < fill; i++) | |
3019 if (flags [i] == 0) | |
3020 goto MISMATCH; | |
3021 | |
3022 /* Ok. */ | |
3023 return 0; | |
3024 | |
3025 MISMATCH: | |
3026 return 1; | |
3027 } | |
3028 | |
3029 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /* | |
3030 Return non-nil if property lists A and B are `eq'. | |
3031 A property list is an alternating list of keywords and values. | |
3032 This function does order-insensitive comparisons of the property lists: | |
3033 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
3034 Comparison between values is done using `eq'. See also `plists-equal'. | |
3035 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3036 a nil value is ignored. This feature is a virus that has infected | |
3037 old Lisp implementations, but should not be used except for backward | |
3038 compatibility. | |
3039 */ | |
3040 (a, b, nil_means_not_present)) | |
3041 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3042 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1, 0) |
428 | 3043 ? Qnil : Qt); |
3044 } | |
3045 | |
3046 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /* | |
3047 Return non-nil if property lists A and B are `equal'. | |
3048 A property list is an alternating list of keywords and values. This | |
3049 function does order-insensitive comparisons of the property lists: For | |
3050 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
3051 Comparison between values is done using `equal'. See also `plists-eq'. | |
3052 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3053 a nil value is ignored. This feature is a virus that has infected | |
3054 old Lisp implementations, but should not be used except for backward | |
3055 compatibility. | |
3056 */ | |
3057 (a, b, nil_means_not_present)) | |
3058 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3059 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1, 0) |
428 | 3060 ? Qnil : Qt); |
3061 } | |
3062 | |
3063 | |
3064 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /* | |
3065 Return non-nil if lax property lists A and B are `eq'. | |
3066 A property list is an alternating list of keywords and values. | |
3067 This function does order-insensitive comparisons of the property lists: | |
3068 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
3069 Comparison between values is done using `eq'. See also `plists-equal'. | |
3070 A lax property list is like a regular one except that comparisons between | |
3071 keywords is done using `equal' instead of `eq'. | |
3072 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3073 a nil value is ignored. This feature is a virus that has infected | |
3074 old Lisp implementations, but should not be used except for backward | |
3075 compatibility. | |
3076 */ | |
3077 (a, b, nil_means_not_present)) | |
3078 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3079 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1, 0) |
428 | 3080 ? Qnil : Qt); |
3081 } | |
3082 | |
3083 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /* | |
3084 Return non-nil if lax property lists A and B are `equal'. | |
3085 A property list is an alternating list of keywords and values. This | |
3086 function does order-insensitive comparisons of the property lists: For | |
3087 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
3088 Comparison between values is done using `equal'. See also `plists-eq'. | |
3089 A lax property list is like a regular one except that comparisons between | |
3090 keywords is done using `equal' instead of `eq'. | |
3091 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3092 a nil value is ignored. This feature is a virus that has infected | |
3093 old Lisp implementations, but should not be used except for backward | |
3094 compatibility. | |
3095 */ | |
3096 (a, b, nil_means_not_present)) | |
3097 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3098 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1, 0) |
428 | 3099 ? Qnil : Qt); |
3100 } | |
3101 | |
3102 /* Return the value associated with key PROPERTY in property list PLIST. | |
3103 Return nil if key not found. This function is used for internal | |
3104 property lists that cannot be directly manipulated by the user. | |
3105 */ | |
3106 | |
3107 Lisp_Object | |
3108 internal_plist_get (Lisp_Object plist, Lisp_Object property) | |
3109 { | |
3110 Lisp_Object tail; | |
3111 | |
3112 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
3113 { | |
3114 if (EQ (XCAR (tail), property)) | |
3115 return XCAR (XCDR (tail)); | |
3116 } | |
3117 | |
3118 return Qunbound; | |
3119 } | |
3120 | |
3121 /* Set PLIST's value for PROPERTY to VALUE. Analogous to | |
3122 internal_plist_get(). */ | |
3123 | |
3124 void | |
3125 internal_plist_put (Lisp_Object *plist, Lisp_Object property, | |
3126 Lisp_Object value) | |
3127 { | |
3128 Lisp_Object tail; | |
3129 | |
3130 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
3131 { | |
3132 if (EQ (XCAR (tail), property)) | |
3133 { | |
3134 XCAR (XCDR (tail)) = value; | |
3135 return; | |
3136 } | |
3137 } | |
3138 | |
3139 *plist = Fcons (property, Fcons (value, *plist)); | |
3140 } | |
3141 | |
3142 int | |
3143 internal_remprop (Lisp_Object *plist, Lisp_Object property) | |
3144 { | |
3145 Lisp_Object tail, prev; | |
3146 | |
3147 for (tail = *plist, prev = Qnil; | |
3148 !NILP (tail); | |
3149 tail = XCDR (XCDR (tail))) | |
3150 { | |
3151 if (EQ (XCAR (tail), property)) | |
3152 { | |
3153 if (NILP (prev)) | |
3154 *plist = XCDR (XCDR (tail)); | |
3155 else | |
3156 XCDR (XCDR (prev)) = XCDR (XCDR (tail)); | |
3157 return 1; | |
3158 } | |
3159 else | |
3160 prev = tail; | |
3161 } | |
3162 | |
3163 return 0; | |
3164 } | |
3165 | |
3166 /* Called on a malformed property list. BADPLACE should be some | |
3167 place where truncating will form a good list -- i.e. we shouldn't | |
3168 result in a list with an odd length. */ | |
3169 | |
3170 static Lisp_Object | |
578 | 3171 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 3172 { |
3173 if (ERRB_EQ (errb, ERROR_ME)) | |
3174 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace)); | |
3175 else | |
3176 { | |
3177 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
3178 { | |
3179 warn_when_safe_lispobj | |
3180 (Qlist, Qwarning, | |
771 | 3181 list2 (build_msg_string |
428 | 3182 ("Malformed property list -- list has been truncated"), |
3183 *plist)); | |
793 | 3184 /* #### WARNING: This is more dangerous than it seems; perhaps |
3185 not a good idea. It also violates the principle of least | |
3186 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
3187 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 3188 *badplace = Qnil; |
3189 } | |
3190 return Qunbound; | |
3191 } | |
3192 } | |
3193 | |
3194 /* Called on a circular property list. BADPLACE should be some place | |
3195 where truncating will result in an even-length list, as above. | |
3196 If doesn't particularly matter where we truncate -- anywhere we | |
3197 truncate along the entire list will break the circularity, because | |
3198 it will create a terminus and the list currently doesn't have one. | |
3199 */ | |
3200 | |
3201 static Lisp_Object | |
578 | 3202 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 3203 { |
3204 if (ERRB_EQ (errb, ERROR_ME)) | |
3205 return Fsignal (Qcircular_property_list, list1 (*plist)); | |
3206 else | |
3207 { | |
3208 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
3209 { | |
3210 warn_when_safe_lispobj | |
3211 (Qlist, Qwarning, | |
771 | 3212 list2 (build_msg_string |
428 | 3213 ("Circular property list -- list has been truncated"), |
3214 *plist)); | |
793 | 3215 /* #### WARNING: This is more dangerous than it seems; perhaps |
3216 not a good idea. It also violates the principle of least | |
3217 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
3218 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 3219 *badplace = Qnil; |
3220 } | |
3221 return Qunbound; | |
3222 } | |
3223 } | |
3224 | |
3225 /* Advance the tortoise pointer by two (one iteration of a property-list | |
3226 loop) and the hare pointer by four and verify that no malformations | |
3227 or circularities exist. If so, return zero and store a value into | |
3228 RETVAL that should be returned by the calling function. Otherwise, | |
3229 return 1. See external_plist_get(). | |
3230 */ | |
3231 | |
3232 static int | |
3233 advance_plist_pointers (Lisp_Object *plist, | |
3234 Lisp_Object **tortoise, Lisp_Object **hare, | |
578 | 3235 Error_Behavior errb, Lisp_Object *retval) |
428 | 3236 { |
3237 int i; | |
3238 Lisp_Object *tortsave = *tortoise; | |
3239 | |
3240 /* Note that our "fixing" may be more brutal than necessary, | |
3241 but it's the user's own problem, not ours, if they went in and | |
3242 manually fucked up a plist. */ | |
3243 | |
3244 for (i = 0; i < 2; i++) | |
3245 { | |
3246 /* This is a standard iteration of a defensive-loop-checking | |
3247 loop. We just do it twice because we want to advance past | |
3248 both the property and its value. | |
3249 | |
3250 If the pointer indirection is confusing you, remember that | |
3251 one level of indirection on the hare and tortoise pointers | |
3252 is only due to pass-by-reference for this function. The other | |
3253 level is so that the plist can be fixed in place. */ | |
3254 | |
3255 /* When we reach the end of a well-formed plist, **HARE is | |
3256 nil. In that case, we don't do anything at all except | |
3257 advance TORTOISE by one. Otherwise, we advance HARE | |
3258 by two (making sure it's OK to do so), then advance | |
3259 TORTOISE by one (it will always be OK to do so because | |
3260 the HARE is always ahead of the TORTOISE and will have | |
3261 already verified the path), then make sure TORTOISE and | |
3262 HARE don't contain the same non-nil object -- if the | |
3263 TORTOISE and the HARE ever meet, then obviously we're | |
3264 in a circularity, and if we're in a circularity, then | |
3265 the TORTOISE and the HARE can't cross paths without | |
3266 meeting, since the HARE only gains one step over the | |
3267 TORTOISE per iteration. */ | |
3268 | |
3269 if (!NILP (**hare)) | |
3270 { | |
3271 Lisp_Object *haresave = *hare; | |
3272 if (!CONSP (**hare)) | |
3273 { | |
3274 *retval = bad_bad_bunny (plist, haresave, errb); | |
3275 return 0; | |
3276 } | |
3277 *hare = &XCDR (**hare); | |
3278 /* In a non-plist, we'd check here for a nil value for | |
3279 **HARE, which is OK (it just means the list has an | |
3280 odd number of elements). In a plist, it's not OK | |
3281 for the list to have an odd number of elements. */ | |
3282 if (!CONSP (**hare)) | |
3283 { | |
3284 *retval = bad_bad_bunny (plist, haresave, errb); | |
3285 return 0; | |
3286 } | |
3287 *hare = &XCDR (**hare); | |
3288 } | |
3289 | |
3290 *tortoise = &XCDR (**tortoise); | |
3291 if (!NILP (**hare) && EQ (**tortoise, **hare)) | |
3292 { | |
3293 *retval = bad_bad_turtle (plist, tortsave, errb); | |
3294 return 0; | |
3295 } | |
3296 } | |
3297 | |
3298 return 1; | |
3299 } | |
3300 | |
3301 /* Return the value of PROPERTY from PLIST, or Qunbound if | |
3302 property is not on the list. | |
3303 | |
3304 PLIST is a Lisp-accessible property list, meaning that it | |
3305 has to be checked for malformations and circularities. | |
3306 | |
3307 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the | |
3308 function will never signal an error; and if ERRB is ERROR_ME_WARN, | |
3309 on finding a malformation or a circularity, it issues a warning and | |
3310 attempts to silently fix the problem. | |
3311 | |
3312 A pointer to PLIST is passed in so that PLIST can be successfully | |
3313 "fixed" even if the error is at the beginning of the plist. */ | |
3314 | |
3315 Lisp_Object | |
3316 external_plist_get (Lisp_Object *plist, Lisp_Object property, | |
578 | 3317 int laxp, Error_Behavior errb) |
428 | 3318 { |
3319 Lisp_Object *tortoise = plist; | |
3320 Lisp_Object *hare = plist; | |
3321 | |
3322 while (!NILP (*tortoise)) | |
3323 { | |
3324 Lisp_Object *tortsave = tortoise; | |
3325 Lisp_Object retval; | |
3326 | |
3327 /* We do the standard tortoise/hare march. We isolate the | |
3328 grungy stuff to do this in advance_plist_pointers(), though. | |
3329 To us, all this function does is advance the tortoise | |
3330 pointer by two and the hare pointer by four and make sure | |
3331 everything's OK. We first advance the pointers and then | |
3332 check if a property matched; this ensures that our | |
3333 check for a matching property is safe. */ | |
3334 | |
3335 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3336 return retval; | |
3337 | |
3338 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3339 : internal_equal (XCAR (*tortsave), property, 0)) | |
3340 return XCAR (XCDR (*tortsave)); | |
3341 } | |
3342 | |
3343 return Qunbound; | |
3344 } | |
3345 | |
3346 /* Set PLIST's value for PROPERTY to VALUE, given a possibly | |
3347 malformed or circular plist. Analogous to external_plist_get(). */ | |
3348 | |
3349 void | |
3350 external_plist_put (Lisp_Object *plist, Lisp_Object property, | |
578 | 3351 Lisp_Object value, int laxp, Error_Behavior errb) |
428 | 3352 { |
3353 Lisp_Object *tortoise = plist; | |
3354 Lisp_Object *hare = plist; | |
3355 | |
3356 while (!NILP (*tortoise)) | |
3357 { | |
3358 Lisp_Object *tortsave = tortoise; | |
3359 Lisp_Object retval; | |
3360 | |
3361 /* See above */ | |
3362 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3363 return; | |
3364 | |
3365 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3366 : internal_equal (XCAR (*tortsave), property, 0)) | |
3367 { | |
3368 XCAR (XCDR (*tortsave)) = value; | |
3369 return; | |
3370 } | |
3371 } | |
3372 | |
3373 *plist = Fcons (property, Fcons (value, *plist)); | |
3374 } | |
3375 | |
3376 int | |
3377 external_remprop (Lisp_Object *plist, Lisp_Object property, | |
578 | 3378 int laxp, Error_Behavior errb) |
428 | 3379 { |
3380 Lisp_Object *tortoise = plist; | |
3381 Lisp_Object *hare = plist; | |
3382 | |
3383 while (!NILP (*tortoise)) | |
3384 { | |
3385 Lisp_Object *tortsave = tortoise; | |
3386 Lisp_Object retval; | |
3387 | |
3388 /* See above */ | |
3389 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
3390 return 0; | |
3391 | |
3392 if (!laxp ? EQ (XCAR (*tortsave), property) | |
3393 : internal_equal (XCAR (*tortsave), property, 0)) | |
3394 { | |
3395 /* Now you see why it's so convenient to have that level | |
3396 of indirection. */ | |
3397 *tortsave = XCDR (XCDR (*tortsave)); | |
3398 return 1; | |
3399 } | |
3400 } | |
3401 | |
3402 return 0; | |
3403 } | |
3404 | |
3405 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /* | |
3406 Extract a value from a property list. | |
3407 PLIST is a property list, which is a list of the form | |
444 | 3408 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...). |
3409 PROPERTY is usually a symbol. | |
3410 This function returns the value corresponding to the PROPERTY, | |
3411 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 3412 */ |
444 | 3413 (plist, property, default_)) |
428 | 3414 { |
444 | 3415 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME); |
3416 return UNBOUNDP (value) ? default_ : value; | |
428 | 3417 } |
3418 | |
3419 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /* | |
444 | 3420 Change value in PLIST of PROPERTY to VALUE. |
3421 PLIST is a property list, which is a list of the form | |
3422 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
3423 PROPERTY is usually a symbol and VALUE is any object. | |
3424 If PROPERTY is already a property on the list, its value is set to VALUE, | |
3425 otherwise the new PROPERTY VALUE pair is added. | |
3426 The new plist is returned; use `(setq x (plist-put x property value))' | |
3427 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 3428 */ |
444 | 3429 (plist, property, value)) |
428 | 3430 { |
444 | 3431 external_plist_put (&plist, property, value, 0, ERROR_ME); |
428 | 3432 return plist; |
3433 } | |
3434 | |
3435 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /* | |
444 | 3436 Remove from PLIST the property PROPERTY and its value. |
3437 PLIST is a property list, which is a list of the form | |
3438 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
3439 PROPERTY is usually a symbol. | |
3440 The new plist is returned; use `(setq x (plist-remprop x property))' | |
3441 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 3442 */ |
444 | 3443 (plist, property)) |
428 | 3444 { |
444 | 3445 external_remprop (&plist, property, 0, ERROR_ME); |
428 | 3446 return plist; |
3447 } | |
3448 | |
3449 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /* | |
444 | 3450 Return t if PROPERTY has a value specified in PLIST. |
428 | 3451 */ |
444 | 3452 (plist, property)) |
428 | 3453 { |
444 | 3454 Lisp_Object value = Fplist_get (plist, property, Qunbound); |
3455 return UNBOUNDP (value) ? Qnil : Qt; | |
428 | 3456 } |
3457 | |
3458 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /* | |
3459 Given a plist, signal an error if there is anything wrong with it. | |
3460 This means that it's a malformed or circular plist. | |
3461 */ | |
3462 (plist)) | |
3463 { | |
3464 Lisp_Object *tortoise; | |
3465 Lisp_Object *hare; | |
3466 | |
3467 start_over: | |
3468 tortoise = &plist; | |
3469 hare = &plist; | |
3470 while (!NILP (*tortoise)) | |
3471 { | |
3472 Lisp_Object retval; | |
3473 | |
3474 /* See above */ | |
3475 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME, | |
3476 &retval)) | |
3477 goto start_over; | |
3478 } | |
3479 | |
3480 return Qnil; | |
3481 } | |
3482 | |
3483 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /* | |
3484 Given a plist, return non-nil if its format is correct. | |
3485 If it returns nil, `check-valid-plist' will signal an error when given | |
442 | 3486 the plist; that means it's a malformed or circular plist. |
428 | 3487 */ |
3488 (plist)) | |
3489 { | |
3490 Lisp_Object *tortoise; | |
3491 Lisp_Object *hare; | |
3492 | |
3493 tortoise = &plist; | |
3494 hare = &plist; | |
3495 while (!NILP (*tortoise)) | |
3496 { | |
3497 Lisp_Object retval; | |
3498 | |
3499 /* See above */ | |
3500 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT, | |
3501 &retval)) | |
3502 return Qnil; | |
3503 } | |
3504 | |
3505 return Qt; | |
3506 } | |
3507 | |
3508 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /* | |
3509 Destructively remove any duplicate entries from a plist. | |
3510 In such cases, the first entry applies. | |
3511 | |
3512 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3513 a nil value is removed. This feature is a virus that has infected | |
3514 old Lisp implementations, but should not be used except for backward | |
3515 compatibility. | |
3516 | |
3517 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
3518 return value may not be EQ to the passed-in value, so make sure to | |
3519 `setq' the value back into where it came from. | |
3520 */ | |
3521 (plist, nil_means_not_present)) | |
3522 { | |
3523 Lisp_Object head = plist; | |
3524 | |
3525 Fcheck_valid_plist (plist); | |
3526 | |
3527 while (!NILP (plist)) | |
3528 { | |
3529 Lisp_Object prop = Fcar (plist); | |
3530 Lisp_Object next = Fcdr (plist); | |
3531 | |
3532 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
3533 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
3534 { | |
3535 if (EQ (head, plist)) | |
3536 head = Fcdr (next); | |
3537 plist = Fcdr (next); | |
3538 continue; | |
3539 } | |
3540 /* external_remprop returns 1 if it removed any property. | |
3541 We have to loop till it didn't remove anything, in case | |
3542 the property occurs many times. */ | |
3543 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME)) | |
3544 DO_NOTHING; | |
3545 plist = Fcdr (next); | |
3546 } | |
3547 | |
3548 return head; | |
3549 } | |
3550 | |
3551 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /* | |
3552 Extract a value from a lax property list. | |
444 | 3553 LAX-PLIST is a lax property list, which is a list of the form |
3554 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3555 properties is done using `equal' instead of `eq'. | |
3556 PROPERTY is usually a symbol. | |
3557 This function returns the value corresponding to PROPERTY, | |
3558 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 3559 */ |
444 | 3560 (lax_plist, property, default_)) |
428 | 3561 { |
444 | 3562 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME); |
3563 return UNBOUNDP (value) ? default_ : value; | |
428 | 3564 } |
3565 | |
3566 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /* | |
444 | 3567 Change value in LAX-PLIST of PROPERTY to VALUE. |
3568 LAX-PLIST is a lax property list, which is a list of the form | |
3569 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3570 properties is done using `equal' instead of `eq'. | |
3571 PROPERTY is usually a symbol and VALUE is any object. | |
3572 If PROPERTY is already a property on the list, its value is set to | |
3573 VALUE, otherwise the new PROPERTY VALUE pair is added. | |
3574 The new plist is returned; use `(setq x (lax-plist-put x property value))' | |
3575 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 3576 */ |
444 | 3577 (lax_plist, property, value)) |
428 | 3578 { |
444 | 3579 external_plist_put (&lax_plist, property, value, 1, ERROR_ME); |
428 | 3580 return lax_plist; |
3581 } | |
3582 | |
3583 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /* | |
444 | 3584 Remove from LAX-PLIST the property PROPERTY and its value. |
3585 LAX-PLIST is a lax property list, which is a list of the form | |
3586 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3587 properties is done using `equal' instead of `eq'. | |
3588 PROPERTY is usually a symbol. | |
3589 The new plist is returned; use `(setq x (lax-plist-remprop x property))' | |
3590 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 3591 */ |
444 | 3592 (lax_plist, property)) |
428 | 3593 { |
444 | 3594 external_remprop (&lax_plist, property, 1, ERROR_ME); |
428 | 3595 return lax_plist; |
3596 } | |
3597 | |
3598 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /* | |
444 | 3599 Return t if PROPERTY has a value specified in LAX-PLIST. |
3600 LAX-PLIST is a lax property list, which is a list of the form | |
3601 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
3602 properties is done using `equal' instead of `eq'. | |
428 | 3603 */ |
444 | 3604 (lax_plist, property)) |
428 | 3605 { |
444 | 3606 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt; |
428 | 3607 } |
3608 | |
3609 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /* | |
3610 Destructively remove any duplicate entries from a lax plist. | |
3611 In such cases, the first entry applies. | |
3612 | |
3613 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
3614 a nil value is removed. This feature is a virus that has infected | |
3615 old Lisp implementations, but should not be used except for backward | |
3616 compatibility. | |
3617 | |
3618 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
3619 return value may not be EQ to the passed-in value, so make sure to | |
3620 `setq' the value back into where it came from. | |
3621 */ | |
3622 (lax_plist, nil_means_not_present)) | |
3623 { | |
3624 Lisp_Object head = lax_plist; | |
3625 | |
3626 Fcheck_valid_plist (lax_plist); | |
3627 | |
3628 while (!NILP (lax_plist)) | |
3629 { | |
3630 Lisp_Object prop = Fcar (lax_plist); | |
3631 Lisp_Object next = Fcdr (lax_plist); | |
3632 | |
3633 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
3634 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
3635 { | |
3636 if (EQ (head, lax_plist)) | |
3637 head = Fcdr (next); | |
3638 lax_plist = Fcdr (next); | |
3639 continue; | |
3640 } | |
3641 /* external_remprop returns 1 if it removed any property. | |
3642 We have to loop till it didn't remove anything, in case | |
3643 the property occurs many times. */ | |
3644 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME)) | |
3645 DO_NOTHING; | |
3646 lax_plist = Fcdr (next); | |
3647 } | |
3648 | |
3649 return head; | |
3650 } | |
3651 | |
3652 /* In C because the frame props stuff uses it */ | |
3653 | |
3654 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /* | |
3655 Convert association list ALIST into the equivalent property-list form. | |
3656 The plist is returned. This converts from | |
3657 | |
3658 \((a . 1) (b . 2) (c . 3)) | |
3659 | |
3660 into | |
3661 | |
3662 \(a 1 b 2 c 3) | |
3663 | |
3664 The original alist is destroyed in the process of constructing the plist. | |
3665 See also `alist-to-plist'. | |
3666 */ | |
3667 (alist)) | |
3668 { | |
3669 Lisp_Object head = alist; | |
3670 while (!NILP (alist)) | |
3671 { | |
3672 /* remember the alist element. */ | |
3673 Lisp_Object el = Fcar (alist); | |
3674 | |
3675 Fsetcar (alist, Fcar (el)); | |
3676 Fsetcar (el, Fcdr (el)); | |
3677 Fsetcdr (el, Fcdr (alist)); | |
3678 Fsetcdr (alist, el); | |
3679 alist = Fcdr (Fcdr (alist)); | |
3680 } | |
3681 | |
3682 return head; | |
3683 } | |
3684 | |
3685 DEFUN ("get", Fget, 2, 3, 0, /* | |
442 | 3686 Return the value of OBJECT's PROPERTY property. |
3687 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'. | |
428 | 3688 If there is no such property, return optional third arg DEFAULT |
442 | 3689 \(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
|
3690 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
|
3691 `object-setplist'. |
428 | 3692 */ |
442 | 3693 (object, property, default_)) |
428 | 3694 { |
3695 /* Various places in emacs call Fget() and expect it not to quit, | |
3696 so don't quit. */ | |
442 | 3697 Lisp_Object val; |
3698 | |
3699 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop) | |
3700 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property); | |
428 | 3701 else |
563 | 3702 invalid_operation ("Object type has no properties", object); |
442 | 3703 |
3704 return UNBOUNDP (val) ? default_ : val; | |
428 | 3705 } |
3706 | |
3707 DEFUN ("put", Fput, 3, 3, 0, /* | |
442 | 3708 Set OBJECT's PROPERTY to VALUE. |
3709 It can be subsequently retrieved with `(get OBJECT PROPERTY)'. | |
3710 OBJECT can be a symbol, face, extent, or string. | |
428 | 3711 For a string, no properties currently have predefined meanings. |
3712 For the predefined properties for extents, see `set-extent-property'. | |
3713 For the predefined properties for faces, see `set-face-property'. | |
3714 See also `get', `remprop', and `object-plist'. | |
3715 */ | |
442 | 3716 (object, property, value)) |
428 | 3717 { |
1920 | 3718 /* This function cannot GC */ |
428 | 3719 CHECK_LISP_WRITEABLE (object); |
3720 | |
442 | 3721 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop) |
428 | 3722 { |
442 | 3723 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop |
3724 (object, property, value)) | |
563 | 3725 invalid_change ("Can't set property on object", property); |
428 | 3726 } |
3727 else | |
563 | 3728 invalid_change ("Object type has no settable properties", object); |
428 | 3729 |
3730 return value; | |
3731 } | |
3732 | |
3733 DEFUN ("remprop", Fremprop, 2, 2, 0, /* | |
442 | 3734 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
|
3735 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
|
3736 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
|
3737 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
|
3738 and `object-setplist'. |
428 | 3739 */ |
442 | 3740 (object, property)) |
428 | 3741 { |
442 | 3742 int ret = 0; |
3743 | |
428 | 3744 CHECK_LISP_WRITEABLE (object); |
3745 | |
442 | 3746 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop) |
428 | 3747 { |
442 | 3748 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property); |
3749 if (ret == -1) | |
563 | 3750 invalid_change ("Can't remove property from object", property); |
428 | 3751 } |
3752 else | |
563 | 3753 invalid_change ("Object type has no removable properties", object); |
442 | 3754 |
3755 return ret ? Qt : Qnil; | |
428 | 3756 } |
3757 | |
3758 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /* | |
442 | 3759 Return a property list of OBJECT's properties. |
3760 For a symbol, this is equivalent to `symbol-plist'. | |
3761 OBJECT can be a symbol, string, extent, face, or glyph. | |
3762 Do not modify the returned property list directly; | |
3763 this may or may not have the desired effects. Use `put' instead. | |
428 | 3764 */ |
3765 (object)) | |
3766 { | |
442 | 3767 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist) |
3768 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object); | |
428 | 3769 else |
563 | 3770 invalid_operation ("Object type has no properties", object); |
428 | 3771 |
3772 return Qnil; | |
3773 } | |
3774 | |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3775 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
|
3776 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
|
3777 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
|
3778 |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3779 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
|
3780 not allow their modification with `object-setplist'. |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3781 */ |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3782 (object, newplist)) |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3783 { |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3784 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
|
3785 { |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3786 return XRECORD_LHEADER_IMPLEMENTATION (object)->setplist (object, |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3787 newplist); |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3788 } |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3789 |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3790 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
|
3791 return Qnil; |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3792 } |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3793 |
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
3794 |
428 | 3795 |
853 | 3796 static Lisp_Object |
3797 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2, | |
3798 Lisp_Object depth) | |
3799 { | |
3800 return make_int (internal_equal (obj1, obj2, XINT (depth))); | |
3801 } | |
3802 | |
3803 int | |
3804 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
|
3805 const Ascbyte *warning_string, |
853 | 3806 int flags, |
3807 struct call_trapping_problems_result *p, | |
3808 int retval, | |
3809 Lisp_Object obj1, Lisp_Object obj2, | |
3810 int depth) | |
3811 { | |
3812 Lisp_Object glorp = | |
3813 va_call_trapping_problems (warning_class, warning_string, | |
3814 flags, p, | |
3815 (lisp_fn_t) tweaked_internal_equal, | |
3816 3, obj1, obj2, make_int (depth)); | |
3817 if (UNBOUNDP (glorp)) | |
3818 return retval; | |
3819 else | |
3820 return XINT (glorp); | |
3821 } | |
3822 | |
428 | 3823 int |
3824 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3825 { | |
3826 if (depth > 200) | |
563 | 3827 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3828 QUIT; |
3829 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
3830 return 1; | |
3831 /* Note that (equal 20 20.0) should be nil */ | |
3832 if (XTYPE (obj1) != XTYPE (obj2)) | |
3833 return 0; | |
3834 if (LRECORDP (obj1)) | |
3835 { | |
442 | 3836 const struct lrecord_implementation |
428 | 3837 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), |
3838 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3839 | |
3840 return (imp1 == imp2) && | |
3841 /* 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
|
3842 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 0)); |
428 | 3843 } |
3844 | |
3845 return 0; | |
3846 } | |
3847 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3848 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
|
3849 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3850 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
|
3851 ARRAY_STRING, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3852 ARRAY_VECTOR, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3853 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
|
3854 }; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3855 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3856 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
|
3857 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
|
3858 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3859 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
|
3860 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
|
3861 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
|
3862 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
|
3863 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
|
3864 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
|
3865 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
|
3866 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3867 |
801 | 3868 int |
3869 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3870 { | |
3871 if (depth > 200) | |
3872 stack_overflow ("Stack overflow in equalp", Qunbound); | |
3873 QUIT; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3874 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3875 /* 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
|
3876 of two equal fixnums or the same object seen twice. */ |
801 | 3877 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) |
3878 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
|
3879 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3880 /* 2. If both numbers, compare with `='. */ |
1983 | 3881 if (NUMBERP (obj1) && NUMBERP (obj2)) |
3882 { | |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
3883 return (0 == bytecode_arithcompare (obj1, obj2)); |
1983 | 3884 } |
4906
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 /* 3. If characters, compare case-insensitively. */ |
801 | 3887 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
|
3888 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
|
3889 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3890 /* 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
|
3891 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
|
3892 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3893 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
|
3894 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
|
3895 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
|
3896 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
|
3897 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3898 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
|
3899 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
|
3900 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
|
3901 /* 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
|
3902 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
|
3903 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3904 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
|
3905 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
|
3906 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
|
3907 return 0; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3908 return 1; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3909 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3910 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3911 /* 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
|
3912 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
|
3913 their contents, the equal() method will call internal_equal_0(). */ |
801 | 3914 if (XTYPE (obj1) != XTYPE (obj2)) |
3915 return 0; | |
3916 if (LRECORDP (obj1)) | |
3917 { | |
3918 const struct lrecord_implementation | |
3919 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), | |
3920 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
3921 | |
3922 return (imp1 == imp2) && | |
3923 /* 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
|
3924 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 1)); |
801 | 3925 } |
3926 | |
3927 return 0; | |
3928 } | |
3929 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3930 int |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3931 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
|
3932 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3933 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3934 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
|
3935 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3936 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
|
3937 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3938 |
428 | 3939 /* Note that we may be calling sub-objects that will use |
3940 internal_equal() (instead of internal_old_equal()). Oh well. | |
3941 We will get an Ebola note if there's any possibility of confusion, | |
3942 but that seems unlikely. */ | |
3943 | |
3944 static int | |
3945 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
3946 { | |
3947 if (depth > 200) | |
563 | 3948 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 3949 QUIT; |
3950 if (HACKEQ_UNSAFE (obj1, obj2)) | |
3951 return 1; | |
3952 /* Note that (equal 20 20.0) should be nil */ | |
3953 if (XTYPE (obj1) != XTYPE (obj2)) | |
3954 return 0; | |
3955 | |
3956 return internal_equal (obj1, obj2, depth); | |
3957 } | |
3958 | |
3959 DEFUN ("equal", Fequal, 2, 2, 0, /* | |
3960 Return t if two Lisp objects have similar structure and contents. | |
3961 They must have the same data type. | |
3962 Conses are compared by comparing the cars and the cdrs. | |
3963 Vectors and strings are compared element by element. | |
3964 Numbers are compared by value. Symbols must match exactly. | |
3965 */ | |
444 | 3966 (object1, object2)) |
428 | 3967 { |
444 | 3968 return internal_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 3969 } |
3970 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3971 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
|
3972 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
|
3973 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3974 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
|
3975 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
|
3976 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
|
3977 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3978 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
|
3979 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
|
3980 `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
|
3981 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3982 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
|
3983 `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
|
3984 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
|
3985 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
|
3986 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
|
3987 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
|
3988 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
|
3989 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
|
3990 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3991 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
|
3992 (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
|
3993 `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
|
3994 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
|
3995 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
|
3996 */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3997 (object1, object2)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3998 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
3999 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
|
4000 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4001 |
428 | 4002 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* |
4003 Return t if two Lisp objects have similar structure and contents. | |
4004 They must have the same data type. | |
4005 \(Note, however, that an exception is made for characters and integers; | |
4006 this is known as the "char-int confoundance disease." See `eq' and | |
4007 `old-eq'.) | |
4008 This function is provided only for byte-code compatibility with v19. | |
4009 Do not use it. | |
4010 */ | |
444 | 4011 (object1, object2)) |
428 | 4012 { |
444 | 4013 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 4014 } |
4015 | |
4016 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4017 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
|
4018 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
|
4019 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
|
4020 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
|
4021 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
|
4022 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
|
4023 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4024 /* 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
|
4025 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
|
4026 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
|
4027 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
|
4028 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
|
4029 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4030 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
|
4031 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
|
4032 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
|
4033 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
|
4034 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
|
4035 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
|
4036 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4037 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
|
4038 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4039 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4040 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
|
4041 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
|
4042 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
|
4043 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4044 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
|
4045 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
|
4046 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
|
4047 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
|
4048 |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4049 arguments: (SEQUENCE ITEM &key (START 0) (END (length SEQUENCE))) |
428 | 4050 */ |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4051 (int nargs, Lisp_Object *args)) |
428 | 4052 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4053 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
|
4054 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
|
4055 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
|
4056 |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
4057 PARSE_KEYWORDS (Ffill, nargs, args, 2, (start, end), (start = Qzero)); |
5182
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 CHECK_NATNUM (start); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4060 starting = XINT (start); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4061 |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4062 if (!NILP (end)) |
428 | 4063 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4064 CHECK_NATNUM (end); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4065 ending = XINT (end); |
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 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4068 retry: |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4069 if (STRINGP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4070 { |
428 | 4071 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
|
4072 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
|
4073 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4074 fill_string_range (sequence, item, start, end); |
428 | 4075 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4076 else if (VECTORP (sequence)) |
428 | 4077 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4078 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
|
4079 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4080 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
|
4081 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
|
4082 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4083 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
|
4084 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
|
4085 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4086 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
|
4087 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4088 p[ii] = item; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4089 } |
428 | 4090 } |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4091 else if (BIT_VECTORP (sequence)) |
428 | 4092 { |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4093 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence); |
428 | 4094 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
|
4095 |
428 | 4096 CHECK_BIT (item); |
444 | 4097 bit = XINT (item); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4098 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
|
4099 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
|
4100 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4101 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
|
4102 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
|
4103 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4104 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
|
4105 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4106 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
|
4107 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4108 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4109 else if (LISTP (sequence)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4110 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4111 Elemcount counting = 0; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4112 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4113 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
|
4114 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4115 if (counting >= starting) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4116 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4117 if (counting < ending) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4118 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4119 XSETCAR (tail, item); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4120 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4121 else if (counting == ending) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4122 { |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4123 break; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4124 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4125 } |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4126 ++counting; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4127 } |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4128 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
4129 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
|
4130 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
4131 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
|
4132 } |
428 | 4133 } |
4134 else | |
4135 { | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4136 sequence = wrong_type_argument (Qsequencep, sequence); |
428 | 4137 goto retry; |
4138 } | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
4139 return sequence; |
428 | 4140 } |
4141 | |
4142 Lisp_Object | |
4143 nconc2 (Lisp_Object arg1, Lisp_Object arg2) | |
4144 { | |
4145 Lisp_Object args[2]; | |
4146 struct gcpro gcpro1; | |
4147 args[0] = arg1; | |
4148 args[1] = arg2; | |
4149 | |
4150 GCPRO1 (args[0]); | |
4151 gcpro1.nvars = 2; | |
4152 | |
4153 RETURN_UNGCPRO (bytecode_nconc2 (args)); | |
4154 } | |
4155 | |
4156 Lisp_Object | |
4157 bytecode_nconc2 (Lisp_Object *args) | |
4158 { | |
4159 retry: | |
4160 | |
4161 if (CONSP (args[0])) | |
4162 { | |
4163 /* (setcdr (last args[0]) args[1]) */ | |
4164 Lisp_Object tortoise, hare; | |
665 | 4165 Elemcount count; |
428 | 4166 |
4167 for (hare = tortoise = args[0], count = 0; | |
4168 CONSP (XCDR (hare)); | |
4169 hare = XCDR (hare), count++) | |
4170 { | |
4171 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
4172 | |
4173 if (count & 1) | |
4174 tortoise = XCDR (tortoise); | |
4175 if (EQ (hare, tortoise)) | |
4176 signal_circular_list_error (args[0]); | |
4177 } | |
4178 XCDR (hare) = args[1]; | |
4179 return args[0]; | |
4180 } | |
4181 else if (NILP (args[0])) | |
4182 { | |
4183 return args[1]; | |
4184 } | |
4185 else | |
4186 { | |
4187 args[0] = wrong_type_argument (args[0], Qlistp); | |
4188 goto retry; | |
4189 } | |
4190 } | |
4191 | |
4192 DEFUN ("nconc", Fnconc, 0, MANY, 0, /* | |
4193 Concatenate any number of lists by altering them. | |
4194 Only the last argument is not altered, and need not be a list. | |
4195 Also see: `append'. | |
4196 If the first argument is nil, there is no way to modify it by side | |
4197 effect; therefore, write `(setq foo (nconc foo list))' to be sure of | |
4198 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
|
4199 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
4200 arguments: (&rest ARGS) |
428 | 4201 */ |
4202 (int nargs, Lisp_Object *args)) | |
4203 { | |
4204 int argnum = 0; | |
4205 struct gcpro gcpro1; | |
4206 | |
4207 /* The modus operandi in Emacs is "caller gc-protects args". | |
4208 However, nconc (particularly nconc2 ()) is called many times | |
4209 in Emacs on freshly created stuff (e.g. you see the idiom | |
4210 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those | |
4211 callers out by protecting the args ourselves to save them | |
4212 a lot of temporary-variable grief. */ | |
4213 | |
4214 GCPRO1 (args[0]); | |
4215 gcpro1.nvars = nargs; | |
4216 | |
4217 while (argnum < nargs) | |
4218 { | |
4219 Lisp_Object val; | |
4220 retry: | |
4221 val = args[argnum]; | |
4222 if (CONSP (val)) | |
4223 { | |
4224 /* `val' is the first cons, which will be our return value. */ | |
4225 /* `last_cons' will be the cons cell to mutate. */ | |
4226 Lisp_Object last_cons = val; | |
4227 Lisp_Object tortoise = val; | |
4228 | |
4229 for (argnum++; argnum < nargs; argnum++) | |
4230 { | |
4231 Lisp_Object next = args[argnum]; | |
4232 retry_next: | |
4233 if (CONSP (next) || argnum == nargs -1) | |
4234 { | |
4235 /* (setcdr (last val) next) */ | |
665 | 4236 Elemcount count; |
428 | 4237 |
4238 for (count = 0; | |
4239 CONSP (XCDR (last_cons)); | |
4240 last_cons = XCDR (last_cons), count++) | |
4241 { | |
4242 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
4243 | |
4244 if (count & 1) | |
4245 tortoise = XCDR (tortoise); | |
4246 if (EQ (last_cons, tortoise)) | |
4247 signal_circular_list_error (args[argnum-1]); | |
4248 } | |
4249 XCDR (last_cons) = next; | |
4250 } | |
4251 else if (NILP (next)) | |
4252 { | |
4253 continue; | |
4254 } | |
4255 else | |
4256 { | |
4257 next = wrong_type_argument (Qlistp, next); | |
4258 goto retry_next; | |
4259 } | |
4260 } | |
4261 RETURN_UNGCPRO (val); | |
4262 } | |
4263 else if (NILP (val)) | |
4264 argnum++; | |
4265 else if (argnum == nargs - 1) /* last arg? */ | |
4266 RETURN_UNGCPRO (val); | |
4267 else | |
4268 { | |
4269 args[argnum] = wrong_type_argument (Qlistp, val); | |
4270 goto retry; | |
4271 } | |
4272 } | |
4273 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */ | |
4274 } | |
4275 | |
4276 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4277 /* 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
|
4278 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
|
4279 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
|
4280 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
|
4281 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
|
4282 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
|
4283 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4284 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
|
4285 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
|
4286 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
|
4287 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
|
4288 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
|
4289 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
|
4290 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4291 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
|
4292 Qnil); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4293 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4294 |
434 | 4295 /* 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
|
4296 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4297 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
|
4298 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
|
4299 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
|
4300 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
|
4301 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
|
4302 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
|
4303 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4304 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
|
4305 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
|
4306 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
|
4307 mapcarX. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4308 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4309 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
|
4310 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
|
4311 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
|
4312 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
|
4313 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
|
4314 traversal operation. |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4315 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4316 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
|
4317 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
|
4318 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4319 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
|
4320 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
|
4321 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
|
4322 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
|
4323 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
|
4324 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
|
4325 otherwise it will be left alone. */ |
428 | 4326 |
4327 static void | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4328 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
|
4329 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
|
4330 Lisp_Object caller) |
428 | 4331 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4332 Lisp_Object called, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4333 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
|
4334 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
|
4335 int i, j; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4336 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4337 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
|
4338 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4339 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
|
4340 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4341 for (i = 1; i <= nsequences; ++i) |
428 | 4342 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4343 args[i] = Qnil; |
428 | 4344 } |
4345 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4346 if (vals != NULL) |
428 | 4347 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4348 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
|
4349 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4350 gcpro2.nvars = 0; |
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 else |
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 GCPRO1 (args[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4355 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4356 } |
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 /* 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
|
4359 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
|
4360 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
|
4361 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
|
4362 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
|
4363 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4364 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
|
4365 Lisp_Object *val = vals; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4366 for (i = 0; i < call_count; ++i) |
434 | 4367 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4368 *val++ = XCAR (lst); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4369 lst = XCDR (lst); |
428 | 4370 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4371 gcpro2.nvars = call_count; |
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 for (i = 0; i < call_count; ++i) |
428 | 4374 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4375 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
|
4376 vals[i] = IGNORE_MULTIPLE_VALUES (Ffuncall (nsequences + 1, args)); |
428 | 4377 } |
4378 } | |
4379 else | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4380 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4381 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
|
4382 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
|
4383 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
|
4384 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4385 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
|
4386 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4387 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4388 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
|
4389 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4390 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
|
4391 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4392 lisp_vals_type |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4393 = (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
|
4394 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4395 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
|
4396 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4397 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
|
4398 = 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
|
4399 } |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4400 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4401 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4402 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
|
4403 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4404 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
|
4405 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4406 switch (sequence_types[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4407 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4408 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4409 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4410 if (!CONSP (sequences[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4411 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4412 /* 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
|
4413 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
|
4414 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
|
4415 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
|
4416 callers. */ |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4417 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
|
4418 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4419 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
|
4420 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
|
4421 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4422 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4423 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4424 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4425 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
|
4426 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4427 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4428 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4429 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4430 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
|
4431 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4432 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4433 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
|
4434 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4435 args[j + 1] |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4436 = 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
|
4437 i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4438 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4439 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4440 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4441 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4442 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4443 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4444 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
|
4445 if (vals != NULL) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4446 { |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4447 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
|
4448 gcpro2.nvars += 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4449 } |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4450 else if (EQ (Qsome, caller)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4451 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4452 if (!NILP (IGNORE_MULTIPLE_VALUES (called))) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4453 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4454 Lisp_Object *result |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4455 = (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
|
4456 *result = called; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4457 UNGCPRO; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4458 return; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4459 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4460 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4461 else if (EQ (Qevery, caller)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4462 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4463 if (NILP (IGNORE_MULTIPLE_VALUES (called))) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4464 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4465 Lisp_Object *result |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4466 = (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
|
4467 *result = Qnil; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4468 UNGCPRO; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4469 return; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4470 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4471 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4472 else |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4473 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4474 called = IGNORE_MULTIPLE_VALUES (called); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4475 switch (lisp_vals_type) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4476 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4477 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
|
4478 /* Discard the result of funcall. */ |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4479 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4480 case lrecord_type_cons: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4481 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4482 if (!CONSP (lisp_vals)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4483 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4484 /* 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
|
4485 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
|
4486 relevant part, error. */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4487 mapping_interaction_error (caller, lisp_vals); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4488 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4489 XSETCAR (lisp_vals, called); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4490 lisp_vals = XCDR (lisp_vals); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4491 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4492 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4493 case lrecord_type_vector: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4494 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4495 i < XVECTOR_LENGTH (lisp_vals) ? |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4496 (XVECTOR_DATA (lisp_vals)[i] = called) : |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4497 /* Let #'aset error. */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4498 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
|
4499 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4500 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4501 case lrecord_type_string: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4502 { |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4503 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
|
4504 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
|
4505 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4506 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4507 case lrecord_type_bit_vector: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4508 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4509 (BITP (called) && |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4510 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
|
4511 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
|
4512 XINT (called)) : |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4513 (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
|
4514 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4515 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4516 default: |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4517 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4518 ABORT(); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4519 break; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4520 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4521 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4522 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4523 } |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4524 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4525 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
|
4526 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
|
4527 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4528 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
|
4529 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
|
4530 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4531 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
4532 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4533 UNGCPRO; |
428 | 4534 } |
4535 | |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4536 /* 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
|
4537 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
|
4538 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
|
4539 static Elemcount |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4540 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
|
4541 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4542 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
|
4543 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
|
4544 int i; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4545 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4546 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
|
4547 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4548 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
|
4549 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4550 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
|
4551 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
|
4552 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4553 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
|
4554 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4555 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4556 else |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4557 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4558 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
|
4559 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
|
4560 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
|
4561 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4562 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4563 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4564 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
|
4565 { |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4566 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
|
4567 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4568 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4569 return len; |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4570 } |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4571 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4572 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
|
4573 Call FUNCTION on each element of SEQUENCE, and concat results to a string. |
751 | 4574 Between each pair of results, insert SEPARATOR. |
4575 | |
4576 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR | |
4577 results in spaces between the values returned by FUNCTION. SEQUENCE itself | |
4578 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
|
4579 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4580 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
|
4581 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
|
4582 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
|
4583 `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
|
4584 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4585 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES) |
428 | 4586 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4587 (int nargs, Lisp_Object *args)) |
428 | 4588 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4589 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
|
4590 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
|
4591 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
|
4592 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
|
4593 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4594 EMACS_INT i, nargs0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4595 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4596 args[2] = sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4597 args[1] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4598 |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4599 len = shortest_length_among_sequences (nargs - 2, args + 2); |
428 | 4600 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
4601 if (len == 0) return build_ascstring (""); |
428 | 4602 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4603 nargs0 = len + len - 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4604 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
|
4605 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4606 /* 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
|
4607 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
|
4608 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
|
4609 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
|
4610 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4611 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
|
4612 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4613 args0[i] = XCAR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4614 sequence = XCDR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4615 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4616 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4617 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4618 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4619 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
|
4620 } |
428 | 4621 |
4622 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
|
4623 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
|
4624 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4625 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
|
4626 args0[i] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4627 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4628 return Fconcat (nargs0, args0); |
428 | 4629 } |
4630 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4631 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
|
4632 Call FUNCTION on each element of SEQUENCE; return a list of the results. |
434 | 4633 The result is a list of the same length as SEQUENCE. |
428 | 4634 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
|
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 `mapcar' |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4639 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) |
428 | 4642 */ |
4995
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)) |
428 | 4644 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4645 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
|
4646 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
|
4647 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4648 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4649 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
|
4650 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
|
4651 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4652 return Flist ((int) len, args0); |
428 | 4653 } |
4654 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4655 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
|
4656 Call FUNCTION on each element of SEQUENCE; return a vector of the results. |
428 | 4657 The result is a vector of the same length as SEQUENCE. |
434 | 4658 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
|
4659 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4660 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
|
4661 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
|
4662 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
|
4663 `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
|
4664 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4665 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4666 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4667 (int nargs, Lisp_Object *args)) |
428 | 4668 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4669 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
|
4670 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
|
4671 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
|
4672 |
428 | 4673 struct gcpro gcpro1; |
4674 GCPRO1 (result); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4675 /* 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
|
4676 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
|
4677 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
|
4678 Qmapvector); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4679 RETURN_UNGCPRO (result); |
428 | 4680 } |
4681 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4682 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
|
4683 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
|
4684 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4685 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
|
4686 together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4687 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4688 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
|
4689 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
|
4690 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
|
4691 `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
|
4692 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4693 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
|
4694 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4695 (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
|
4696 { |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4697 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
|
4698 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
|
4699 |
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4700 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
|
4701 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4702 /* #'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
|
4703 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
|
4704 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4705 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4706 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
|
4707 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
|
4708 |
428 | 4709 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4710 This function is like `mapcar' but does not accumulate the results, | |
4711 which is more efficient if you do not use the results. | |
4712 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4713 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
|
4714 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
|
4715 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
|
4716 `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
|
4717 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4718 Return SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4719 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4720 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
|
4721 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4722 (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
|
4723 { |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4724 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
|
4725 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
|
4726 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4727 /* 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
|
4728 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
|
4729 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
|
4730 GCPRO1 (sequence); |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4731 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
|
4732 RETURN_UNGCPRO (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4733 } |
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 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
|
4736 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
|
4737 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4738 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
|
4739 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
|
4740 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4741 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
|
4742 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
|
4743 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4744 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
|
4745 `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
|
4746 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
|
4747 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4748 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 4749 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4750 (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
|
4751 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4752 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
|
4753 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
|
4754 Lisp_Object result = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4755 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
|
4756 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
|
4757 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4758 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4759 if (!NILP (type)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4760 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4761 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
|
4762 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4763 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4764 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
|
4765 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4766 if (EQ (type, Qnil)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4767 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4768 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4769 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4770 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4771 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
|
4772 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4773 result = Fvector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4774 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4775 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
|
4776 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4777 result = Fstring (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4778 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4779 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
|
4780 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4781 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4782 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4783 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
|
4784 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4785 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
|
4786 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4787 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4788 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4789 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4790 GCPRO1 (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4791 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
|
4792 UNGCPRO; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4793 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4794 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4795 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4796 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4797 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4798 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
|
4799 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
|
4800 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4801 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
|
4802 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4803 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
|
4804 \(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
|
4805 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
|
4806 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
|
4807 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4808 Return RESULT-SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4809 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4810 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
|
4811 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4812 (int nargs, Lisp_Object *args)) |
428 | 4813 { |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4814 Elemcount len; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4815 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
|
4816 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
|
4817 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4818 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4819 args[1] = result_sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4820 |
5273
799742b751c8
Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5272
diff
changeset
|
4821 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
|
4822 |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4823 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
|
4824 Qmap_into); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4825 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4826 return result_sequence; |
428 | 4827 } |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4828 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4829 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
|
4830 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
|
4831 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4832 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
|
4833 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4834 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
|
4835 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
|
4836 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4837 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4838 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4839 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4840 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4841 Lisp_Object result = Qnil, |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4842 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
|
4843 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
|
4844 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4845 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
|
4846 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4847 return result; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4848 } |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4849 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4850 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
|
4851 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
|
4852 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4853 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
|
4854 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
|
4855 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4856 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
|
4857 |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4858 arguments: (PREDICATE SEQUENCE &rest SEQUENCES) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4859 */ |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4860 (int nargs, Lisp_Object *args)) |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4861 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4862 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
|
4863 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
|
4864 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4865 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
|
4866 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4867 return result; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4868 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4869 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4870 /* 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
|
4871 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
|
4872 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
|
4873 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4874 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
|
4875 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
|
4876 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4877 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
|
4878 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
|
4879 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4880 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
|
4881 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
|
4882 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
|
4883 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4884 static Lisp_Object |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4885 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
|
4886 Lisp_Object caller) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4887 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4888 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
|
4889 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
|
4890 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
|
4891 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
|
4892 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4893 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
|
4894 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4895 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
|
4896 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4897 args[i] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4898 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4899 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4900 tortoises = alloca_array (Lisp_Object, nlists); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4901 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
|
4902 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4903 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
|
4904 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4905 nconcing[0] = Qnil; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4906 nconcing[1] = Qnil; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4907 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
|
4908 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4909 gcpro2.nvars = 2; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4910 gcpro3.nvars = nlists; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4911 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4912 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4913 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4914 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
|
4915 gcpro1.nvars = 1; |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4916 gcpro2.nvars = nlists; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4917 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4918 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4919 while (continuing) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4920 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4921 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
|
4922 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4923 if (CONSP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4924 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4925 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
|
4926 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
|
4927 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4928 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
|
4929 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4930 continuing = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4931 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4932 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4933 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4934 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4935 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
|
4936 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4937 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4938 if (!continuing) break; |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
4939 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
|
4940 |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4941 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
|
4942 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4943 DO_NOTHING; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4944 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4945 else if (EQ (caller, Qmapcon)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4946 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4947 nconcing[1] = funcalled; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4948 accum = bytecode_nconc2 (nconcing); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4949 if (NILP (result)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4950 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4951 result = accum; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4952 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4953 /* 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
|
4954 once: */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4955 nconcing[0] = funcalled; |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4956 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4957 else if (NILP (accum)) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4958 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4959 accum = result = Fcons (funcalled, Qnil); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4960 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4961 else |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4962 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4963 /* 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
|
4964 once we're done: */ |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4965 XSETCDR (accum, Fcons (funcalled, Qnil)); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4966 accum = XCDR (accum); |
4995
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 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4969 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
|
4970 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4971 if (called_count & 1) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4972 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4973 for (j = 0; j < nlists; ++j) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4974 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4975 tortoises[j] = XCDR (tortoises[j]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4976 if (EQ (lists[j], tortoises[j])) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4977 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4978 signal_circular_list_error (lists[j]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4979 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4980 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4981 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4982 else |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4983 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4984 for (j = 0; j < nlists; ++j) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4985 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4986 if (EQ (lists[j], tortoises[j])) |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4987 { |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4988 signal_circular_list_error (lists[j]); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4989 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4990 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4991 } |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
4992 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4993 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4994 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4995 RETURN_UNGCPRO (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4996 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4997 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4998 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
|
4999 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
|
5000 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
|
5001 the elements themselves." |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5002 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5003 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
|
5004 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5005 (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
|
5006 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
5007 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
|
5008 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5009 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5010 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
|
5011 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
|
5012 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5013 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
|
5014 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5015 (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
|
5016 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
5017 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
|
5018 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5019 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5020 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
|
5021 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
|
5022 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5023 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
|
5024 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
|
5025 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5026 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
|
5027 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
5028 (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
|
5029 { |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
5030 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
|
5031 } |
428 | 5032 |
771 | 5033 /* Extra random functions */ |
442 | 5034 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5035 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
|
5036 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
|
5037 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5038 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
|
5039 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
|
5040 in SEQUENCE. |
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 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
|
5043 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
|
5044 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5045 :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
|
5046 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
|
5047 :from-end is given). |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5048 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5049 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
|
5050 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
|
5051 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
|
5052 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5053 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
|
5054 */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5055 (int nargs, Lisp_Object *args)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5056 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5057 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
|
5058 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
|
5059 |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
5060 PARSE_KEYWORDS (Freduce, nargs, args, 5, |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5061 (start, end, from_end, initial_value, key), |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
5062 (start = Qzero, initial_value = Qunbound)); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5063 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5064 CHECK_SEQUENCE (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5065 CHECK_NATNUM (start); |
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 CHECK_KEY_ARGUMENT (key); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5068 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5069 #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
|
5070 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
|
5071 #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
|
5072 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
|
5073 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5074 starting = XINT (start); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5075 if (!NILP (end)) |
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 CHECK_NATNUM (end); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5078 ending = XINT (end); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5079 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5080 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5081 if (!(starting <= ending)) |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5082 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5083 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
|
5084 } |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5085 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5086 if (VECTORP (sequence)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5087 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5088 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
|
5089 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5090 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
|
5091 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5092 ending = min (ending, vv->size); |
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 if (!UNBOUNDP (initial_value)) |
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 = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5097 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5098 else if (ending - starting) |
5227
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 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5101 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5102 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
|
5103 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5104 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5105 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5106 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5107 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
|
5108 ending--; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5109 } |
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 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5112 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5113 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5114 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
|
5115 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5116 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
|
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 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5120 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5121 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
|
5122 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5123 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
|
5124 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5125 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5126 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5127 else if (BIT_VECTORP (sequence)) |
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 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
|
5130 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5131 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
|
5132 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5133 ending = min (ending, bv->size); |
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 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5142 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5143 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
|
5144 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5145 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5146 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5147 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5148 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
|
5149 ending--; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5150 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5151 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5152 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5153 if (NILP (from_end)) |
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 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
|
5156 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5157 accum = CALL2 (function, accum, |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5158 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
|
5159 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5160 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5161 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5162 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5163 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
|
5164 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5165 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
|
5166 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
|
5167 ii))), |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5168 accum); |
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 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5171 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5172 else if (STRINGP (sequence)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5173 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5174 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5175 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5176 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
|
5177 Bytecount cursor_offset = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5178 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
|
5179 const Ibyte *cursor = startp; |
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 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
|
5182 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5183 INC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5184 cursor_offset = cursor - startp; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5185 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5186 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5187 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5188 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5189 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5190 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5191 else if (ending - starting) |
5227
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 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
|
5194 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5195 startp = XSTRING_DATA (sequence); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5196 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
|
5197 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5198 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
|
5199 || !valid_ibyteptr_p (cursor)) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5200 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5201 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
|
5202 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5203 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5204 INC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5205 cursor_offset = cursor - startp; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5206 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5207 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5208 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
|
5209 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5210 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
|
5211 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
|
5212 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5213 startp = XSTRING_DATA (sequence); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5214 cursor = startp + cursor_offset; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5215 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5216 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
|
5217 || !valid_ibyteptr_p (cursor)) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5218 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5219 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
|
5220 } |
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 INC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5223 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
|
5224 ++ii; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5225 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5226 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5227 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
|
5228 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5229 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
|
5230 ABORT (); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5231 } |
5227
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 else |
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 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
|
5236 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
|
5237 const Ibyte *cursor; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5238 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5239 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
|
5240 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5241 ending = min (ending, len); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5242 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
|
5243 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
|
5244 |
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 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5251 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
|
5252 ending--; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5253 if (ending > 0) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5254 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5255 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
|
5256 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5257 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
|
5258 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5259 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
|
5260 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5261 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5262 DEC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5263 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
|
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 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5267 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
|
5268 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5269 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
|
5270 make_char (itext_ichar (cursor))), |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5271 accum); |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5272 if (ii > 0) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5273 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5274 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
|
5275 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5276 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
|
5277 || !valid_ibyteptr_p (cursor)) |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5278 { |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5279 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
|
5280 } |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5281 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5282 DEC_IBYTEPTR (cursor); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5283 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
|
5284 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5285 } |
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 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5288 else if (LISTP (sequence)) |
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 if (NILP (from_end)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5291 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5292 struct gcpro gcpro1; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5293 Lisp_Object tailed = Qnil; |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5294 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5295 GCPRO1 (tailed); |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5296 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5297 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5298 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5299 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5300 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5301 else if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5302 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5303 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
|
5304 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5305 /* 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
|
5306 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
|
5307 tailed = tail; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5308 if (ii == starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5309 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5310 accum = KEY (key, elt); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5311 starting++; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5312 break; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5313 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5314 ++ii; |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5315 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5316 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5317 |
5275
5a9aa6c40c9b
Avoid statement-before-declaration problems with strict C89 builds, fns.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5273
diff
changeset
|
5318 ii = 0; |
5a9aa6c40c9b
Avoid statement-before-declaration problems with strict C89 builds, fns.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5273
diff
changeset
|
5319 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5320 if (ending - starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5321 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5322 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
|
5323 { |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5324 /* 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
|
5325 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
|
5326 reachable. */ |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5327 tailed = tail; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5328 if (ii >= starting) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5329 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5330 if (ii < ending) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5331 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5332 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
|
5333 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5334 else if (ii == ending) |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5335 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5336 break; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5337 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5338 } |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5339 ++ii; |
5227
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 } |
5241
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5342 |
d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents:
5227
diff
changeset
|
5343 UNGCPRO; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5344 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5345 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
|
5346 { |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5347 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
|
5348 ABORT (); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5349 } |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5350 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5351 else |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5352 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5353 Boolint need_accum = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5354 Lisp_Object *subsequence = NULL; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5355 Elemcount counting = 0, len = 0; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5356 struct gcpro gcpro1; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5357 |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5358 len = XINT (Flength (sequence)); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5359 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
|
5360 ending = min (ending, len); |
5227
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 /* :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
|
5363 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
|
5364 if (!UNBOUNDP (initial_value)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5365 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5366 accum = initial_value; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5367 if (ending - starting && starting < ending) |
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 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
|
5370 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5371 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5372 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
|
5373 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5374 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
|
5375 need_accum = 1; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5376 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5377 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5378 if (ending - starting && starting < ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5379 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5380 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
|
5381 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5382 if (counting >= starting) |
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 if (counting < ending) |
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 subsequence[ii++] = elt; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5387 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5388 else if (counting == ending) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5389 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5390 break; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5391 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5392 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5393 ++counting; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5394 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5395 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5396 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5397 if (subsequence != NULL) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5398 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5399 len = ending - starting; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5400 /* 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
|
5401 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
|
5402 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
|
5403 reachable via SEQUENCE. */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5404 GCPRO1 (subsequence[0]); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5405 gcpro1.nvars = len; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5406 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5407 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5408 if (need_accum) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5409 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5410 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
|
5411 --len; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5412 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5413 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5414 for (ii = len; ii != 0;) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5415 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5416 --ii; |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5417 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
|
5418 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5419 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5420 if (subsequence != NULL) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5421 { |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5422 UNGCPRO; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5423 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5424 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5425 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5426 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5427 /* 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
|
5428 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
|
5429 arguments. */ |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5430 if (UNBOUNDP (accum)) |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5431 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5432 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
|
5433 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5434 |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5435 return accum; |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5436 } |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
5437 |
442 | 5438 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /* |
5439 Destructively replace the list OLD with NEW. | |
5440 This is like (copy-sequence NEW) except that it reuses the | |
5441 conses in OLD as much as possible. If OLD and NEW are the same | |
5442 length, no consing will take place. | |
5443 */ | |
3025 | 5444 (old, new_)) |
442 | 5445 { |
2367 | 5446 Lisp_Object oldtail = old, prevoldtail = Qnil; |
5447 | |
3025 | 5448 EXTERNAL_LIST_LOOP_2 (elt, new_) |
442 | 5449 { |
5450 if (!NILP (oldtail)) | |
5451 { | |
5452 CHECK_CONS (oldtail); | |
2367 | 5453 XCAR (oldtail) = elt; |
442 | 5454 } |
5455 else if (!NILP (prevoldtail)) | |
5456 { | |
2367 | 5457 XCDR (prevoldtail) = Fcons (elt, Qnil); |
442 | 5458 prevoldtail = XCDR (prevoldtail); |
5459 } | |
5460 else | |
2367 | 5461 old = oldtail = Fcons (elt, Qnil); |
442 | 5462 |
5463 if (!NILP (oldtail)) | |
5464 { | |
5465 prevoldtail = oldtail; | |
5466 oldtail = XCDR (oldtail); | |
5467 } | |
5468 } | |
5469 | |
5470 if (!NILP (prevoldtail)) | |
5471 XCDR (prevoldtail) = Qnil; | |
5472 else | |
5473 old = Qnil; | |
5474 | |
5475 return old; | |
5476 } | |
5477 | |
5261
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5478 /* 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
|
5479 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
|
5480 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
|
5481 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
|
5482 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
|
5483 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
|
5484 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5485 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
|
5486 *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
|
5487 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
|
5488 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
|
5489 Elemcount delta; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5490 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5491 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
|
5492 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5493 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
|
5494 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5495 } |
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 pcursor = p; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5498 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5499 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
|
5500 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5501 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
|
5502 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5503 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
|
5504 ii++; |
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 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
|
5508 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5509 else |
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 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
|
5512 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
|
5513 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5514 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
|
5515 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5516 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5517 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5518 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5519 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
|
5520 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5521 /* 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
|
5522 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
|
5523 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5524 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5525 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
|
5526 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5527 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
|
5528 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5529 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
|
5530 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5531 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
|
5532 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
|
5533 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
|
5534 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5535 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5536 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5537 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
|
5538 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
|
5539 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5540 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5541 if (delta) |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5542 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5543 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
|
5544 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
|
5545 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
|
5546 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
|
5547 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5548 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5549 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
|
5550 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5551 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
|
5552 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5553 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
|
5554 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
|
5555 starting++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5556 } |
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 else |
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 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
|
5561 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5562 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
|
5563 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
|
5564 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5565 } |
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 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
|
5568 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
|
5569 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
|
5570 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5571 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5572 return dest; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5575 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
|
5576 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
|
5577 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5578 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
|
5579 changed. |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5580 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5581 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
|
5582 :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
|
5583 information. |
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 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
|
5586 */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5587 (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
|
5588 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5589 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
|
5590 result = sequence1; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5591 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
|
5592 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
|
5593 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
|
5594 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
|
5595 |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
5596 PARSE_KEYWORDS (Freplace, nargs, args, 4, (start1, end1, start2, end2), |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5275
diff
changeset
|
5597 (start1 = start2 = Qzero)); |
5261
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 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
|
5600 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
|
5601 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5602 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
|
5603 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5604 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
|
5605 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
|
5606 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
|
5607 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
|
5608 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5609 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
|
5610 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5611 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
|
5612 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
|
5613 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5614 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
|
5615 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5616 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
|
5617 } |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5620 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
|
5621 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5622 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
|
5623 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
|
5624 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5625 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
|
5626 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5627 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
|
5628 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5629 } |
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 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
|
5632 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
|
5633 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5634 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
|
5635 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5636 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
|
5637 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5638 sequence1 = Fnthcdr (start1, sequence1); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5639 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5640 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
|
5641 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5642 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
|
5643 /* 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
|
5644 return result; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5645 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5646 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5647 ending1 -= starting1; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5648 starting1 = 0; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5651 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
|
5652 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5653 sequence2 = Fnthcdr (start2, sequence2); |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5654 |
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5655 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
|
5656 { |
5272
66dbef5f8076
Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5262
diff
changeset
|
5657 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
|
5658 /* 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
|
5659 return result; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5662 ending2 -= starting2; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5663 starting2 = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5664 } |
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 if (overwriting) |
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 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
|
5669 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5670 return result; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5673 /* 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
|
5674 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5675 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
|
5676 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5677 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
|
5678 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
|
5679 = 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
|
5680 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
|
5681 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5682 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
|
5683 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5684 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
|
5685 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5686 break; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5689 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
|
5690 counting++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5691 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5692 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5693 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
|
5694 /* 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
|
5695 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
|
5696 start2 sequence2). */ |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5697 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
|
5698 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
|
5699 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
|
5700 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5701 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
|
5702 && 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
|
5703 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5704 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
|
5705 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
|
5706 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5707 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5708 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5709 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5710 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
|
5711 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5712 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
|
5713 *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
|
5714 *staging; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5715 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
|
5716 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5717 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
|
5718 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5719 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
|
5720 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5721 } |
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 pcursor = p; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5724 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5725 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
|
5726 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5727 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
|
5728 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5729 ii++; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5732 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
|
5733 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5734 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
|
5735 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
|
5736 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5737 else |
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 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
|
5740 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
|
5741 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
|
5742 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
|
5743 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
|
5744 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
|
5745 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5746 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5747 else |
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 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
|
5750 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
|
5751 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
|
5752 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
|
5753 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5754 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
|
5755 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
|
5756 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5757 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
|
5758 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5759 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
|
5760 ii++, starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5761 } |
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 ii = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5764 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5765 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
|
5766 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5767 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
|
5768 ii++, starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5769 } |
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 && sequence2_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 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
|
5775 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
|
5776 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
|
5777 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5778 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
|
5779 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5780 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
|
5781 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5782 XSETCAR (sequence1, |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5783 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
|
5784 : Fcar (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5785 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
|
5786 : Fcdr (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5787 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
|
5788 : Fcdr (sequence2); |
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 shortest_len++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5791 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5792 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
|
5793 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5794 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
|
5795 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5796 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
|
5797 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
|
5798 } |
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 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
|
5801 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5802 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
|
5803 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5804 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5805 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
|
5806 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5807 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
|
5808 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5809 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5810 } |
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 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
|
5813 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5814 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
|
5815 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
|
5816 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5817 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
|
5818 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5819 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
|
5820 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
|
5821 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5822 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5823 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
|
5824 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5825 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
|
5826 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5827 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
|
5828 *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
|
5829 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
|
5830 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
|
5831 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5832 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
|
5833 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5834 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
|
5835 char_count++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5836 } |
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 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
|
5839 && 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
|
5840 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5841 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
|
5842 CONSP (sequence1) ? |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5843 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
|
5844 : 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
|
5845 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
|
5846 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5847 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5848 char_count++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5849 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
|
5850 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5851 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5852 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
|
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_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
|
5855 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
|
5856 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5857 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5858 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
|
5859 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5860 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
|
5861 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
|
5862 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5863 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5864 else |
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 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
|
5867 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
|
5868 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5869 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
|
5870 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
|
5871 && 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
|
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_CONS (sequence1); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5874 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
|
5875 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
|
5876 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5877 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5878 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5879 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5880 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
|
5881 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5882 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
|
5883 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
|
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 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5887 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
|
5888 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5889 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
|
5890 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5891 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
|
5892 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
|
5893 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
|
5894 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5895 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
|
5896 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
|
5897 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
|
5898 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
|
5899 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5900 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
|
5901 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5902 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
|
5903 : Fcar (sequence2); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5904 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5905 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
|
5906 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
|
5907 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5908 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
|
5909 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5910 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5911 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
|
5912 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5913 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
|
5914 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
|
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 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
|
5918 staging, cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5919 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5920 else |
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 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
|
5923 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5924 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
|
5925 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
|
5926 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5927 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
|
5928 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5929 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
|
5930 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
|
5931 : Fcar (sequence2)); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5932 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
|
5933 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5934 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5935 } |
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 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
|
5938 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5939 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
|
5940 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
|
5941 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5942 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5943 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5944 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5945 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5946 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
|
5947 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5948 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
|
5949 *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
|
5950 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
|
5951 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5952 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
|
5953 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5954 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
|
5955 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5956 } |
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 p2cursor = p2; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5959 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
|
5960 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5961 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
|
5962 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5963 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
|
5964 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5965 starting1++; |
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 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5968 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
|
5969 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5970 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
|
5971 } |
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 /* 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
|
5974 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
|
5975 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
|
5976 p2, p2cursor); |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5977 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5978 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
|
5979 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5980 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
|
5981 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
|
5982 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
|
5983 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
|
5984 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5985 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
|
5986 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
|
5987 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5988 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
|
5989 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
|
5990 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
|
5991 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
|
5992 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5993 ii = 0; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5994 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
|
5995 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5996 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
|
5997 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
5998 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
|
5999 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
|
6000 starting2++, ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6001 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6002 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6003 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
|
6004 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
|
6005 staging, cursor); |
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 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
|
6008 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6009 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
|
6010 *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
|
6011 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
|
6012 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6013 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
|
6014 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
|
6015 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6016 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
|
6017 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6018 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
|
6019 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6020 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6021 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6022 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
|
6023 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6024 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
|
6025 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
|
6026 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
|
6027 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6028 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6029 ii++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6030 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6031 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6032 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
|
6033 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6034 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
|
6035 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6036 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6037 else |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6038 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6039 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
|
6040 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
|
6041 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6042 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
|
6043 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
|
6044 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6045 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
|
6046 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
|
6047 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6048 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
|
6049 { |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6050 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
|
6051 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
|
6052 starting1++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6053 starting2++; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6054 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6055 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6056 } |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6057 |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6058 return result; |
69f687b3ba9d
Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
6059 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6060 |
771 | 6061 Lisp_Object |
2367 | 6062 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string) |
771 | 6063 { |
6064 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
|
6065 build_ascstring (ascii_string)), |
771 | 6066 Qnil); |
6067 } | |
6068 | |
6069 Lisp_Object | |
2367 | 6070 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol) |
771 | 6071 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4797
diff
changeset
|
6072 return Fintern (concat2 (build_ascstring (ascii_string), |
771 | 6073 Fsymbol_name (symbol)), |
6074 Qnil); | |
6075 } | |
6076 | |
442 | 6077 |
428 | 6078 /* #### this function doesn't belong in this file! */ |
6079 | |
442 | 6080 #ifdef HAVE_GETLOADAVG |
6081 #ifdef HAVE_SYS_LOADAVG_H | |
6082 #include <sys/loadavg.h> | |
6083 #endif | |
6084 #else | |
6085 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */ | |
6086 #endif | |
6087 | |
428 | 6088 DEFUN ("load-average", Fload_average, 0, 1, 0, /* |
6089 Return list of 1 minute, 5 minute and 15 minute load averages. | |
6090 Each of the three load averages is multiplied by 100, | |
6091 then converted to integer. | |
6092 | |
6093 When USE-FLOATS is non-nil, floats will be used instead of integers. | |
6094 These floats are not multiplied by 100. | |
6095 | |
6096 If the 5-minute or 15-minute load averages are not available, return a | |
6097 shortened list, containing only those averages which are available. | |
6098 | |
6099 On some systems, this won't work due to permissions on /dev/kmem, | |
6100 in which case you can't use this. | |
6101 */ | |
6102 (use_floats)) | |
6103 { | |
6104 double load_ave[3]; | |
6105 int loads = getloadavg (load_ave, countof (load_ave)); | |
6106 Lisp_Object ret = Qnil; | |
6107 | |
6108 if (loads == -2) | |
563 | 6109 signal_error (Qunimplemented, |
6110 "load-average not implemented for this operating system", | |
6111 Qunbound); | |
428 | 6112 else if (loads < 0) |
563 | 6113 invalid_operation ("Could not get load-average", lisp_strerror (errno)); |
428 | 6114 |
6115 while (loads-- > 0) | |
6116 { | |
6117 Lisp_Object load = (NILP (use_floats) ? | |
6118 make_int ((int) (100.0 * load_ave[loads])) | |
6119 : make_float (load_ave[loads])); | |
6120 ret = Fcons (load, ret); | |
6121 } | |
6122 return ret; | |
6123 } | |
6124 | |
6125 | |
6126 Lisp_Object Vfeatures; | |
6127 | |
6128 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /* | |
6129 Return non-nil if feature FEXP is present in this Emacs. | |
6130 Use this to conditionalize execution of lisp code based on the | |
6131 presence or absence of emacs or environment extensions. | |
6132 FEXP can be a symbol, a number, or a list. | |
6133 If it is a symbol, that symbol is looked up in the `features' variable, | |
6134 and non-nil will be returned if found. | |
6135 If it is a number, the function will return non-nil if this Emacs | |
6136 has an equal or greater version number than FEXP. | |
6137 If it is a list whose car is the symbol `and', it will return | |
6138 non-nil if all the features in its cdr are non-nil. | |
6139 If it is a list whose car is the symbol `or', it will return non-nil | |
6140 if any of the features in its cdr are non-nil. | |
6141 If it is a list whose car is the symbol `not', it will return | |
6142 non-nil if the feature is not present. | |
6143 | |
6144 Examples: | |
6145 | |
6146 (featurep 'xemacs) | |
6147 => ; Non-nil on XEmacs. | |
6148 | |
6149 (featurep '(and xemacs gnus)) | |
6150 => ; Non-nil on XEmacs with Gnus loaded. | |
6151 | |
6152 (featurep '(or tty-frames (and emacs 19.30))) | |
6153 => ; Non-nil if this Emacs supports TTY frames. | |
6154 | |
6155 (featurep '(or (and xemacs 19.15) (and emacs 19.34))) | |
6156 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later. | |
6157 | |
442 | 6158 (featurep '(and xemacs 21.02)) |
6159 => ; Non-nil on XEmacs 21.2 and later. | |
6160 | |
428 | 6161 NOTE: The advanced arguments of this function (anything other than a |
6162 symbol) are not yet supported by FSF Emacs. If you feel they are useful | |
6163 for supporting multiple Emacs variants, lobby Richard Stallman at | |
442 | 6164 <bug-gnu-emacs@gnu.org>. |
428 | 6165 */ |
6166 (fexp)) | |
6167 { | |
6168 #ifndef FEATUREP_SYNTAX | |
6169 CHECK_SYMBOL (fexp); | |
6170 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
6171 #else /* FEATUREP_SYNTAX */ | |
6172 static double featurep_emacs_version; | |
6173 | |
6174 /* Brute force translation from Erik Naggum's lisp function. */ | |
6175 if (SYMBOLP (fexp)) | |
6176 { | |
6177 /* Original definition */ | |
6178 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
6179 } | |
6180 else if (INTP (fexp) || FLOATP (fexp)) | |
6181 { | |
6182 double d = extract_float (fexp); | |
6183 | |
6184 if (featurep_emacs_version == 0.0) | |
6185 { | |
6186 featurep_emacs_version = XINT (Vemacs_major_version) + | |
6187 (XINT (Vemacs_minor_version) / 100.0); | |
6188 } | |
6189 return featurep_emacs_version >= d ? Qt : Qnil; | |
6190 } | |
6191 else if (CONSP (fexp)) | |
6192 { | |
6193 Lisp_Object tem = XCAR (fexp); | |
6194 if (EQ (tem, Qnot)) | |
6195 { | |
6196 Lisp_Object negate; | |
6197 | |
6198 tem = XCDR (fexp); | |
6199 negate = Fcar (tem); | |
6200 if (!NILP (tem)) | |
6201 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil; | |
6202 else | |
6203 return Fsignal (Qinvalid_read_syntax, list1 (tem)); | |
6204 } | |
6205 else if (EQ (tem, Qand)) | |
6206 { | |
6207 tem = XCDR (fexp); | |
6208 /* Use Fcar/Fcdr for error-checking. */ | |
6209 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem)))) | |
6210 { | |
6211 tem = Fcdr (tem); | |
6212 } | |
6213 return NILP (tem) ? Qt : Qnil; | |
6214 } | |
6215 else if (EQ (tem, Qor)) | |
6216 { | |
6217 tem = XCDR (fexp); | |
6218 /* Use Fcar/Fcdr for error-checking. */ | |
6219 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem)))) | |
6220 { | |
6221 tem = Fcdr (tem); | |
6222 } | |
6223 return NILP (tem) ? Qnil : Qt; | |
6224 } | |
6225 else | |
6226 { | |
6227 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp))); | |
6228 } | |
6229 } | |
6230 else | |
6231 { | |
6232 return Fsignal (Qinvalid_read_syntax, list1 (fexp)); | |
6233 } | |
6234 } | |
6235 #endif /* FEATUREP_SYNTAX */ | |
6236 | |
6237 DEFUN ("provide", Fprovide, 1, 1, 0, /* | |
6238 Announce that FEATURE is a feature of the current Emacs. | |
6239 This function updates the value of the variable `features'. | |
6240 */ | |
6241 (feature)) | |
6242 { | |
6243 Lisp_Object tem; | |
6244 CHECK_SYMBOL (feature); | |
6245 if (!NILP (Vautoload_queue)) | |
6246 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); | |
6247 tem = Fmemq (feature, Vfeatures); | |
6248 if (NILP (tem)) | |
6249 Vfeatures = Fcons (feature, Vfeatures); | |
6250 LOADHIST_ATTACH (Fcons (Qprovide, feature)); | |
6251 return feature; | |
6252 } | |
6253 | |
1067 | 6254 DEFUN ("require", Frequire, 1, 3, 0, /* |
3842 | 6255 Ensure that FEATURE is present in the Lisp environment. |
6256 FEATURE is a symbol naming a collection of resources (functions, etc). | |
6257 Optional FILENAME is a library from which to load resources; it defaults to | |
6258 the print name of FEATURE. | |
6259 Optional NOERROR, if non-nil, causes require to return nil rather than signal | |
6260 `file-error' if loading the library fails. | |
6261 | |
6262 If feature FEATURE is present in `features', update `load-history' to reflect | |
6263 the require and return FEATURE. Otherwise, try to load it from a library. | |
6264 The normal messages at start and end of loading are suppressed. | |
6265 If the library is successfully loaded and it calls `(provide FEATURE)', add | |
6266 FEATURE to `features', update `load-history' and return FEATURE. | |
6267 If the load succeeds but FEATURE is not provided by the library, signal | |
6268 `invalid-state'. | |
6269 | |
6270 The byte-compiler treats top-level calls to `require' specially, by evaluating | |
6271 them at compile time (and then compiling them normally). Thus a library may | |
6272 request that definitions that should be inlined such as macros and defsubsts | |
6273 be loaded into its compilation environment. Achieving this in other contexts | |
6274 requires an explicit \(eval-and-compile ...\) block. | |
428 | 6275 */ |
1067 | 6276 (feature, filename, noerror)) |
428 | 6277 { |
6278 Lisp_Object tem; | |
6279 CHECK_SYMBOL (feature); | |
6280 tem = Fmemq (feature, Vfeatures); | |
6281 LOADHIST_ATTACH (Fcons (Qrequire, feature)); | |
6282 if (!NILP (tem)) | |
6283 return feature; | |
6284 else | |
6285 { | |
6286 int speccount = specpdl_depth (); | |
6287 | |
6288 /* Value saved here is to be restored into Vautoload_queue */ | |
6289 record_unwind_protect (un_autoload, Vautoload_queue); | |
6290 Vautoload_queue = Qt; | |
6291 | |
1067 | 6292 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename, |
1261 | 6293 noerror, Qrequire, Qnil); |
1067 | 6294 /* If load failed entirely, return nil. */ |
6295 if (NILP (tem)) | |
6296 return unbind_to_1 (speccount, Qnil); | |
428 | 6297 |
6298 tem = Fmemq (feature, Vfeatures); | |
6299 if (NILP (tem)) | |
563 | 6300 invalid_state ("Required feature was not provided", feature); |
428 | 6301 |
6302 /* Once loading finishes, don't undo it. */ | |
6303 Vautoload_queue = Qt; | |
771 | 6304 return unbind_to_1 (speccount, feature); |
428 | 6305 } |
6306 } | |
6307 | |
6308 /* base64 encode/decode functions. | |
6309 | |
6310 Originally based on code from GNU recode. Ported to FSF Emacs by | |
6311 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and | |
6312 subsequently heavily hacked by Hrvoje Niksic. */ | |
6313 | |
6314 #define MIME_LINE_LENGTH 72 | |
6315 | |
6316 #define IS_ASCII(Character) \ | |
6317 ((Character) < 128) | |
6318 #define IS_BASE64(Character) \ | |
6319 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | |
6320 | |
6321 /* 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
|
6322 static Ascbyte base64_value_to_char[64] = |
428 | 6323 { |
6324 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */ | |
6325 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */ | |
6326 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */ | |
6327 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */ | |
6328 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */ | |
6329 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */ | |
6330 '8', '9', '+', '/' /* 60-63 */ | |
6331 }; | |
6332 | |
6333 /* Table of base64 values for first 128 characters. */ | |
6334 static short base64_char_to_value[128] = | |
6335 { | |
6336 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */ | |
6337 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */ | |
6338 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */ | |
6339 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */ | |
6340 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */ | |
6341 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */ | |
6342 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */ | |
6343 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */ | |
6344 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */ | |
6345 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */ | |
6346 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */ | |
6347 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */ | |
6348 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */ | |
6349 }; | |
6350 | |
6351 /* The following diagram shows the logical steps by which three octets | |
6352 get transformed into four base64 characters. | |
6353 | |
6354 .--------. .--------. .--------. | |
6355 |aaaaaabb| |bbbbcccc| |ccdddddd| | |
6356 `--------' `--------' `--------' | |
6357 6 2 4 4 2 6 | |
6358 .--------+--------+--------+--------. | |
6359 |00aaaaaa|00bbbbbb|00cccccc|00dddddd| | |
6360 `--------+--------+--------+--------' | |
6361 | |
6362 .--------+--------+--------+--------. | |
6363 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD| | |
6364 `--------+--------+--------+--------' | |
6365 | |
6366 The octets are divided into 6 bit chunks, which are then encoded into | |
6367 base64 characters. */ | |
6368 | |
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
|
6369 static DECLARE_DOESNT_RETURN (base64_conversion_error (const Ascbyte *, |
2268 | 6370 Lisp_Object)); |
6371 | |
575 | 6372 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
|
6373 base64_conversion_error (const Ascbyte *reason, Lisp_Object frob) |
563 | 6374 { |
6375 signal_error (Qbase64_conversion_error, reason, frob); | |
6376 } | |
6377 | |
6378 #define ADVANCE_INPUT(c, stream) \ | |
867 | 6379 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \ |
563 | 6380 ((ec > 255) ? \ |
6381 (base64_conversion_error ("Non-ascii character in base64 input", \ | |
6382 make_char (ec)), 0) \ | |
867 | 6383 : (c = (Ibyte)ec), 1)) |
665 | 6384 |
6385 static Bytebpos | |
867 | 6386 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break) |
428 | 6387 { |
6388 EMACS_INT counter = 0; | |
867 | 6389 Ibyte *e = to; |
6390 Ichar ec; | |
428 | 6391 unsigned int value; |
6392 | |
6393 while (1) | |
6394 { | |
1204 | 6395 Ibyte c = 0; |
428 | 6396 if (!ADVANCE_INPUT (c, istream)) |
6397 break; | |
6398 | |
6399 /* Wrap line every 76 characters. */ | |
6400 if (line_break) | |
6401 { | |
6402 if (counter < MIME_LINE_LENGTH / 4) | |
6403 counter++; | |
6404 else | |
6405 { | |
6406 *e++ = '\n'; | |
6407 counter = 1; | |
6408 } | |
6409 } | |
6410 | |
6411 /* Process first byte of a triplet. */ | |
6412 *e++ = base64_value_to_char[0x3f & c >> 2]; | |
6413 value = (0x03 & c) << 4; | |
6414 | |
6415 /* Process second byte of a triplet. */ | |
6416 if (!ADVANCE_INPUT (c, istream)) | |
6417 { | |
6418 *e++ = base64_value_to_char[value]; | |
6419 *e++ = '='; | |
6420 *e++ = '='; | |
6421 break; | |
6422 } | |
6423 | |
6424 *e++ = base64_value_to_char[value | (0x0f & c >> 4)]; | |
6425 value = (0x0f & c) << 2; | |
6426 | |
6427 /* Process third byte of a triplet. */ | |
6428 if (!ADVANCE_INPUT (c, istream)) | |
6429 { | |
6430 *e++ = base64_value_to_char[value]; | |
6431 *e++ = '='; | |
6432 break; | |
6433 } | |
6434 | |
6435 *e++ = base64_value_to_char[value | (0x03 & c >> 6)]; | |
6436 *e++ = base64_value_to_char[0x3f & c]; | |
6437 } | |
6438 | |
6439 return e - to; | |
6440 } | |
6441 #undef ADVANCE_INPUT | |
6442 | |
6443 /* Get next character from the stream, except that non-base64 | |
6444 characters are ignored. This is in accordance with rfc2045. EC | |
867 | 6445 should be an Ichar, so that it can hold -1 as the value for EOF. */ |
428 | 6446 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \ |
867 | 6447 ec = Lstream_get_ichar (stream); \ |
428 | 6448 ++streampos; \ |
6449 /* IS_BASE64 may not be called with negative arguments so check for \ | |
6450 EOF first. */ \ | |
6451 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \ | |
6452 break; \ | |
6453 } while (1) | |
6454 | |
6455 #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
|
6456 pos += set_itext_ichar (pos, (Ichar)((Binbyte)(val))); \ |
428 | 6457 ++ccnt; \ |
6458 } while (0) | |
6459 | |
665 | 6460 static Bytebpos |
867 | 6461 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr) |
428 | 6462 { |
6463 Charcount ccnt = 0; | |
867 | 6464 Ibyte *e = to; |
428 | 6465 EMACS_INT streampos = 0; |
6466 | |
6467 while (1) | |
6468 { | |
867 | 6469 Ichar ec; |
428 | 6470 unsigned long value; |
6471 | |
6472 /* Process first byte of a quadruplet. */ | |
6473 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6474 if (ec < 0) | |
6475 break; | |
6476 if (ec == '=') | |
563 | 6477 base64_conversion_error ("Illegal `=' character while decoding base64", |
6478 make_int (streampos)); | |
428 | 6479 value = base64_char_to_value[ec] << 18; |
6480 | |
6481 /* Process second byte of a quadruplet. */ | |
6482 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6483 if (ec < 0) | |
563 | 6484 base64_conversion_error ("Premature EOF while decoding base64", |
6485 Qunbound); | |
428 | 6486 if (ec == '=') |
563 | 6487 base64_conversion_error ("Illegal `=' character while decoding base64", |
6488 make_int (streampos)); | |
428 | 6489 value |= base64_char_to_value[ec] << 12; |
6490 STORE_BYTE (e, value >> 16, ccnt); | |
6491 | |
6492 /* Process third byte of a quadruplet. */ | |
6493 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6494 if (ec < 0) | |
563 | 6495 base64_conversion_error ("Premature EOF while decoding base64", |
6496 Qunbound); | |
428 | 6497 |
6498 if (ec == '=') | |
6499 { | |
6500 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6501 if (ec < 0) | |
563 | 6502 base64_conversion_error ("Premature EOF while decoding base64", |
6503 Qunbound); | |
428 | 6504 if (ec != '=') |
563 | 6505 base64_conversion_error |
6506 ("Padding `=' expected but not found while decoding base64", | |
6507 make_int (streampos)); | |
428 | 6508 continue; |
6509 } | |
6510 | |
6511 value |= base64_char_to_value[ec] << 6; | |
6512 STORE_BYTE (e, 0xff & value >> 8, ccnt); | |
6513 | |
6514 /* Process fourth byte of a quadruplet. */ | |
6515 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
6516 if (ec < 0) | |
563 | 6517 base64_conversion_error ("Premature EOF while decoding base64", |
6518 Qunbound); | |
428 | 6519 if (ec == '=') |
6520 continue; | |
6521 | |
6522 value |= base64_char_to_value[ec]; | |
6523 STORE_BYTE (e, 0xff & value, ccnt); | |
6524 } | |
6525 | |
6526 *ccptr = ccnt; | |
6527 return e - to; | |
6528 } | |
6529 #undef ADVANCE_INPUT | |
6530 #undef ADVANCE_INPUT_IGNORE_NONBASE64 | |
6531 #undef STORE_BYTE | |
6532 | |
6533 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /* | |
444 | 6534 Base64-encode the region between START and END. |
428 | 6535 Return the length of the encoded text. |
6536 Optional third argument NO-LINE-BREAK means do not break long lines | |
6537 into shorter lines. | |
6538 */ | |
444 | 6539 (start, end, no_line_break)) |
428 | 6540 { |
867 | 6541 Ibyte *encoded; |
665 | 6542 Bytebpos encoded_length; |
428 | 6543 Charcount allength, length; |
6544 struct buffer *buf = current_buffer; | |
665 | 6545 Charbpos begv, zv, old_pt = BUF_PT (buf); |
428 | 6546 Lisp_Object input; |
851 | 6547 int speccount = specpdl_depth (); |
428 | 6548 |
444 | 6549 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 6550 barf_if_buffer_read_only (buf, begv, zv); |
6551 | |
6552 /* We need to allocate enough room for encoding the text. | |
6553 We need 33 1/3% more space, plus a newline every 76 | |
6554 characters, and then we round up. */ | |
6555 length = zv - begv; | |
6556 allength = length + length/3 + 1; | |
6557 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
6558 | |
6559 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
867 | 6560 /* We needn't multiply allength with MAX_ICHAR_LEN because all the |
428 | 6561 base64 characters will be single-byte. */ |
867 | 6562 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 6563 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
6564 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
6565 assert (encoded_length <= allength); |
428 | 6566 Lstream_delete (XLSTREAM (input)); |
6567 | |
6568 /* Now we have encoded the region, so we insert the new contents | |
6569 and delete the old. (Insert first in order to preserve markers.) */ | |
6570 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0); | |
851 | 6571 unbind_to (speccount); |
428 | 6572 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0); |
6573 | |
6574 /* Simulate FSF Emacs implementation of this function: if point was | |
6575 in the region, place it at the beginning. */ | |
6576 if (old_pt >= begv && old_pt < zv) | |
6577 BUF_SET_PT (buf, begv); | |
6578 | |
6579 /* We return the length of the encoded text. */ | |
6580 return make_int (encoded_length); | |
6581 } | |
6582 | |
6583 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /* | |
6584 Base64 encode STRING and return the result. | |
444 | 6585 Optional argument NO-LINE-BREAK means do not break long lines |
6586 into shorter lines. | |
428 | 6587 */ |
6588 (string, no_line_break)) | |
6589 { | |
6590 Charcount allength, length; | |
665 | 6591 Bytebpos encoded_length; |
867 | 6592 Ibyte *encoded; |
428 | 6593 Lisp_Object input, result; |
6594 int speccount = specpdl_depth(); | |
6595 | |
6596 CHECK_STRING (string); | |
6597 | |
826 | 6598 length = string_char_length (string); |
428 | 6599 allength = length + length/3 + 1; |
6600 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
6601 | |
6602 input = make_lisp_string_input_stream (string, 0, -1); | |
867 | 6603 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 6604 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
6605 NILP (no_line_break)); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
6606 assert (encoded_length <= allength); |
428 | 6607 Lstream_delete (XLSTREAM (input)); |
6608 result = make_string (encoded, encoded_length); | |
851 | 6609 unbind_to (speccount); |
428 | 6610 return result; |
6611 } | |
6612 | |
6613 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /* | |
444 | 6614 Base64-decode the region between START and END. |
428 | 6615 Return the length of the decoded text. |
6616 If the region can't be decoded, return nil and don't modify the buffer. | |
6617 Characters out of the base64 alphabet are ignored. | |
6618 */ | |
444 | 6619 (start, end)) |
428 | 6620 { |
6621 struct buffer *buf = current_buffer; | |
665 | 6622 Charbpos begv, zv, old_pt = BUF_PT (buf); |
867 | 6623 Ibyte *decoded; |
665 | 6624 Bytebpos decoded_length; |
428 | 6625 Charcount length, cc_decoded_length; |
6626 Lisp_Object input; | |
6627 int speccount = specpdl_depth(); | |
6628 | |
444 | 6629 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 6630 barf_if_buffer_read_only (buf, begv, zv); |
6631 | |
6632 length = zv - begv; | |
6633 | |
6634 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
6635 /* We need to allocate enough room for decoding the text. */ | |
867 | 6636 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 6637 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
|
6638 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 6639 Lstream_delete (XLSTREAM (input)); |
6640 | |
6641 /* Now we have decoded the region, so we insert the new contents | |
6642 and delete the old. (Insert first in order to preserve markers.) */ | |
6643 BUF_SET_PT (buf, begv); | |
6644 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0); | |
851 | 6645 unbind_to (speccount); |
428 | 6646 buffer_delete_range (buf, begv + cc_decoded_length, |
6647 zv + cc_decoded_length, 0); | |
6648 | |
6649 /* Simulate FSF Emacs implementation of this function: if point was | |
6650 in the region, place it at the beginning. */ | |
6651 if (old_pt >= begv && old_pt < zv) | |
6652 BUF_SET_PT (buf, begv); | |
6653 | |
6654 return make_int (cc_decoded_length); | |
6655 } | |
6656 | |
6657 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /* | |
6658 Base64-decode STRING and return the result. | |
6659 Characters out of the base64 alphabet are ignored. | |
6660 */ | |
6661 (string)) | |
6662 { | |
867 | 6663 Ibyte *decoded; |
665 | 6664 Bytebpos decoded_length; |
428 | 6665 Charcount length, cc_decoded_length; |
6666 Lisp_Object input, result; | |
6667 int speccount = specpdl_depth(); | |
6668 | |
6669 CHECK_STRING (string); | |
6670 | |
826 | 6671 length = string_char_length (string); |
428 | 6672 /* We need to allocate enough room for decoding the text. */ |
867 | 6673 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 6674 |
6675 input = make_lisp_string_input_stream (string, 0, -1); | |
6676 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, | |
6677 &cc_decoded_length); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5002
diff
changeset
|
6678 assert (decoded_length <= length * MAX_ICHAR_LEN); |
428 | 6679 Lstream_delete (XLSTREAM (input)); |
6680 | |
6681 result = make_string (decoded, decoded_length); | |
851 | 6682 unbind_to (speccount); |
428 | 6683 return result; |
6684 } | |
6685 | |
6686 Lisp_Object Qyes_or_no_p; | |
6687 | |
6688 void | |
6689 syms_of_fns (void) | |
6690 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
6691 INIT_LISP_OBJECT (bit_vector); |
442 | 6692 |
563 | 6693 DEFSYMBOL (Qstring_lessp); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6694 DEFSYMBOL (Qsort); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6695 DEFSYMBOL (Qmerge); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6696 DEFSYMBOL (Qfill); |
563 | 6697 DEFSYMBOL (Qidentity); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6698 DEFSYMBOL (Qvector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6699 DEFSYMBOL (Qarray); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6700 DEFSYMBOL (Qstring); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6701 DEFSYMBOL (Qlist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6702 DEFSYMBOL (Qbit_vector); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6703 defsymbol (&QsortX, "sort*"); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6704 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
|
6705 DEFSYMBOL (Qreplace); |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6706 |
5253
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6707 DEFSYMBOL (Qmapconcat); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6708 defsymbol (&QmapcarX, "mapcar*"); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6709 DEFSYMBOL (Qmapvector); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6710 DEFSYMBOL (Qmapcan); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6711 DEFSYMBOL (Qmapc); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6712 DEFSYMBOL (Qmap); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6713 DEFSYMBOL (Qmap_into); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6714 DEFSYMBOL (Qsome); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6715 DEFSYMBOL (Qevery); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6716 DEFSYMBOL (Qmaplist); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6717 DEFSYMBOL (Qmapl); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6718 DEFSYMBOL (Qmapcon); |
b6a398dbb403
Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents:
5241
diff
changeset
|
6719 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6720 DEFKEYWORD (Q_from_end); |
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6721 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
|
6722 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
|
6723 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
|
6724 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
|
6725 DEFKEYWORD (Q_end2); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6726 |
563 | 6727 DEFSYMBOL (Qyes_or_no_p); |
6728 | |
6729 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error); | |
428 | 6730 |
6731 DEFSUBR (Fidentity); | |
6732 DEFSUBR (Frandom); | |
6733 DEFSUBR (Flength); | |
6734 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
|
6735 DEFSUBR (Flist_length); |
428 | 6736 DEFSUBR (Fstring_equal); |
801 | 6737 DEFSUBR (Fcompare_strings); |
428 | 6738 DEFSUBR (Fstring_lessp); |
6739 DEFSUBR (Fstring_modified_tick); | |
6740 DEFSUBR (Fappend); | |
6741 DEFSUBR (Fconcat); | |
6742 DEFSUBR (Fvconcat); | |
6743 DEFSUBR (Fbvconcat); | |
6744 DEFSUBR (Fcopy_list); | |
6745 DEFSUBR (Fcopy_sequence); | |
6746 DEFSUBR (Fcopy_alist); | |
6747 DEFSUBR (Fcopy_tree); | |
6748 DEFSUBR (Fsubseq); | |
6749 DEFSUBR (Fnthcdr); | |
6750 DEFSUBR (Fnth); | |
6751 DEFSUBR (Felt); | |
6752 DEFSUBR (Flast); | |
6753 DEFSUBR (Fbutlast); | |
6754 DEFSUBR (Fnbutlast); | |
6755 DEFSUBR (Fmember); | |
6756 DEFSUBR (Fold_member); | |
6757 DEFSUBR (Fmemq); | |
6758 DEFSUBR (Fold_memq); | |
6759 DEFSUBR (Fassoc); | |
6760 DEFSUBR (Fold_assoc); | |
6761 DEFSUBR (Fassq); | |
6762 DEFSUBR (Fold_assq); | |
6763 DEFSUBR (Frassoc); | |
6764 DEFSUBR (Fold_rassoc); | |
6765 DEFSUBR (Frassq); | |
6766 DEFSUBR (Fold_rassq); | |
6767 DEFSUBR (Fdelete); | |
6768 DEFSUBR (Fold_delete); | |
6769 DEFSUBR (Fdelq); | |
6770 DEFSUBR (Fold_delq); | |
6771 DEFSUBR (Fremassoc); | |
6772 DEFSUBR (Fremassq); | |
6773 DEFSUBR (Fremrassoc); | |
6774 DEFSUBR (Fremrassq); | |
6775 DEFSUBR (Fnreverse); | |
6776 DEFSUBR (Freverse); | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6777 DEFSUBR (FsortX); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6778 Ffset (intern ("sort"), QsortX); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6779 DEFSUBR (Fmerge); |
428 | 6780 DEFSUBR (Fplists_eq); |
6781 DEFSUBR (Fplists_equal); | |
6782 DEFSUBR (Flax_plists_eq); | |
6783 DEFSUBR (Flax_plists_equal); | |
6784 DEFSUBR (Fplist_get); | |
6785 DEFSUBR (Fplist_put); | |
6786 DEFSUBR (Fplist_remprop); | |
6787 DEFSUBR (Fplist_member); | |
6788 DEFSUBR (Fcheck_valid_plist); | |
6789 DEFSUBR (Fvalid_plist_p); | |
6790 DEFSUBR (Fcanonicalize_plist); | |
6791 DEFSUBR (Flax_plist_get); | |
6792 DEFSUBR (Flax_plist_put); | |
6793 DEFSUBR (Flax_plist_remprop); | |
6794 DEFSUBR (Flax_plist_member); | |
6795 DEFSUBR (Fcanonicalize_lax_plist); | |
6796 DEFSUBR (Fdestructive_alist_to_plist); | |
6797 DEFSUBR (Fget); | |
6798 DEFSUBR (Fput); | |
6799 DEFSUBR (Fremprop); | |
6800 DEFSUBR (Fobject_plist); | |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5253
diff
changeset
|
6801 DEFSUBR (Fobject_setplist); |
428 | 6802 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
|
6803 DEFSUBR (Fequalp); |
428 | 6804 DEFSUBR (Fold_equal); |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6805 DEFSUBR (Ffill); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6806 Ffset (intern ("fillarray"), Qfill); |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5128
diff
changeset
|
6807 |
428 | 6808 DEFSUBR (Fnconc); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6809 DEFSUBR (FmapcarX); |
428 | 6810 DEFSUBR (Fmapvector); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6811 DEFSUBR (Fmapcan); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6812 DEFSUBR (Fmapc); |
428 | 6813 DEFSUBR (Fmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6814 DEFSUBR (Fmap); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6815 DEFSUBR (Fmap_into); |
4997
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
6816 DEFSUBR (Fsome); |
8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
6817 DEFSUBR (Fevery); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6818 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
|
6819 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
|
6820 DEFSUBR (Fmaplist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6821 DEFSUBR (Fmapl); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6822 DEFSUBR (Fmapcon); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
6823 |
5227
fbd1485af104
Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5224
diff
changeset
|
6824 DEFSUBR (Freduce); |
442 | 6825 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
|
6826 DEFSUBR (Freplace); |
428 | 6827 DEFSUBR (Fload_average); |
6828 DEFSUBR (Ffeaturep); | |
6829 DEFSUBR (Frequire); | |
6830 DEFSUBR (Fprovide); | |
6831 DEFSUBR (Fbase64_encode_region); | |
6832 DEFSUBR (Fbase64_encode_string); | |
6833 DEFSUBR (Fbase64_decode_region); | |
6834 DEFSUBR (Fbase64_decode_string); | |
771 | 6835 |
5224
35c2b7e9c03f
Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
6836 DEFSUBR (Fsubstring_no_properties); |
771 | 6837 DEFSUBR (Fsplit_string_by_char); |
6838 DEFSUBR (Fsplit_path); /* #### */ | |
6839 } | |
6840 | |
6841 void | |
6842 vars_of_fns (void) | |
6843 { | |
6844 DEFVAR_LISP ("path-separator", &Vpath_separator /* | |
6845 The directory separator in search paths, as a string. | |
6846 */ ); | |
6847 { | |
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
|
6848 Ascbyte c = SEPCHAR; |
867 | 6849 Vpath_separator = make_string ((Ibyte *) &c, 1); |
771 | 6850 } |
428 | 6851 } |
6852 | |
6853 void | |
6854 init_provide_once (void) | |
6855 { | |
6856 DEFVAR_LISP ("features", &Vfeatures /* | |
6857 A list of symbols which are the features of the executing emacs. | |
6858 Used by `featurep' and `require', and altered by `provide'. | |
6859 */ ); | |
6860 Vfeatures = Qnil; | |
6861 | |
6862 Fprovide (intern ("base64")); | |
6863 } |