annotate src/fns.c @ 5283:be436ac36ba4

Don't share a counter when checking for circularity, list_merge(). src/ChangeLog addition: 2010-10-12 Aidan Kehoe <kehoea@parhasard.net> * fns.c (list_merge): Circularity checking here needs to be done independently for each list, they can't share a loop counter. Thank you for the bug report, Robert Pluim! tests/ChangeLog addition: 2010-10-12 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Make sure circularity checking with #'merge is sane.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 12 Oct 2010 18:14:12 +0100
parents d804e621add0
children 99de5fd48e87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Random utility Lisp functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.0, FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* This file has been Mule-ized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* Note: FSF 19.30 has bool vectors. We have bit vectors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 /* Hacked on for Mule by Ben Wing, December 1994, January 1995. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 /* Note on some machines this defines `vector' as a typedef,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 so make sure we don't use that name in this file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #undef vector
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #define vector *****
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
39 #include "sysfile.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
40 #include "sysproc.h" /* for qxe_getpid() */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #include "bytecode.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #include "device.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include "events.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #include "extents.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include "frame.h"
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
48 #include "process.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 /* NOTE: This symbol is also used in lread.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #define FEATUREP_SYNTAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
64 Lisp_Object Qbase64_conversion_error;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
65
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
66 Lisp_Object Vpath_separator;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
67
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 static int internal_old_equal (Lisp_Object, Lisp_Object, int);
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
69 Lisp_Object safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
92 mark_bit_vector (Lisp_Object UNUSED (obj))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
98 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
99 int UNUSED (escapeflag))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
101 Elemcount i;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
102 Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
103 Elemcount len = bit_vector_length (v);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
104 Elemcount last = len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 if (INTP (Vprint_length))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 for (i = 0; i < last; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
125 Lisp_Bit_Vector *v1 = XBIT_VECTOR (obj1);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
126 Lisp_Bit_Vector *v2 = XBIT_VECTOR (obj2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 return ((bit_vector_length (v1) == bit_vector_length (v2)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 !memcmp (v1->bits, v2->bits,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 sizeof (long)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 return HASH2 (bit_vector_length (v),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 memory_hash (v->bits,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 sizeof (long)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
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
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 454
diff changeset
187 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, unsigned long, bits,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
188 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
189 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
190
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1067
diff changeset
191 static const struct memory_description bit_vector_description[] = {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4693
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
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
204
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 DEFUN ("identity", Fidentity, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 Return the argument unchanged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 return arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 DEFUN ("random", Frandom, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 Return a pseudo-random number.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
216 All fixnums are equally likely. On most systems, this is 31 bits' worth.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 With positive integer argument N, return random number in interval [0,N).
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
218 N can be a bignum, in which case the range of possible values is extended.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 With argument t, set the random number seed from the current time and pid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (limit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 EMACS_INT val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 unsigned long denominator;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 if (EQ (limit, Qt))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
227 seed_random (qxe_getpid () + time (NULL));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 if (NATNUMP (limit) && !ZEROP (limit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 /* Try to take our random number from the higher bits of VAL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 not the lower, since (says Gentzel) the low bits of `random'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 are less random than the higher ones. We do this by using the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 quotient rather than the remainder. At the high end of the RNG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 it's possible to get a quotient larger than limit; discarding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 these values eliminates the bias that would otherwise appear
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 when using a large limit. */
2039
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1983
diff changeset
237 denominator = ((unsigned long)1 << INT_VALBITS) / XINT (limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 val = get_random () / denominator;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 while (val >= XINT (limit));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
242 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
243 else if (BIGNUMP (limit))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
244 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
245 bignum_random (scratch_bignum, XBIGNUM_DATA (limit));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
246 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
247 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
248 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 val = get_random ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 return make_int (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 /* Random data-structure functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 /* #### Delete this shit */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 /* Charcount is a misnomer here as we might be dealing with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 length of a vector or list, but emphasizes that we're not dealing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 with Bytecounts in strings */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 static Charcount
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 length_with_bytecode_hack (Lisp_Object seq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 if (!COMPILED_FUNCTIONP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 return XINT (Flength (seq));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
271 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (seq);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 return (f->flags.interactivep ? COMPILED_INTERACTIVE :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 f->flags.domainp ? COMPILED_DOMAIN :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 COMPILED_DOC_STRING)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 #endif /* LOSING_BYTECODE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 if (COMPILED_FUNCTIONP (seq))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
286 signal_ferror_with_frob
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
287 (Qinvalid_argument, seq,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 "As of 20.3, `%s' no longer works with compiled-function objects",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 function);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 DEFUN ("length", Flength, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 Return the length of vector, bit vector, list or string SEQUENCE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 if (STRINGP (sequence))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
299 return make_int (string_char_length (sequence));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 else if (CONSP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
302 Elemcount len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 GET_EXTERNAL_LIST_LENGTH (sequence, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 return make_int (len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 else if (VECTORP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 return make_int (XVECTOR_LENGTH (sequence));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 else if (NILP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 return Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 else if (BIT_VECTORP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 return make_int (bit_vector_length (XBIT_VECTOR (sequence)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 check_losing_bytecode ("length", sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 sequence = wrong_type_argument (Qsequencep, sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 Return the length of a list, but avoid error or infinite loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 This function never gets an error. If LIST is not really a list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 it returns 0. If LIST is circular, it returns a finite value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 which is at least the number of distinct elements.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 Lisp_Object hare, tortoise;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
329 Elemcount len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 for (hare = tortoise = list, len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 CONSP (hare) && (! EQ (hare, tortoise) || len == 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 hare = XCDR (hare), len++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 if (len & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 return make_int (len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
342 /* This is almost the above, but is defined by Common Lisp. We need it in C
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
343 for shortest_length_among_sequences(), below, for the various sequence
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
344 functions that can usefully operate on circular lists. */
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
345
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
346 DEFUN ("list-length", Flist_length, 1, 1, 0, /*
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
347 Return the length of LIST. Return nil if LIST is circular.
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
348 */
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
349 (list))
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
350 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
351 Lisp_Object hare, tortoise;
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
352 Elemcount len;
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
353
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
354 for (hare = tortoise = list, len = 0;
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
355 CONSP (hare) && (! EQ (hare, tortoise) || len == 0);
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
356 hare = XCDR (hare), len++)
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
357 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
358 if (len & 1)
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
359 tortoise = XCDR (tortoise);
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
360 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
361
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
362 return EQ (hare, tortoise) && len != 0 ? Qnil : make_int (len);
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
363 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
364
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 /*** string functions. ***/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 Return t if two strings have identical contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 Case is significant. Text properties are ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 \(Under XEmacs, `equal' also ignores text properties and extents in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 `equal' is the same as in XEmacs, in that respect.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 Symbols are also allowed; their print names are used instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
375 (string1, string2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 Bytecount len;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
378 Lisp_Object p1, p2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
380 if (SYMBOLP (string1))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
381 p1 = XSYMBOL (string1)->name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
384 CHECK_STRING (string1);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
385 p1 = string1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
388 if (SYMBOLP (string2))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
389 p2 = XSYMBOL (string2)->name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
392 CHECK_STRING (string2);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
393 p2 = string2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
396 return (((len = XSTRING_LENGTH (p1)) == XSTRING_LENGTH (p2)) &&
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
397 !memcmp (XSTRING_DATA (p1), XSTRING_DATA (p2), len)) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
400 DEFUN ("compare-strings", Fcompare_strings, 6, 7, 0, /*
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
401 Compare the contents of two strings, maybe ignoring case.
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
402 In string STR1, skip the first START1 characters and stop at END1.
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
403 In string STR2, skip the first START2 characters and stop at END2.
4796
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
404 END1 and END2 default to the full lengths of the respective strings,
4797
a5eca70cf401 Fix typo in last patch.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4796
diff changeset
405 and arguments that are outside the string (negative STARTi or ENDi
4796
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
406 greater than length) are coerced to 0 or string length as appropriate.
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
407
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
408 Optional IGNORE-CASE non-nil means use case-insensitive comparison.
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
409 Case is significant by default.
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
410
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
411 The value is t if the strings (or specified portions) match.
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
412 If string STR1 is less, the value is a negative number N;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
413 - 1 - N is the number of characters that match at the beginning.
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
414 If string STR1 is greater, the value is a positive number N;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
415 N - 1 is the number of characters that match at the beginning.
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
416 */
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
417 (str1, start1, end1, str2, start2, end2, ignore_case))
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
418 {
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
419 Charcount ccstart1, ccend1, ccstart2, ccend2;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
420 Bytecount bstart1, blen1, bstart2, blen2;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
421 Charcount matching;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
422 int res;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
423
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
424 CHECK_STRING (str1);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
425 CHECK_STRING (str2);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
426 get_string_range_char (str1, start1, end1, &ccstart1, &ccend1,
4796
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
427 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
428 get_string_range_char (str2, start2, end2, &ccstart2, &ccend2,
4796
c45fdd4e1858 Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
429 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
430
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
431 bstart1 = string_index_char_to_byte (str1, ccstart1);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
432 blen1 = string_offset_char_to_byte_len (str1, bstart1, ccend1 - ccstart1);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
433 bstart2 = string_index_char_to_byte (str2, ccstart2);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
434 blen2 = string_offset_char_to_byte_len (str2, bstart2, ccend2 - ccstart2);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
435
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
436 res = ((NILP (ignore_case) ? qxetextcmp_matching : qxetextcasecmp_matching)
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
437 (XSTRING_DATA (str1) + bstart1, blen1,
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
438 XSTRING_DATA (str2) + bstart2, blen2,
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
439 &matching));
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
440
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
441 if (!res)
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
442 return Qt;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
443 else if (res > 0)
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
444 return make_int (1 + matching);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
445 else
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
446 return make_int (-1 - matching);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
447 }
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
448
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 Return t if first arg string is less than second in lexicographic order.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
451 Comparison is simply done on a character-by-character basis using the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
452 numeric value of a character. (Note that this may not produce
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
453 particularly meaningful results under Mule if characters from
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
454 different charsets are being compared.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 Symbols are also allowed; their print names are used instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
458 Currently we don't do proper language-specific collation or handle
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
459 multiple character sets. This may be changed when Unicode support
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
460 is implemented.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
462 (string1, string2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
464 Lisp_Object p1, p2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 Charcount end, len2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
468 if (SYMBOLP (string1))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
469 p1 = XSYMBOL (string1)->name;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
470 else
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
471 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
472 CHECK_STRING (string1);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
473 p1 = string1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
476 if (SYMBOLP (string2))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
477 p2 = XSYMBOL (string2)->name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
480 CHECK_STRING (string2);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
481 p2 = string2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
484 end = string_char_length (p1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
485 len2 = string_char_length (p2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 if (end > len2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 end = len2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
490 Ibyte *ptr1 = XSTRING_DATA (p1);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
491 Ibyte *ptr2 = XSTRING_DATA (p2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 /* #### It is not really necessary to do this: We could compare
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 byte-by-byte and still get a reasonable comparison, since this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 would compare characters with a charset in the same way. With
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 a little rearrangement of the leading bytes, we could make most
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 inter-charset comparisons work out the same, too; even if some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 don't, this is not a big deal because inter-charset comparisons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 aren't really well-defined anyway. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 for (i = 0; i < end; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
502 if (itext_ichar (ptr1) != itext_ichar (ptr2))
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
503 return itext_ichar (ptr1) < itext_ichar (ptr2) ? Qt : Qnil;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
504 INC_IBYTEPTR (ptr1);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
505 INC_IBYTEPTR (ptr2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 /* Can't do i < len2 because then comparison between "foo" and "foo^@"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 won't work right in I18N2 case */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 return end < len2 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 Return STRING's tick counter, incremented for each change to the string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 Each string has a tick counter which is incremented each time the contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 of the string are changed (e.g. with `aset'). It wraps around occasionally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 CHECK_STRING (string);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
521 if (CONSP (XSTRING_PLIST (string)) && INTP (XCAR (XSTRING_PLIST (string))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
522 return XCAR (XSTRING_PLIST (string));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 return Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 bump_string_modiff (Lisp_Object str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
530 Lisp_Object *ptr = &XSTRING_PLIST (str);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 #ifdef I18N3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 /* #### remove the `string-translatable' property from the string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 if there is one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 /* skip over extent info if it's there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 ptr = &XCDR (*ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
540 XCAR (*ptr) = make_int (1+XINT (XCAR (*ptr)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 *ptr = Fcons (make_int (1), *ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 static Lisp_Object concat (int nargs, Lisp_Object *args,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 enum concat_target_type target_type,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 int last_special);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
552 concat2 (Lisp_Object string1, Lisp_Object string2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 Lisp_Object args[2];
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
555 args[0] = string1;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
556 args[1] = string2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 return concat (2, args, c_string, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
561 concat3 (Lisp_Object string1, Lisp_Object string2, Lisp_Object string3)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 Lisp_Object args[3];
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
564 args[0] = string1;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
565 args[1] = string2;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
566 args[2] = string3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 return concat (3, args, c_string, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
571 vconcat2 (Lisp_Object vec1, Lisp_Object vec2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 Lisp_Object args[2];
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
574 args[0] = vec1;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
575 args[1] = vec2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 return concat (2, args, c_vector, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
580 vconcat3 (Lisp_Object vec1, Lisp_Object vec2, Lisp_Object vec3)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 Lisp_Object args[3];
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
583 args[0] = vec1;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
584 args[1] = vec2;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
585 args[2] = vec3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 return concat (3, args, c_vector, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 DEFUN ("append", Fappend, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 Concatenate all the arguments and make the result a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 The result is a list whose elements are the elements of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 Each argument may be a list, vector, bit vector, or string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 The last argument is not copied, just used as the tail of the new list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 Also see: `nconc'.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
595
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
596 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 return concat (nargs, args, c_cons, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 DEFUN ("concat", Fconcat, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 Concatenate all the arguments and make the result a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 The result is a string whose elements are the elements of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 Each argument may be a string or a list or vector of characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 As of XEmacs 21.0, this function does NOT accept individual integers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 as arguments. Old code that relies on, for example, (concat "foo" 50)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 returning "foo50" will fail. To fix such code, either apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 `int-to-string' to the integer argument, or use `format'.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
612
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
613 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 return concat (nargs, args, c_string, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 Concatenate all the arguments and make the result a vector.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 The result is a vector whose elements are the elements of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 Each argument may be a list, vector, bit vector, or string.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
624
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
625 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 return concat (nargs, args, c_vector, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 Concatenate all the arguments and make the result a bit vector.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 The result is a bit vector whose elements are the elements of all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 arguments. Each argument may be a list, vector, bit vector, or string.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
636
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
637 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 return concat (nargs, args, c_bit_vector, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 /* Copy a (possibly dotted) list. LIST must be a cons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 copy_list (Lisp_Object list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 Lisp_Object last = list_copy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 Lisp_Object hare, tortoise;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
652 Elemcount len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 for (tortoise = hare = XCDR (list), len = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 CONSP (hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 hare = XCDR (hare), len++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 XCDR (last) = Fcons (XCAR (hare), XCDR (hare));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 last = XCDR (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 if (len < CIRCULAR_LIST_SUSPICION_LENGTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 if (len & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 if (EQ (tortoise, hare))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 signal_circular_list_error (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 return list_copy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 Return a copy of list LIST, which may be a dotted list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 The elements of LIST are not copied; they are shared
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 with the original.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 again:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 if (NILP (list)) return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 if (CONSP (list)) return copy_list (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 list = wrong_type_argument (Qlistp, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 goto again;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 Return a copy of list, vector, bit vector or string SEQUENCE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 The elements of a list or vector are not copied; they are shared
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 with the original. SEQUENCE may be a dotted list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 again:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 if (NILP (sequence)) return sequence;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 if (CONSP (sequence)) return copy_list (sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 check_losing_bytecode ("copy-sequence", sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 sequence = wrong_type_argument (Qsequencep, sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 goto again;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 struct merge_string_extents_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 Lisp_Object string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 Bytecount entry_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 Bytecount entry_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 concat (int nargs, Lisp_Object *args,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 enum concat_target_type target_type,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 int last_special)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 Lisp_Object val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 Lisp_Object tail = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 int toindex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 int argnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 Lisp_Object last_tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 Lisp_Object prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 struct merge_string_extents_struct *args_mse = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
725 Ibyte *string_result = 0;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
726 Ibyte *string_result_ptr = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 struct gcpro gcpro1;
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
728 int sdep = specpdl_depth ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 /* The modus operandi in Emacs is "caller gc-protects args".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 However, concat is called many times in Emacs on freshly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 created stuff. So we help those callers out by protecting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 the args ourselves to save them a lot of temporary-variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 grief. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 GCPRO1 (args[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 gcpro1.nvars = nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 #ifdef I18N3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 /* #### if the result is a string and any of the strings have a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 for the `string-translatable' property, then concat should also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 concat the args but use the `string-translatable' strings, and store
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 the result in the returned string's `string-translatable' property. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 if (target_type == c_string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 args_mse = alloca_array (struct merge_string_extents_struct, nargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 /* In append, the last arg isn't treated like the others */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 if (last_special && nargs > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 nargs--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 last_tail = args[nargs];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 last_tail = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 /* Check and coerce the arguments. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 for (argnum = 0; argnum < nargs; argnum++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 Lisp_Object seq = args[argnum];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 if (LISTP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 else if (COMPILED_FUNCTIONP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 /* Urk! We allow this, for "compatibility"... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 #if 0 /* removed for XEmacs 21 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 else if (INTP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 /* This is too revolting to think about but maintains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 compatibility with FSF (and lots and lots of old code). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 args[argnum] = Fnumber_to_string (seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 check_losing_bytecode ("concat", seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 args[argnum] = wrong_type_argument (Qsequencep, seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 if (args_mse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 if (STRINGP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 args_mse[argnum].string = seq;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 args_mse[argnum].string = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 /* Charcount is a misnomer here as we might be dealing with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 length of a vector or list, but emphasizes that we're not dealing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 with Bytecounts in strings */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 Charcount total_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 for (argnum = 0, total_length = 0; argnum < nargs; argnum++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 Charcount thislen = length_with_bytecode_hack (args[argnum]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 Charcount thislen = XINT (Flength (args[argnum]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 total_length += thislen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 switch (target_type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 case c_cons:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 if (total_length == 0)
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
811 {
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
812 unbind_to (sdep);
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
813 /* In append, if all but last arg are nil, return last arg */
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
814 RETURN_UNGCPRO (last_tail);
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
815 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 val = Fmake_list (make_int (total_length), Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 case c_vector:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 val = make_vector (total_length, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 case c_bit_vector:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 val = make_bit_vector (total_length, Qzero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 case c_string:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 /* We don't make the string yet because we don't know the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 actual number of bytes. This loop was formerly written
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 to call Fmake_string() here and then call set_string_char()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 for each char. This seems logical enough but is waaaaaaaay
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 slow -- set_string_char() has to scan the whole string up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 to the place where the substitution is called for in order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 to find the place to change, and may have to do some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 realloc()ing in order to make the char fit properly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 O(N^2) yuckage. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 val = Qnil;
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
835 string_result =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
836 (Ibyte *) MALLOC_OR_ALLOCA (total_length * MAX_ICHAR_LEN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 string_result_ptr = string_result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 default:
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
840 val = Qnil;
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
841 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 if (CONSP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 tail = val, toindex = -1; /* -1 in toindex is flag we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 making a list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 toindex = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 prev = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 for (argnum = 0; argnum < nargs; argnum++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 Charcount thisleni = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 Charcount thisindex = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 Lisp_Object seq = args[argnum];
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
859 Ibyte *string_source_ptr = 0;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
860 Ibyte *string_prev_result_ptr = string_result_ptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 if (!CONSP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 thisleni = length_with_bytecode_hack (seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 thisleni = XINT (Flength (seq));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 if (STRINGP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 string_source_ptr = XSTRING_DATA (seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 Lisp_Object elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 /* We've come to the end of this arg, so exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 if (NILP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 /* Fetch next element of `seq' arg into `elt' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 if (CONSP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 elt = XCAR (seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 seq = XCDR (seq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 if (thisindex >= thisleni)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 if (STRINGP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
894 elt = make_char (itext_ichar (string_source_ptr));
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
895 INC_IBYTEPTR (string_source_ptr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 else if (VECTORP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 elt = XVECTOR_DATA (seq)[thisindex];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 else if (BIT_VECTORP (seq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 thisindex));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 elt = Felt (seq, make_int (thisindex));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 thisindex++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 /* Store into result */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 if (toindex < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 /* toindex negative means we are making a list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 XCAR (tail) = elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 prev = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 tail = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 else if (VECTORP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 XVECTOR_DATA (val)[toindex++] = elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 else if (BIT_VECTORP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 CHECK_BIT (elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 CHECK_CHAR_COERCE_INT (elt);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
925 string_result_ptr += set_itext_ichar (string_result_ptr,
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
926 XCHAR (elt));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 if (args_mse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 args_mse[argnum].entry_offset =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 string_prev_result_ptr - string_result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 args_mse[argnum].entry_length =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 string_result_ptr - string_prev_result_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 /* Now we finally make the string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 if (target_type == c_string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 val = make_string (string_result, string_result_ptr - string_result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 for (argnum = 0; argnum < nargs; argnum++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 if (STRINGP (args_mse[argnum].string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 copy_string_extents (val, args_mse[argnum].string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 args_mse[argnum].entry_offset, 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 args_mse[argnum].entry_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 if (!NILP (prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 XCDR (prev) = last_tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
954 unbind_to (sdep);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 RETURN_UNGCPRO (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 Return a copy of ALIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 This is an alist which represents the same mapping from objects to objects,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 but does not share the alist structure with ALIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 The objects mapped (cars and cdrs of elements of the alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 are shared, however.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 Elements of ALIST that are not conses are also shared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 (alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 Lisp_Object tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 if (NILP (alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 return alist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 CHECK_CONS (alist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 alist = concat (1, &alist, c_cons, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 Lisp_Object car = XCAR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 if (CONSP (car))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 XCAR (tail) = Fcons (XCAR (car), XCDR (car));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 return alist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 Return a copy of a list and substructures.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 The argument is copied, and any lists contained within it are copied
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 recursively. Circularities and shared substructures are not preserved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 Second arg VECP causes vectors to be copied, too. Strings and bit vectors
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 are not copied.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 (arg, vecp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 {
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
994 return safe_copy_tree (arg, vecp, 0);
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
995 }
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
996
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
997 Lisp_Object
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
998 safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth)
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
999 {
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
1000 if (depth > 200)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
1001 stack_overflow ("Stack overflow in copy-tree", arg);
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
1002
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 if (CONSP (arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 rest = arg = Fcopy_sequence (arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 while (CONSP (rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 Lisp_Object elt = XCAR (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 if (CONSP (elt) || VECTORP (elt))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
1012 XCAR (rest) = safe_copy_tree (elt, vecp, depth + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
1014 XCDR (rest) = safe_copy_tree (XCDR (rest), vecp, depth +1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 rest = XCDR (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 else if (VECTORP (arg) && ! NILP (vecp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 int i = XVECTOR_LENGTH (arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 int j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 arg = Fcopy_sequence (arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 for (j = 0; j < i; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 Lisp_Object elt = XVECTOR_DATA (arg) [j];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 if (CONSP (elt) || VECTORP (elt))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 444
diff changeset
1028 XVECTOR_DATA (arg) [j] = safe_copy_tree (elt, vecp, depth + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 return arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 DEFUN ("subseq", Fsubseq, 2, 3, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1035 Return the subsequence of SEQUENCE starting at START and ending before END.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1036 END may be omitted; then the subsequence runs to the end of SEQUENCE.
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1037
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1038 If START or END is negative, it counts from the end, in contravention of
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1039 Common Lisp.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1040 The returned subsequence is always of the same type as SEQUENCE.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1041 If SEQUENCE is a string, relevant parts of the string-extent-data
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1042 are copied to the new string.
5224
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1043
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1044 See also `substring-no-properties', which only operates on strings, and does
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1045 not copy extent data.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1047 (sequence, start, end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1049 Elemcount len, ss, ee = EMACS_INT_MAX, ii;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1050 Lisp_Object result = Qnil;
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5051
diff changeset
1051
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
1052 CHECK_SEQUENCE (sequence);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1053 CHECK_INT (start);
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1054 ss = XINT (start);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1055
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1056 if (!NILP (end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1058 CHECK_INT (end);
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1059 ee = XINT (end);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1060 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1061
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1062 if (STRINGP (sequence))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1063 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1064 Bytecount bstart, blen;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1065
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1066 get_string_range_char (sequence, start, end, &ss, &ee,
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1067 GB_HISTORICAL_STRING_BEHAVIOR);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1068 bstart = string_index_char_to_byte (sequence, ss);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1069 blen = string_offset_char_to_byte_len (sequence, bstart, ee - ss);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1070
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1071 result = make_string (XSTRING_DATA (sequence) + bstart, blen);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1072 /* Copy any applicable extent information into the new string. */
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1073 copy_string_extents (result, sequence, 0, bstart, blen);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1074 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1075 else if (CONSP (sequence))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1076 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1077 Lisp_Object result_tail, saved = sequence;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1078
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1079 if (ss < 0 || ee < 0)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1080 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1081 len = XINT (Flength (sequence));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1082 if (ss < 0)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1083 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1084 ss = len + ss;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1085 start = make_integer (ss);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1086 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1087
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1088 if (ee < 0)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1089 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1090 ee = len + ee;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1091 end = make_integer (ee);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1092 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1093 else
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1094 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1095 ee = min (ee, len);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1096 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1097 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1098
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1099 if (0 != ss)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1100 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1101 sequence = Fnthcdr (make_int (ss), sequence);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1102 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1103
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1104 if (ss < ee && !NILP (sequence))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1105 {
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
1106 result = result_tail = Fcons (Fcar (sequence), Qnil);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1107 sequence = Fcdr (sequence);
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1108 ii = ss + 1;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1109
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1110 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1111 EXTERNAL_LIST_LOOP_2 (elt, sequence)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1112 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1113 if (!(ii < ee))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1114 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1115 break;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1116 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1117
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1118 XSETCDR (result_tail, Fcons (elt, Qnil));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1119 result_tail = XCDR (result_tail);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1120 ii++;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1121 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1122 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1123 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1124
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1125 if (NILP (result) || (ii < ee && !NILP (end)))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1126 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1127 /* We were handed a cons, which definitely has elements. nil
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1128 result means either ss >= ee or SEQUENCE was nil after the
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1129 nthcdr; in both cases that means START and END were incorrectly
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1130 specified for this sequence. ii < ee with a non-nil end means
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1131 the user handed us a bogus end value. */
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1132 check_sequence_range (saved, start, end, Flength (saved));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1133 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1134 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1135 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1136 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1137 len = XINT (Flength (sequence));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1138 if (ss < 0)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1139 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1140 ss = len + ss;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1141 start = make_integer (ss);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1142 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1143
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1144 if (ee < 0)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1145 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1146 ee = len + ee;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1147 end = make_integer (ee);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1148 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1149 else
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1150 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1151 ee = min (len, ee);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1152 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1153
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1154 check_sequence_range (sequence, start, end, make_int (len));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1155
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1156 if (VECTORP (sequence))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1157 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1158 result = Fvector (ee - ss, XVECTOR_DATA (sequence) + ss);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1159 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1160 else if (BIT_VECTORP (sequence))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1161 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1162 result = make_bit_vector (ee - ss, Qzero);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1163
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1164 for (ii = ss; ii < ee; ii++)
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1165 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1166 set_bit_vector_bit (XBIT_VECTOR (result), ii - ss,
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1167 bit_vector_bit (XBIT_VECTOR (sequence), ii));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1168 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1169 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1170 else if (NILP (sequence))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1171 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1172 DO_NOTHING;
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1173 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1174 else
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1175 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1176 /* Won't happen, since CHECK_SEQUENCE didn't error. */
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1177 ABORT ();
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1178 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1179 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1180
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
1181 return result;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183
5224
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1184 DEFUN ("substring-no-properties", Fsubstring_no_properties, 1, 3, 0, /*
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1185 Return a substring of STRING, without copying the extents.
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1186 END may be nil or omitted; then the substring runs to the end of STRING.
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1187 If START or END is negative, it counts from the end.
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1188
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1189 With one argument, copy STRING without its properties.
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1190 */
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1191 (string, start, end))
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1192 {
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1193 Charcount ccstart, ccend;
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1194 Bytecount bstart, blen;
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1195 Lisp_Object val;
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1196
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1197 get_string_range_char (string, start, end, &ccstart, &ccend,
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1198 GB_HISTORICAL_STRING_BEHAVIOR);
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1199 bstart = string_index_char_to_byte (string, ccstart);
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1200 blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart);
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1201 val = make_string (XSTRING_DATA (string) + bstart, blen);
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1202
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1203 return val;
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1204 }
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
1205
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1206 /* Split STRING into a list of substrings. The substrings are the
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1207 parts of original STRING separated by SEPCHAR.
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1208
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1209 If UNESCAPE is non-zero, ESCAPECHAR specifies a character that will quote
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1210 SEPCHAR, and cause it not to split STRING. A double ESCAPECHAR is
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1211 necessary for ESCAPECHAR to appear once in a substring. */
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1212
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1213 static Lisp_Object
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1214 split_string_by_ichar_1 (const Ibyte *string, Bytecount size,
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1215 Ichar sepchar, int unescape, Ichar escapechar)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1216 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1217 Lisp_Object result = Qnil;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1218 const Ibyte *end = string + size;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1219
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1220 if (unescape)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1221 {
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1222 Ibyte unescape_buffer[64], *unescape_buffer_ptr = unescape_buffer,
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1223 escaped[MAX_ICHAR_LEN], *unescape_cursor;
5036
9624523604c5 Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents: 5035
diff changeset
1224 Bytecount unescape_buffer_size = countof (unescape_buffer),
9624523604c5 Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents: 5035
diff changeset
1225 escaped_len = set_itext_ichar (escaped, escapechar);
9624523604c5 Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents: 5035
diff changeset
1226 Boolint deleting_escapes, previous_escaped;
9624523604c5 Use better types when ESCAPECHAR is specified, split_string_by_ichar_1
Aidan Kehoe <kehoea@parhasard.net>
parents: 5035
diff changeset
1227 Ichar pchar;
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1228
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1229 while (1)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1230 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1231 const Ibyte *p = string, *cursor;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1232 deleting_escapes = 0;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1233 previous_escaped = 0;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1234
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1235 while (p < end)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1236 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1237 pchar = itext_ichar (p);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1238
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1239 if (pchar == sepchar)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1240 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1241 if (!previous_escaped)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1242 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1243 break;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1244 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1245 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1246 else if (pchar == escapechar
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1247 /* Doubled escapes don't escape: */
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1248 && !previous_escaped)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1249 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1250 ++deleting_escapes;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1251 previous_escaped = 1;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1252 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1253 else
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1254 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1255 previous_escaped = 0;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1256 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1257
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1258 INC_IBYTEPTR (p);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1259 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1260
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1261 if (deleting_escapes)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1262 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1263 if (((p - string) - (escaped_len * deleting_escapes))
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1264 > unescape_buffer_size)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1265 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1266 unescape_buffer_size =
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1267 ((p - string) - (escaped_len * deleting_escapes)) * 1.5;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1268 unescape_buffer_ptr = alloca_ibytes (unescape_buffer_size);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1269 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1270
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1271 cursor = string;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1272 unescape_cursor = unescape_buffer_ptr;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1273 previous_escaped = 0;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1274
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1275 while (cursor < p)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1276 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1277 pchar = itext_ichar (cursor);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1278
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1279 if (pchar != escapechar || previous_escaped)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1280 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1281 memcpy (unescape_cursor, cursor,
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1282 itext_ichar_len (cursor));
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1283 INC_IBYTEPTR (unescape_cursor);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1284 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1285
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1286 previous_escaped = !previous_escaped
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1287 && (pchar == escapechar);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1288
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1289 INC_IBYTEPTR (cursor);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1290 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1291
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1292 result = Fcons (make_string (unescape_buffer_ptr,
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1293 unescape_cursor
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1294 - unescape_buffer_ptr),
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1295 result);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1296 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1297 else
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1298 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1299 result = Fcons (make_string (string, p - string), result);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1300 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1301 if (p < end)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1302 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1303 string = p;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1304 INC_IBYTEPTR (string); /* skip sepchar */
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1305 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1306 else
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1307 break;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1308 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1309 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1310 else
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1311 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1312 while (1)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1313 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1314 const Ibyte *p = string;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1315 while (p < end)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1316 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1317 if (itext_ichar (p) == sepchar)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1318 break;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1319 INC_IBYTEPTR (p);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1320 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1321 result = Fcons (make_string (string, p - string), result);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1322 if (p < end)
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1323 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1324 string = p;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1325 INC_IBYTEPTR (string); /* skip sepchar */
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1326 }
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1327 else
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1328 break;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1329 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1330 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1331 return Fnreverse (result);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1332 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1333
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1334 /* The same as the above, except PATH is an external C string (it is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1335 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1336 (':' or whatever). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1337 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1338 split_external_path (const Extbyte *path)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1339 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1340 Bytecount newlen;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1341 Ibyte *newpath;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1342 if (!path)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1343 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1344
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1345 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1346
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1347 /* #### Does this make sense? It certainly does for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1348 split_env_path(), but it looks dubious here. Does any code
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1349 depend on split_external_path("") returning nil instead of an empty
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1350 string? */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1351 if (!newlen)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1352 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1353
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1354 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR, 0, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1355 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1356
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1357 Lisp_Object
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1358 split_env_path (const CIbyte *evarname, const Ibyte *default_)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1359 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1360 const Ibyte *path = 0;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1361 if (evarname)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1362 path = egetenv (evarname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1363 if (!path)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1364 path = default_;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1365 if (!path)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1366 return Qnil;
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1367 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR, 0, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1368 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1369
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1370 /* Ben thinks this function should not exist or be exported to Lisp.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1371 We use it to define split-path-string in subr.el (not!). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1372
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1373 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 3, 0, /*
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1374 Split STRING into a list of substrings originally separated by SEPCHAR.
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1375
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1376 With optional ESCAPE-CHAR, any instances of SEPCHAR preceded by that
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1377 character will not split the string, and a double instance of ESCAPE-CHAR
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1378 will be necessary for a single ESCAPE-CHAR to appear in the output string.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1379 */
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1380 (string, sepchar, escape_char))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1381 {
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1382 Ichar escape_ichar = 0;
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1383
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1384 CHECK_STRING (string);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1385 CHECK_CHAR (sepchar);
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1386 if (!NILP (escape_char))
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1387 {
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1388 CHECK_CHAR (escape_char);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1389 escape_ichar = XCHAR (escape_char);
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1390 }
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1391 return split_string_by_ichar_1 (XSTRING_DATA (string),
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1392 XSTRING_LENGTH (string),
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1393 XCHAR (sepchar),
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1394 !NILP (escape_char), escape_ichar);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1395 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1396
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1397 /* #### This was supposed to be in subr.el, but is used VERY early in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1398 the bootstrap process, so it goes here. Damn. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1399
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1400 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1401 Explode a search path into a list of strings.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1402 The path components are separated with the characters specified
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1403 with `path-separator'.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1404 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1405 (path))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1406 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1407 CHECK_STRING (path);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1408
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1409 while (!STRINGP (Vpath_separator)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1410 || (string_char_length (Vpath_separator) != 1))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1411 Vpath_separator = signal_continuable_error
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1412 (Qinvalid_state,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1413 "`path-separator' should be set to a single-character string",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1414 Vpath_separator);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1415
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1416 return (split_string_by_ichar_1
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1417 (XSTRING_DATA (path), XSTRING_LENGTH (path),
5035
b1e48555be7d Add a new optional ESCAPE-CHAR argument to #'split-string-by-char.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5034
diff changeset
1418 itext_ichar (XSTRING_DATA (Vpath_separator)), 0, 0));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1419 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1420
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 Take cdr N times on LIST, and return the result.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 (n, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 {
1920
c66036f59678 [xemacs-hg @ 2004-02-20 07:29:16 by stephent]
stephent
parents: 1849
diff changeset
1427 /* This function can GC */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 578
diff changeset
1428 REGISTER EMACS_INT i;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 REGISTER Lisp_Object tail = list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 CHECK_NATNUM (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 for (i = XINT (n); i; i--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 if (CONSP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 tail = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 else if (NILP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 tail = wrong_type_argument (Qlistp, tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 return tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 DEFUN ("nth", Fnth, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 Return the Nth element of LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 N counts from zero. If LIST is not that long, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 (n, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 {
1920
c66036f59678 [xemacs-hg @ 2004-02-20 07:29:16 by stephent]
stephent
parents: 1849
diff changeset
1452 /* This function can GC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 return Fcar (Fnthcdr (n, list));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 DEFUN ("elt", Felt, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 Return element of SEQUENCE at index N.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 (sequence, n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 {
1920
c66036f59678 [xemacs-hg @ 2004-02-20 07:29:16 by stephent]
stephent
parents: 1849
diff changeset
1461 /* This function can GC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 CHECK_INT_COERCE_CHAR (n); /* yuck! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 if (LISTP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 Lisp_Object tem = Fnthcdr (n, sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 /* #### Utterly, completely, fucking disgusting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 * #### The whole point of "elt" is that it operates on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 * #### sequences, and does error- (bounds-) checking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 if (CONSP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 return XCAR (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 #if 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 /* This is The Way It Has Always Been. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 /* This is The Way Mly and Cltl2 say It Should Be. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 args_out_of_range (sequence, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 else if (STRINGP (sequence) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 VECTORP (sequence) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 BIT_VECTORP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 return Faref (sequence, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 else if (COMPILED_FUNCTIONP (sequence))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 EMACS_INT idx = XINT (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 if (idx < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 lose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 args_out_of_range (sequence, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 /* Utter perversity */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 switch (idx)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 case COMPILED_ARGLIST:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 return compiled_function_arglist (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 case COMPILED_INSTRUCTIONS:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 return compiled_function_instructions (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 case COMPILED_CONSTANTS:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 return compiled_function_constants (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 case COMPILED_STACK_DEPTH:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 return compiled_function_stack_depth (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 case COMPILED_DOC_STRING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 return compiled_function_documentation (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 case COMPILED_DOMAIN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 return compiled_function_domain (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 case COMPILED_INTERACTIVE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 if (f->flags.interactivep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 return compiled_function_interactive (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 /* if we return nil, can't tell interactive with no args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 from noninteractive. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 #endif /* LOSING_BYTECODE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 check_losing_bytecode ("elt", sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 sequence = wrong_type_argument (Qsequencep, sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 DEFUN ("last", Flast, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 Return the tail of list LIST, of length N (default 1).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 LIST may be a dotted list, but not a circular list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 Optional argument N must be a non-negative integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 If N is zero, then the atom that terminates the list is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 If N is greater than the length of LIST, then LIST itself is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 (list, n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 EMACS_INT int_n, count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 Lisp_Object retval, tortoise, hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 CHECK_LIST (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 if (NILP (n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 int_n = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 CHECK_NATNUM (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 int_n = XINT (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 for (retval = tortoise = hare = list, count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 CONSP (hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 hare = XCDR (hare),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 if (count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 if (EQ (hare, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 signal_circular_list_error (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 return retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 Modify LIST to remove the last N (default 1) elements.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 If LIST has N or fewer elements, nil is returned and LIST is unmodified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 (list, n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 EMACS_INT int_n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 CHECK_LIST (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 if (NILP (n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 int_n = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 CHECK_NATNUM (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 int_n = XINT (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 Lisp_Object last_cons = list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 EXTERNAL_LIST_LOOP_1 (list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 if (int_n-- < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 last_cons = XCDR (last_cons);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 if (int_n >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 XCDR (last_cons) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 DEFUN ("butlast", Fbutlast, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 Return a copy of LIST with the last N (default 1) elements removed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 If LIST has N or fewer elements, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 (list, n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1612 EMACS_INT int_n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 CHECK_LIST (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 if (NILP (n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 int_n = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 CHECK_NATNUM (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 int_n = XINT (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 Lisp_Object retval = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 Lisp_Object tail = list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 EXTERNAL_LIST_LOOP_1 (list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 if (--int_n < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 retval = Fcons (XCAR (tail), retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 tail = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 return Fnreverse (retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 DEFUN ("member", Fmember, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 The value is actually the tail of LIST whose car is ELT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 if (internal_equal (elt, list_elt, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 return tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 The value is actually the tail of LIST whose car is ELT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 This function is provided only for byte-code compatibility with v19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 Do not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 if (internal_old_equal (elt, list_elt, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 return tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 DEFUN ("memq", Fmemq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 The value is actually the tail of LIST whose car is ELT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 return tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 The value is actually the tail of LIST whose car is ELT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 This function is provided only for byte-code compatibility with v19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 Do not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 if (HACKEQ_UNSAFE (elt, list_elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 return tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 memq_no_quit (Lisp_Object elt, Lisp_Object list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 LIST_LOOP_3 (list_elt, list, tail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 return tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 DEFUN ("assoc", Fassoc, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1713 Return non-nil if KEY is `equal' to the car of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1714 The value is actually the element of ALIST whose car equals KEY.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1716 (key, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 /* This function can GC. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1719 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 if (internal_equal (key, elt_car, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1728 Return non-nil if KEY is `old-equal' to the car of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1729 The value is actually the element of ALIST whose car equals KEY.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1731 (key, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 /* This function can GC. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1734 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 if (internal_old_equal (key, elt_car, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1743 assoc_no_quit (Lisp_Object key, Lisp_Object alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 specbind (Qinhibit_quit, Qt);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1747 return unbind_to_1 (speccount, Fassoc (key, alist));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 DEFUN ("assq", Fassq, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1751 Return non-nil if KEY is `eq' to the car of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1752 The value is actually the element of ALIST whose car is KEY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1753 Elements of ALIST that are not conses are ignored.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1755 (key, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1757 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 if (EQ_WITH_EBOLA_NOTICE (key, elt_car))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1766 Return non-nil if KEY is `old-eq' to the car of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1767 The value is actually the element of ALIST whose car is KEY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1768 Elements of ALIST that are not conses are ignored.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 This function is provided only for byte-code compatibility with v19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 Do not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1772 (key, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1774 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 if (HACKEQ_UNSAFE (key, elt_car))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 /* Like Fassq but never report an error and do not allow quits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 Use only on lists known never to be circular. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1786 assq_no_quit (Lisp_Object key, Lisp_Object alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 /* This cannot GC. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1789 LIST_LOOP_2 (elt, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 Lisp_Object elt_car = XCAR (elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 if (EQ_WITH_EBOLA_NOTICE (key, elt_car))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 DEFUN ("rassoc", Frassoc, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1799 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1800 The value is actually the element of ALIST whose cdr equals VALUE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1802 (value, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1804 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1806 if (internal_equal (value, elt_cdr, 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1813 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1814 The value is actually the element of ALIST whose cdr equals VALUE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1816 (value, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1818 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1820 if (internal_old_equal (value, elt_cdr, 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 DEFUN ("rassq", Frassq, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1827 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1828 The value is actually the element of ALIST whose cdr is VALUE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1830 (value, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1832 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1834 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1841 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1842 The value is actually the element of ALIST whose cdr is VALUE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1844 (value, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1846 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1848 if (HACKEQ_UNSAFE (value, elt_cdr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1854 /* Like Frassq, but caller must ensure that ALIST is properly
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 nil-terminated and ebola-free. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1857 rassq_no_quit (Lisp_Object value, Lisp_Object alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1859 LIST_LOOP_2 (elt, alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 Lisp_Object elt_cdr = XCDR (elt);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1862 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 return elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 DEFUN ("delete", Fdelete, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 Delete by side effect any occurrences of ELT as a member of LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 The modified LIST is returned. Comparison is done with `equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 If the first member of LIST is ELT, there is no way to remove it by side
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 effect; therefore, write `(setq foo (delete element foo))' to be sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 of changing the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 Also see: `remove'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 (internal_equal (elt, list_elt, 0)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 Delete by side effect any occurrences of ELT as a member of LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 The modified LIST is returned. Comparison is done with `old-equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 If the first member of LIST is ELT, there is no way to remove it by side
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 effect; therefore, write `(setq foo (old-delete element foo))' to be sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 of changing the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 (internal_old_equal (elt, list_elt, 0)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 DEFUN ("delq", Fdelq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 Delete by side effect any occurrences of ELT as a member of LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 The modified LIST is returned. Comparison is done with `eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 If the first member of LIST is ELT, there is no way to remove it by side
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 effect; therefore, write `(setq foo (delq element foo))' to be sure of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 changing the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 (EQ_WITH_EBOLA_NOTICE (elt, list_elt)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 Delete by side effect any occurrences of ELT as a member of LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 The modified LIST is returned. Comparison is done with `old-eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 If the first member of LIST is ELT, there is no way to remove it by side
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 changing the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (elt, list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (HACKEQ_UNSAFE (elt, list_elt)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 /* Like Fdelq, but caller must ensure that LIST is properly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 nil-terminated and ebola-free. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 delq_no_quit (Lisp_Object elt, Lisp_Object list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 LIST_LOOP_DELETE_IF (list_elt, list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 (EQ_WITH_EBOLA_NOTICE (elt, list_elt)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 /* Be VERY careful with this. This is like delq_no_quit() but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 also calls free_cons() on the removed conses. You must be SURE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 that no pointers to the freed conses remain around (e.g.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 someone else is pointing to part of the list). This function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 is useful on internal lists that are used frequently and where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 the actual list doesn't escape beyond known code bounds. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 REGISTER Lisp_Object tail = list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 REGISTER Lisp_Object prev = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 while (!NILP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 REGISTER Lisp_Object tem = XCAR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 if (EQ (elt, tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 Lisp_Object cons_to_free = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 if (NILP (prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 list = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 XCDR (prev) = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 tail = XCDR (tail);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
1961 free_cons (cons_to_free);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 prev = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 tail = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1973 Delete by side effect any elements of ALIST whose car is `equal' to KEY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1974 The modified ALIST is returned. If the first member of ALIST has a car
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 that is `equal' to KEY, there is no way to remove it by side effect;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 therefore, write `(setq foo (remassoc key foo))' to be sure of changing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1979 (key, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1981 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 (CONSP (elt) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 internal_equal (key, XCAR (elt), 0)));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1984 return alist;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1988 remassoc_no_quit (Lisp_Object key, Lisp_Object alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 specbind (Qinhibit_quit, Qt);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
1992 return unbind_to_1 (speccount, Fremassoc (key, alist));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 DEFUN ("remassq", Fremassq, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1996 Delete by side effect any elements of ALIST whose car is `eq' to KEY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1997 The modified ALIST is returned. If the first member of ALIST has a car
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 that is `eq' to KEY, there is no way to remove it by side effect;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 therefore, write `(setq foo (remassq key foo))' to be sure of changing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2002 (key, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2004 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 (CONSP (elt) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt))));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2007 return alist;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 /* no quit, no errors; be careful */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2013 remassq_no_quit (Lisp_Object key, Lisp_Object alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2015 LIST_LOOP_DELETE_IF (elt, alist,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 (CONSP (elt) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt))));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2018 return alist;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2022 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2023 The modified ALIST is returned. If the first member of ALIST has a car
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 that is `equal' to VALUE, there is no way to remove it by side effect;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2028 (value, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2030 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 (CONSP (elt) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 internal_equal (value, XCDR (elt), 0)));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2033 return alist;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2037 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2038 The modified ALIST is returned. If the first member of ALIST has a car
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 that is `eq' to VALUE, there is no way to remove it by side effect;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 therefore, write `(setq foo (remrassq value foo))' to be sure of changing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 the value of `foo'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2043 (value, alist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2045 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 (CONSP (elt) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt))));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2048 return alist;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 /* Like Fremrassq, fast and unsafe; be careful */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2053 remrassq_no_quit (Lisp_Object value, Lisp_Object alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2055 LIST_LOOP_DELETE_IF (elt, alist,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 (CONSP (elt) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt))));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2058 return alist;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 Reverse LIST by destructively modifying cdr pointers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 Return the beginning of the reversed list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 Also see: `reverse'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 struct gcpro gcpro1, gcpro2;
1849
21549d437f09 [xemacs-hg @ 2004-01-03 21:54:41 by james]
james
parents: 1261
diff changeset
2069 Lisp_Object prev = Qnil;
21549d437f09 [xemacs-hg @ 2004-01-03 21:54:41 by james]
james
parents: 1261
diff changeset
2070 Lisp_Object tail = list;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 /* We gcpro our args; see `nconc' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 GCPRO2 (prev, tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 while (!NILP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 REGISTER Lisp_Object next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 CONCHECK_CONS (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 next = XCDR (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 XCDR (tail) = prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 prev = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 tail = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 return prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 DEFUN ("reverse", Freverse, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 Reverse LIST, copying. Return the beginning of the reversed list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 See also the function `nreverse', which is used more often.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 Lisp_Object reversed_list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 EXTERNAL_LIST_LOOP_2 (elt, list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 reversed_list = Fcons (elt, reversed_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 return reversed_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2101 static Lisp_Object
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2102 c_merge_predicate_key (Lisp_Object obj1, Lisp_Object obj2,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2103 Lisp_Object pred, Lisp_Object key_func)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2105 struct gcpro gcpro1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2106 Lisp_Object args[3];
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2107
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2108 /* We could use call2() and call3() here, but we're called O(nlogn) times
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2109 for a sequence of length n, it make some sense to inline them. */
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2110 args[0] = key_func;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2111 args[1] = obj1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2112 args[2] = Qnil;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2113
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2114 GCPRO1 (args[0]);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2115 gcpro1.nvars = countof (args);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2116
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2117 obj1 = IGNORE_MULTIPLE_VALUES (Ffuncall (2, args));
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2118
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2119 args[1] = obj2;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2120 obj2 = IGNORE_MULTIPLE_VALUES (Ffuncall (2, args));
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2121
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2122 args[0] = pred;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2123 args[1] = obj1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2124 args[2] = obj2;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2125
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2126 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2129 static Lisp_Object
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2130 c_merge_predicate_nokey (Lisp_Object obj1, Lisp_Object obj2,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2131 Lisp_Object pred, Lisp_Object UNUSED (key_func))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2133 struct gcpro gcpro1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2134 Lisp_Object args[3];
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2135
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2136 /* This is (almost) the implementation of call2, it makes some sense to
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2137 inline it here. */
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2138 args[0] = pred;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2139 args[1] = obj1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2140 args[2] = obj2;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2141
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2142 GCPRO1 (args[0]);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2143 gcpro1.nvars = countof (args);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2144
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2145 RETURN_UNGCPRO (IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2150 Lisp_Object (*c_predicate) (Lisp_Object, Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2151 Lisp_Object, Lisp_Object),
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2152 Lisp_Object predicate, Lisp_Object key_func)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 Lisp_Object value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 Lisp_Object tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 Lisp_Object l1, l2;
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2158 Lisp_Object tortoises[2];
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2159 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
5283
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2160 int l1_count = 0, l2_count = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 l1 = org_l1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 l2 = org_l2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 tail = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 value = Qnil;
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2166 tortoises[0] = org_l1;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2167 tortoises[1] = org_l2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2169 if (NULL == c_predicate)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2170 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2171 c_predicate = EQ (key_func, Qidentity) ?
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2172 c_merge_predicate_nokey : c_merge_predicate_key;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2173 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2174
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 /* It is sufficient to protect org_l1 and org_l2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 When l1 and l2 are updated, we copy the new values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 back into the org_ vars. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2179 GCPRO5 (org_l1, org_l2, predicate, value, tortoises[0]);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2180 gcpro5.nvars = 2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 if (NILP (l1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 if (NILP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 return l2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 Fsetcdr (tail, l2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 if (NILP (l2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 if (NILP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 return l1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 Fsetcdr (tail, l1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2201 if (NILP (c_predicate (Fcar (l2), Fcar (l1), predicate, key_func)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 tem = l1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 l1 = Fcdr (l1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 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
2206
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2207 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
2208 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2209 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
2210 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2211 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
2212 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2213 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
2214 }
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2215
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2216 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
2217 }
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2218
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2219 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
2220 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2221 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
2222 }
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2223 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 tem = l2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 l2 = Fcdr (l2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 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
2230
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2231 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
2232 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2233 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
2234 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2235 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
2236 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2237 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
2238 }
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 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
2241 }
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2242
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2243 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
2244 {
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2245 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
2246 }
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2247 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 }
5283
be436ac36ba4 Don't share a counter when checking for circularity, list_merge().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5277
diff changeset
2249
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 if (NILP (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 value = tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 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
2254
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 tail = tem;
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2256 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2257 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2258
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2259 static void
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2260 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
2261 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
2262 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
2263 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
2264 Lisp_Object, Lisp_Object),
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2265 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
2266 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2267 Elemcount ii, fronting, backing;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2268 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
2269 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
2270 struct gcpro gcpro1, gcpro2;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2271
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2272 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
2273
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2274 if (0 == dest_len)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2275 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2276 return;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2277 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2278
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2279 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
2280 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2281 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
2282
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2283 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
2284 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2285 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
2286 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2287 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2288
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2289 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
2290 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2291 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
2292
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2293 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
2294 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2295 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
2296 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2297 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2298
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2299 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
2300 gcpro1.nvars = front_len;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2301 gcpro2.nvars = back_len;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2302
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2303 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
2304 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2305 if (fronting >= 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 while (ii < 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 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
2310 ++ii, ++backing;
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 UNGCPRO;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2313 return;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2314 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2315
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2316 if (backing >= back_len)
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 while (ii < dest_len)
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 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
2321 ++ii, ++fronting;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2322 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2323 UNGCPRO;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2324 return;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2325 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2326
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2327 if (NILP (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
2328 predicate, key_func)))
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 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
2331 ++fronting;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2332 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2333 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2334 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2335 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
2336 ++backing;
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 }
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 UNGCPRO;
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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2343 static Lisp_Object
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2344 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
2345 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
2346 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
2347 Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2348 Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2349 Lisp_Object),
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2350 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
2351 Boolint reverse_order)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2352 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2353 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
2354 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
2355 Elemcount array_index = 0;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2356 int looped = 0;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2357
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2358 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
2359
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2360 while (1)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2361 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2362 if (NILP (list))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2363 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2364 UNGCPRO;
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 if (NILP (tail))
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 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
2369 }
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 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
2372 return value;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2373 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2374
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2375 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
2376 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2377 UNGCPRO;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2378 if (NILP (tail))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2379 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2380 return list;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2381 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2382
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2383 Fsetcdr (tail, list);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2384 return value;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2385 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2386
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2387
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2388 if (reverse_order ?
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2389 !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
2390 key_func)) :
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2391 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
2392 key_func)))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2393 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2394 if (NILP (tail))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2395 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2396 value = tail = list;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2397 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2398 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2399 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2400 Fsetcdr (tail, list);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2401 tail = XCDR (tail);
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 list = Fcdr (list);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2405 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2406 else
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 (NILP (tail))
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 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
2411 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2412 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2413 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2414 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
2415 tail = XCDR (tail);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2416 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2417 ++array_index;
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
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2420 if (++looped > CIRCULAR_LIST_SUSPICION_LENGTH)
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2421 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2422 if (looped & 1)
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2423 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2424 tortoise = XCDR (tortoise);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2425 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2426
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2427 if (EQ (list, tortoise))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2428 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2429 signal_circular_list_error (list);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2430 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2431 }
5182
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 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2434
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2435 static void
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2436 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
2437 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
2438 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
2439 Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2440 Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2441 Lisp_Object),
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2442 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
2443 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2444 Elemcount output_index = 0;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2445
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2446 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
2447 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2448 if (NILP (list_one))
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 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
2451 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2452 output [output_index] = Fcar (list_two);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2453 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
2454 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2455 return;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2456 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2457
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2458 if (NILP (list_two))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2459 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2460 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
2461 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2462 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
2463 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
2464 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2465 return;
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 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
2469 key_func)))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2470 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2471 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
2472 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
2473 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2474 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2475 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2476 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
2477 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
2478 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2479
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2480 ++output_index;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2481
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2482 /* 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
2483 }
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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2486 static void
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2487 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
2488 Lisp_Object list,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2489 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
2490 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
2491 Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2492 Lisp_Object,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2493 Lisp_Object),
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2494 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
2495 Boolint reverse_order)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2496 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2497 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
2498
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2499 while (output_index < output_len)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2500 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2501 if (NILP (list))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2502 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2503 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
2504 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
2505 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
2506 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2507
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2508 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
2509 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2510 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
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 return;
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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2516 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
2517 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2518 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
2519 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2520 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
2521 list = Fcdr (list);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2522 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2523
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2524 return;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2525 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2526
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2527 if (reverse_order ?
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2528 !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
2529 key_func)) :
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2530 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
2531 key_func)))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2532 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2533 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
2534 list = XCDR (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 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2537 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2538 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
2539 ++array_index;
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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2542 ++output_index;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2546 #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
2547 do { \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2548 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
2549 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
2550 { \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2551 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
2552 INC_IBYTEPTR (strdata); \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2553 } \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2554 } while (0)
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 #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
2557 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
2558 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
2559 { \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2560 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
2561 } \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2562 } while (0)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2563
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2564 /* 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
2565
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2566 #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
2567 do { \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2568 if (NILP (key)) \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2569 { \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2570 key = Qidentity; \
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2571 } \
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2572 \
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2573 if (!EQ (key, Qidentity)) \
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2574 { \
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2575 key = indirect_function (key, 1); \
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2576 } \
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2577 } while (0)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2578
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2579 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
2580 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
2581
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2582 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
2583 predicate on the elements.
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2584
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2585 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
2586 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
2587
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2588 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
2589 */
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2590 (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
2591 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2592 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
2593 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
2594 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
2595 Lisp_Object);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2596
5277
d804e621add0 Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5275
diff changeset
2597 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
2598
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2599 CHECK_SEQUENCE (sequence_one);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2600 CHECK_SEQUENCE (sequence_two);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2601
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2602 CHECK_KEY_ARGUMENT (key);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2603
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2604 c_predicate = EQ (key, Qidentity) ?
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2605 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
2606
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2607 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
2608 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2609 if (NILP (sequence_two))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2610 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2611 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
2612 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2613 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
2614 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2615 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
2616 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
2617 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
2618 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2619 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
2620 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2621 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
2622 predicate, key);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2623 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2624 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2625 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2626 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
2627 Elemcount array_length, i;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2628 Boolint reverse_order = 0;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2629
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2630 if (!CONSP (sequence_one))
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 /* 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
2633 swap = sequence_one;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2634 sequence_one = sequence_two;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2635 sequence_two = swap;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2636 reverse_order = 1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2637 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2638
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2639 if (VECTORP (sequence_two))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2640 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2641 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
2642 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
2643 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2644 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
2645 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2646 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
2647 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
2648 /* 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
2649 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
2650 array_length);
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 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2653 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2654 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2655 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
2656 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
2657 /* 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
2658 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
2659 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2660
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2661 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
2662 array_storage, array_length,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2663 c_predicate,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2664 predicate, key,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2665 reverse_order);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2666 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2667 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2668 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2669 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2670 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
2671 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
2672 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
2673 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
2674 *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
2675 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
2676 || 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
2677 Ibyte *strdata = NULL;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2678 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
2679 struct gcpro gcpro1;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2680
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2681 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
2682 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
2683 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2684 output[i] = Qnil;
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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2687 GCPRO1 (output[0]);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2688 gcpro1.nvars = output_len;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2689
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2690 if (VECTORP (sequence_one))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2691 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2692 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
2693 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2694 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
2695 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2696 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
2697 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
2698 i, sequence_one_len);
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 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
2701 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2702 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
2703 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
2704 i, sequence_one_len);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2705 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2706
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2707 if (VECTORP (sequence_two))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2708 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2709 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
2710 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2711 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
2712 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2713 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
2714 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
2715 i, sequence_two_len);
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 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
2718 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2719 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
2720 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
2721 i, sequence_two_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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2724 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
2725 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2726 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
2727 sequence_one, sequence_two,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2728 c_predicate, predicate,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2729 key);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2730 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2731 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
2732 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2733 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
2734 sequence_one,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2735 sequence_two_storage,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2736 sequence_two_len,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2737 c_predicate, predicate,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2738 key, 0);
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 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
2741 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2742 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
2743 sequence_two,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2744 sequence_one_storage,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2745 sequence_one_len,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2746 c_predicate, predicate,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2747 key, 1);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2748 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2749 else
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2750 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2751 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
2752 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
2753 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
2754 c_predicate, predicate,
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2755 key);
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
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2758 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
2759
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2760 if (do_coerce)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2761 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2762 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
2763 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2764
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2765 UNGCPRO;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2766 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2767
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2768 return result;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2769 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2770
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2771 /* 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
2772 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
2773 Lisp_Object
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2774 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
2775 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
2776 Lisp_Object, Lisp_Object),
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2777 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
2778 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2779 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
2780 Lisp_Object back, tem;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2781 Lisp_Object front = list;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2782 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
2783
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2784 if (XINT (len) < 2)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2785 return list;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2786
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2787 if (NULL == c_predicate)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2788 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2789 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
2790 c_merge_predicate_key;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2791 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2792
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2793 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
2794 tem = Fnthcdr (len, list);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2795 back = Fcdr (tem);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2796 Fsetcdr (tem, Qnil);
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 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
2799 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
2800 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
2801
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2802 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
2803 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2804
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2805 static void
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2806 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
2807 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
2808 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 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
2810 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2811 Elemcount split;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2812
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2813 if (array_len < 2)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2814 return;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2815
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2816 split = array_len / 2;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2817
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2818 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
2819 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
2820 key_func);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2821 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
2822 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
2823 }
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 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
2826 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
2827 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
2828
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2829 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
2830 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
2831
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2832 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
2833 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
2834
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2835 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
2836 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
2837 same guarantees.
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2838
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2839 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
2840 */
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2841 (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
2842 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2843 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
2844 Lisp_Object *sequence_carray;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2845 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
2846 Lisp_Object);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2847 Elemcount sequence_len, i;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2848
5277
d804e621add0 Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5275
diff changeset
2849 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
2850
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2851 CHECK_SEQUENCE (sequence);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2852
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2853 CHECK_KEY_ARGUMENT (key);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2854
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2855 c_predicate = EQ (key, Qidentity) ?
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
2856 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
2857
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2858 if (LISTP (sequence))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2859 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2860 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
2861 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2862 else if (VECTORP (sequence))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2863 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2864 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
2865 c_predicate, predicate, key);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2866 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2867 else if (STRINGP (sequence))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2868 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2869 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
2870
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2871 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
2872
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2873 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
2874
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2875 /* 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
2876 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
2877
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2878 strdata = XSTRING_DATA (sequence);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2879
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2880 CHECK_LISP_WRITEABLE (sequence);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2881 for (i = 0; i < sequence_len; ++i)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2882 {
5184
039d9a7f2e6d Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
2883 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
2884 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2885
5184
039d9a7f2e6d Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
2886 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
2887 bump_string_modiff (sequence);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2888 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
2889 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2890 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
2891 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2892 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
2893 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
2894
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2895 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
2896
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2897 /* 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
2898 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
2899
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2900 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
2901 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2902 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
2903 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2904 }
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 return sequence;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
2907 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 /* property-list functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 /* For properties of text, we need to do order-insensitive comparison of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 plists. That is, we need to compare two plists such that they are the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 same if they have the same set of keys, and equivalent values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 So (a 1 b 2) would be equal to (b 2 a 1).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 LAXP means use `equal' for comparisons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 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
2923 int laxp, int depth, int foldcase)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 434
diff changeset
2925 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 int la, lb, m, i, fill;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 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
2928 Boolbyte *flags;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 if (NILP (a) && NILP (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 Fcheck_valid_plist (a);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 Fcheck_valid_plist (b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 la = XINT (Flength (a));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 lb = XINT (Flength (b));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 m = (la > lb ? la : lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 fill = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 keys = alloca_array (Lisp_Object, m);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 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
2943 flags = alloca_array (Boolbyte, m);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 /* First extract the pairs from A. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 Lisp_Object k = XCAR (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 Lisp_Object v = XCAR (XCDR (rest));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 /* Maybe be Ebolified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 if (nil_means_not_present && NILP (v)) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 keys [fill] = k;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 vals [fill] = v;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 flags[fill] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 fill++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 /* Now iterate over B, and stop if we find something that's not in A,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 or that doesn't match. As we match, mark them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 Lisp_Object k = XCAR (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 Lisp_Object v = XCAR (XCDR (rest));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 /* Maybe be Ebolified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 if (nil_means_not_present && NILP (v)) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 for (i = 0; i < fill; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 {
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
2967 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
2968 internal_equal_0 (k, keys [i], depth, foldcase))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 {
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2970 if (eqp
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2971 /* We narrowly escaped being Ebolified here. */
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2972 ? !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
2973 : !internal_equal_0 (v, vals [i], depth, foldcase))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 /* a property in B has a different value than in A */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 goto MISMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 flags [i] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 if (i == fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 /* there are some properties in B that are not in A */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 goto MISMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 /* Now check to see that all the properties in A were also in B */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 for (i = 0; i < fill; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 if (flags [i] == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 goto MISMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 /* Ok. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 MISMATCH:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 Return non-nil if property lists A and B are `eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 A property list is an alternating list of keywords and values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 This function does order-insensitive comparisons of the property lists:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 Comparison between values is done using `eq'. See also `plists-equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 a nil value is ignored. This feature is a virus that has infected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 old Lisp implementations, but should not be used except for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 (a, b, nil_means_not_present))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 {
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3009 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1, 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 ? Qnil : Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 Return non-nil if property lists A and B are `equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 A property list is an alternating list of keywords and values. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 function does order-insensitive comparisons of the property lists: For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 Comparison between values is done using `equal'. See also `plists-eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 a nil value is ignored. This feature is a virus that has infected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 old Lisp implementations, but should not be used except for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 (a, b, nil_means_not_present))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 {
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3026 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1, 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 ? Qnil : Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 Return non-nil if lax property lists A and B are `eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 A property list is an alternating list of keywords and values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 This function does order-insensitive comparisons of the property lists:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 Comparison between values is done using `eq'. See also `plists-equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 A lax property list is like a regular one except that comparisons between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 keywords is done using `equal' instead of `eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 a nil value is ignored. This feature is a virus that has infected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 old Lisp implementations, but should not be used except for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (a, b, nil_means_not_present))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 {
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3046 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1, 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 ? Qnil : Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 Return non-nil if lax property lists A and B are `equal'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 A property list is an alternating list of keywords and values. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 function does order-insensitive comparisons of the property lists: For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 Comparison between values is done using `equal'. See also `plists-eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 A lax property list is like a regular one except that comparisons between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 keywords is done using `equal' instead of `eq'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 a nil value is ignored. This feature is a virus that has infected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 old Lisp implementations, but should not be used except for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 (a, b, nil_means_not_present))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 {
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3065 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1, 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 ? Qnil : Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 /* Return the value associated with key PROPERTY in property list PLIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 Return nil if key not found. This function is used for internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 property lists that cannot be directly manipulated by the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 internal_plist_get (Lisp_Object plist, Lisp_Object property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 Lisp_Object tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 if (EQ (XCAR (tail), property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 return XCAR (XCDR (tail));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 return Qunbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 /* Set PLIST's value for PROPERTY to VALUE. Analogous to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 internal_plist_get(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 internal_plist_put (Lisp_Object *plist, Lisp_Object property,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 Lisp_Object tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 if (EQ (XCAR (tail), property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 XCAR (XCDR (tail)) = value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 *plist = Fcons (property, Fcons (value, *plist));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 internal_remprop (Lisp_Object *plist, Lisp_Object property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 Lisp_Object tail, prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 for (tail = *plist, prev = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 !NILP (tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 tail = XCDR (XCDR (tail)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 if (EQ (XCAR (tail), property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 if (NILP (prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 *plist = XCDR (XCDR (tail));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 XCDR (XCDR (prev)) = XCDR (XCDR (tail));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 prev = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 /* Called on a malformed property list. BADPLACE should be some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 place where truncating will form a good list -- i.e. we shouldn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 result in a list with an odd length. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 static Lisp_Object
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 575
diff changeset
3138 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 if (ERRB_EQ (errb, ERROR_ME))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 if (ERRB_EQ (errb, ERROR_ME_WARN))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 warn_when_safe_lispobj
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 (Qlist, Qwarning,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
3148 list2 (build_msg_string
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 ("Malformed property list -- list has been truncated"),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 *plist));
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3151 /* #### WARNING: This is more dangerous than it seems; perhaps
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3152 not a good idea. It also violates the principle of least
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3153 surprise -- passing in ERROR_ME_WARN causes truncation, but
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3154 ERROR_ME and ERROR_ME_NOT don't. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 *badplace = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 return Qunbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 /* Called on a circular property list. BADPLACE should be some place
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 where truncating will result in an even-length list, as above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 If doesn't particularly matter where we truncate -- anywhere we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 truncate along the entire list will break the circularity, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 it will create a terminus and the list currently doesn't have one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 static Lisp_Object
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 575
diff changeset
3169 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 if (ERRB_EQ (errb, ERROR_ME))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 return Fsignal (Qcircular_property_list, list1 (*plist));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 if (ERRB_EQ (errb, ERROR_ME_WARN))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 warn_when_safe_lispobj
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 (Qlist, Qwarning,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
3179 list2 (build_msg_string
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 ("Circular property list -- list has been truncated"),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 *plist));
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3182 /* #### WARNING: This is more dangerous than it seems; perhaps
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3183 not a good idea. It also violates the principle of least
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3184 surprise -- passing in ERROR_ME_WARN causes truncation, but
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 780
diff changeset
3185 ERROR_ME and ERROR_ME_NOT don't. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 *badplace = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 return Qunbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 /* Advance the tortoise pointer by two (one iteration of a property-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 loop) and the hare pointer by four and verify that no malformations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 or circularities exist. If so, return zero and store a value into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 RETVAL that should be returned by the calling function. Otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 return 1. See external_plist_get().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 advance_plist_pointers (Lisp_Object *plist,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 Lisp_Object **tortoise, Lisp_Object **hare,
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 575
diff changeset
3202 Error_Behavior errb, Lisp_Object *retval)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 Lisp_Object *tortsave = *tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 /* Note that our "fixing" may be more brutal than necessary,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 but it's the user's own problem, not ours, if they went in and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 manually fucked up a plist. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 for (i = 0; i < 2; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 /* This is a standard iteration of a defensive-loop-checking
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 loop. We just do it twice because we want to advance past
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 both the property and its value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 If the pointer indirection is confusing you, remember that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 one level of indirection on the hare and tortoise pointers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 is only due to pass-by-reference for this function. The other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 level is so that the plist can be fixed in place. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 /* When we reach the end of a well-formed plist, **HARE is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 nil. In that case, we don't do anything at all except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 advance TORTOISE by one. Otherwise, we advance HARE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 by two (making sure it's OK to do so), then advance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 TORTOISE by one (it will always be OK to do so because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 the HARE is always ahead of the TORTOISE and will have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 already verified the path), then make sure TORTOISE and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 HARE don't contain the same non-nil object -- if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 TORTOISE and the HARE ever meet, then obviously we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 in a circularity, and if we're in a circularity, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 the TORTOISE and the HARE can't cross paths without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 meeting, since the HARE only gains one step over the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 TORTOISE per iteration. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 if (!NILP (**hare))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 Lisp_Object *haresave = *hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 if (!CONSP (**hare))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 *retval = bad_bad_bunny (plist, haresave, errb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 *hare = &XCDR (**hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 /* In a non-plist, we'd check here for a nil value for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 **HARE, which is OK (it just means the list has an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 odd number of elements). In a plist, it's not OK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 for the list to have an odd number of elements. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 if (!CONSP (**hare))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 *retval = bad_bad_bunny (plist, haresave, errb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 *hare = &XCDR (**hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 *tortoise = &XCDR (**tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 if (!NILP (**hare) && EQ (**tortoise, **hare))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 *retval = bad_bad_turtle (plist, tortsave, errb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 /* Return the value of PROPERTY from PLIST, or Qunbound if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 property is not on the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 PLIST is a Lisp-accessible property list, meaning that it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 has to be checked for malformations and circularities.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 function will never signal an error; and if ERRB is ERROR_ME_WARN,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 on finding a malformation or a circularity, it issues a warning and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 attempts to silently fix the problem.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 A pointer to PLIST is passed in so that PLIST can be successfully
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 "fixed" even if the error is at the beginning of the plist. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 external_plist_get (Lisp_Object *plist, Lisp_Object property,
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 575
diff changeset
3284 int laxp, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 Lisp_Object *tortoise = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 Lisp_Object *hare = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 while (!NILP (*tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 Lisp_Object *tortsave = tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 Lisp_Object retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 /* We do the standard tortoise/hare march. We isolate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 grungy stuff to do this in advance_plist_pointers(), though.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 To us, all this function does is advance the tortoise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 pointer by two and the hare pointer by four and make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 everything's OK. We first advance the pointers and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 check if a property matched; this ensures that our
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 check for a matching property is safe. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 return retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 if (!laxp ? EQ (XCAR (*tortsave), property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 : internal_equal (XCAR (*tortsave), property, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 return XCAR (XCDR (*tortsave));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 return Qunbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 /* Set PLIST's value for PROPERTY to VALUE, given a possibly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 malformed or circular plist. Analogous to external_plist_get(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 external_plist_put (Lisp_Object *plist, Lisp_Object property,
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 575
diff changeset
3318 Lisp_Object value, int laxp, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 Lisp_Object *tortoise = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 Lisp_Object *hare = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 while (!NILP (*tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 Lisp_Object *tortsave = tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 Lisp_Object retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 /* See above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 if (!laxp ? EQ (XCAR (*tortsave), property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 : internal_equal (XCAR (*tortsave), property, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 XCAR (XCDR (*tortsave)) = value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 *plist = Fcons (property, Fcons (value, *plist));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 external_remprop (Lisp_Object *plist, Lisp_Object property,
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 575
diff changeset
3345 int laxp, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 Lisp_Object *tortoise = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 Lisp_Object *hare = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 while (!NILP (*tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 Lisp_Object *tortsave = tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 Lisp_Object retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 /* See above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 if (!laxp ? EQ (XCAR (*tortsave), property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 : internal_equal (XCAR (*tortsave), property, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 /* Now you see why it's so convenient to have that level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363 of indirection. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 *tortsave = XCDR (XCDR (*tortsave));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 Extract a value from a property list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 PLIST is a property list, which is a list of the form
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3375 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3376 PROPERTY is usually a symbol.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3377 This function returns the value corresponding to the PROPERTY,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3378 or DEFAULT if PROPERTY is not one of the properties on the list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3380 (plist, property, default_))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3382 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3383 return UNBOUNDP (value) ? default_ : value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3387 Change value in PLIST of PROPERTY to VALUE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3388 PLIST is a property list, which is a list of the form
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3389 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3390 PROPERTY is usually a symbol and VALUE is any object.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3391 If PROPERTY is already a property on the list, its value is set to VALUE,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3392 otherwise the new PROPERTY VALUE pair is added.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3393 The new plist is returned; use `(setq x (plist-put x property value))'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3394 to be sure to use the new value. PLIST is modified by side effect.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3396 (plist, property, value))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3398 external_plist_put (&plist, property, value, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 return plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3403 Remove from PLIST the property PROPERTY and its value.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3404 PLIST is a property list, which is a list of the form
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3405 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3406 PROPERTY is usually a symbol.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3407 The new plist is returned; use `(setq x (plist-remprop x property))'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3408 to be sure to use the new value. PLIST is modified by side effect.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3410 (plist, property))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3412 external_remprop (&plist, property, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 return plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3417 Return t if PROPERTY has a value specified in PLIST.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3419 (plist, property))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3421 Lisp_Object value = Fplist_get (plist, property, Qunbound);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3422 return UNBOUNDP (value) ? Qnil : Qt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 Given a plist, signal an error if there is anything wrong with it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 This means that it's a malformed or circular plist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 (plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 Lisp_Object *tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 Lisp_Object *hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 start_over:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 tortoise = &plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 hare = &plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 while (!NILP (*tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 Lisp_Object retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 /* See above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 &retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 goto start_over;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 Given a plist, return non-nil if its format is correct.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 If it returns nil, `check-valid-plist' will signal an error when given
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3453 the plist; that means it's a malformed or circular plist.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 (plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 Lisp_Object *tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 Lisp_Object *hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 tortoise = &plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 hare = &plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 while (!NILP (*tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 Lisp_Object retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 /* See above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 &retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 Destructively remove any duplicate entries from a plist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 In such cases, the first entry applies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 a nil value is removed. This feature is a virus that has infected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 old Lisp implementations, but should not be used except for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 return value may not be EQ to the passed-in value, so make sure to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 `setq' the value back into where it came from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 (plist, nil_means_not_present))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 Lisp_Object head = plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 Fcheck_valid_plist (plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 while (!NILP (plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 Lisp_Object prop = Fcar (plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 Lisp_Object next = Fcdr (plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 CHECK_CONS (next); /* just make doubly sure we catch any errors */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 if (EQ (head, plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 head = Fcdr (next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 plist = Fcdr (next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 /* external_remprop returns 1 if it removed any property.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 We have to loop till it didn't remove anything, in case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 the property occurs many times. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 DO_NOTHING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 plist = Fcdr (next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 return head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 Extract a value from a lax property list.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3520 LAX-PLIST is a lax property list, which is a list of the form
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3521 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3522 properties is done using `equal' instead of `eq'.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3523 PROPERTY is usually a symbol.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3524 This function returns the value corresponding to PROPERTY,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3525 or DEFAULT if PROPERTY is not one of the properties on the list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3527 (lax_plist, property, default_))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3529 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3530 return UNBOUNDP (value) ? default_ : value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3534 Change value in LAX-PLIST of PROPERTY to VALUE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3535 LAX-PLIST is a lax property list, which is a list of the form
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3536 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3537 properties is done using `equal' instead of `eq'.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3538 PROPERTY is usually a symbol and VALUE is any object.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3539 If PROPERTY is already a property on the list, its value is set to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3540 VALUE, otherwise the new PROPERTY VALUE pair is added.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3541 The new plist is returned; use `(setq x (lax-plist-put x property value))'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3542 to be sure to use the new value. LAX-PLIST is modified by side effect.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3544 (lax_plist, property, value))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3546 external_plist_put (&lax_plist, property, value, 1, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 return lax_plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3551 Remove from LAX-PLIST the property PROPERTY and its value.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3552 LAX-PLIST is a lax property list, which is a list of the form
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3553 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3554 properties is done using `equal' instead of `eq'.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3555 PROPERTY is usually a symbol.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3556 The new plist is returned; use `(setq x (lax-plist-remprop x property))'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3557 to be sure to use the new value. LAX-PLIST is modified by side effect.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3559 (lax_plist, property))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3561 external_remprop (&lax_plist, property, 1, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 return lax_plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3566 Return t if PROPERTY has a value specified in LAX-PLIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3567 LAX-PLIST is a lax property list, which is a list of the form
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3568 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3569 properties is done using `equal' instead of `eq'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3571 (lax_plist, property))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3573 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 Destructively remove any duplicate entries from a lax plist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 In such cases, the first entry applies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 a nil value is removed. This feature is a virus that has infected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 old Lisp implementations, but should not be used except for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 return value may not be EQ to the passed-in value, so make sure to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 `setq' the value back into where it came from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 (lax_plist, nil_means_not_present))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 Lisp_Object head = lax_plist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 Fcheck_valid_plist (lax_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 while (!NILP (lax_plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 Lisp_Object prop = Fcar (lax_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 Lisp_Object next = Fcdr (lax_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 CHECK_CONS (next); /* just make doubly sure we catch any errors */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 if (EQ (head, lax_plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 head = Fcdr (next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 lax_plist = Fcdr (next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 /* external_remprop returns 1 if it removed any property.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 We have to loop till it didn't remove anything, in case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 the property occurs many times. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 DO_NOTHING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 lax_plist = Fcdr (next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 return head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 /* In C because the frame props stuff uses it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 Convert association list ALIST into the equivalent property-list form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 The plist is returned. This converts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 \((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 \(a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 The original alist is destroyed in the process of constructing the plist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 See also `alist-to-plist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 (alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 Lisp_Object head = alist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 while (!NILP (alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 /* remember the alist element. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 Lisp_Object el = Fcar (alist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 Fsetcar (alist, Fcar (el));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 Fsetcar (el, Fcdr (el));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 Fsetcdr (el, Fcdr (alist));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 Fsetcdr (alist, el);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 alist = Fcdr (Fcdr (alist));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 return head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 DEFUN ("get", Fget, 2, 3, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3653 Return the value of OBJECT's PROPERTY property.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3654 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 If there is no such property, return optional third arg DEFAULT
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3656 \(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
3657 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
3658 `object-setplist'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3660 (object, property, default_))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 /* Various places in emacs call Fget() and expect it not to quit,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 so don't quit. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3664 Lisp_Object val;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3665
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3666 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3667 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3669 invalid_operation ("Object type has no properties", object);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3670
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3671 return UNBOUNDP (val) ? default_ : val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 DEFUN ("put", Fput, 3, 3, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3675 Set OBJECT's PROPERTY to VALUE.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3676 It can be subsequently retrieved with `(get OBJECT PROPERTY)'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3677 OBJECT can be a symbol, face, extent, or string.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 For a string, no properties currently have predefined meanings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 For the predefined properties for extents, see `set-extent-property'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 For the predefined properties for faces, see `set-face-property'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 See also `get', `remprop', and `object-plist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3683 (object, property, value))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 {
1920
c66036f59678 [xemacs-hg @ 2004-02-20 07:29:16 by stephent]
stephent
parents: 1849
diff changeset
3685 /* This function cannot GC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 CHECK_LISP_WRITEABLE (object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3688 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3690 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3691 (object, property, value))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3692 invalid_change ("Can't set property on object", property);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3695 invalid_change ("Object type has no settable properties", object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 DEFUN ("remprop", Fremprop, 2, 2, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3701 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
3702 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
3703 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
3704 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
3705 and `object-setplist'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3707 (object, property))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3709 int ret = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3710
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 CHECK_LISP_WRITEABLE (object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3713 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3715 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3716 if (ret == -1)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3717 invalid_change ("Can't remove property from object", property);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3720 invalid_change ("Object type has no removable properties", object);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3721
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3722 return ret ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3726 Return a property list of OBJECT's properties.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3727 For a symbol, this is equivalent to `symbol-plist'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3728 OBJECT can be a symbol, string, extent, face, or glyph.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3729 Do not modify the returned property list directly;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3730 this may or may not have the desired effects. Use `put' instead.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3734 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3735 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3737 invalid_operation ("Object type has no properties", object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741
5255
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3742 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
3743 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
3744 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
3745
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3746 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
3747 not allow their modification with `object-setplist'.
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3748 */
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3749 (object, newplist))
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3750 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3751 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
3752 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3753 return XRECORD_LHEADER_IMPLEMENTATION (object)->setplist (object,
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3754 newplist);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3755 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3756
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3757 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
3758 return Qnil;
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3759 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3760
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
3761
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3763 static Lisp_Object
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3764 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3765 Lisp_Object depth)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3766 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3767 return make_int (internal_equal (obj1, obj2, XINT (depth)));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3768 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3769
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3770 int
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3771 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
3772 const Ascbyte *warning_string,
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3773 int flags,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3774 struct call_trapping_problems_result *p,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3775 int retval,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3776 Lisp_Object obj1, Lisp_Object obj2,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3777 int depth)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3778 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3779 Lisp_Object glorp =
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3780 va_call_trapping_problems (warning_class, warning_string,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3781 flags, p,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3782 (lisp_fn_t) tweaked_internal_equal,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3783 3, obj1, obj2, make_int (depth));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3784 if (UNBOUNDP (glorp))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3785 return retval;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3786 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3787 return XINT (glorp);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3788 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3789
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 if (depth > 200)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3794 stack_overflow ("Stack overflow in equal", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 /* Note that (equal 20 20.0) should be nil */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 if (XTYPE (obj1) != XTYPE (obj2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 if (LRECORDP (obj1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3803 const struct lrecord_implementation
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 return (imp1 == imp2) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 /* 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
3809 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 0));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3815 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
3816 {
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3817 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
3818 ARRAY_STRING,
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3819 ARRAY_VECTOR,
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3820 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
3821 };
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3822
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3823 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
3824 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
3825 {
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3826 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
3827 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
3828 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
3829 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
3830 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
3831 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
3832 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
3833 }
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3834
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3835 int
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3836 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth)
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3837 {
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3838 if (depth > 200)
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3839 stack_overflow ("Stack overflow in equalp", Qunbound);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3840 QUIT;
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3841
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3842 /* 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
3843 of two equal fixnums or the same object seen twice. */
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3844 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2))
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3845 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
3846
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3847 /* 2. If both numbers, compare with `='. */
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
3848 if (NUMBERP (obj1) && NUMBERP (obj2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
3849 {
4910
6bc1f3f6cf0d Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4906
diff changeset
3850 return (0 == bytecode_arithcompare (obj1, obj2));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1920
diff changeset
3851 }
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3852
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3853 /* 3. If characters, compare case-insensitively. */
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3854 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
3855 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
3856
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3857 /* 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
3858 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
3859 {
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3860 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
3861 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
3862 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
3863 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
3864 {
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3865 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
3866 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
3867 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
3868 /* 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
3869 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
3870 return 0;
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3871 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
3872 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
3873 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
3874 return 0;
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3875 return 1;
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3876 }
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3877 }
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3878 /* 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
3879 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
3880 their contents, the equal() method will call internal_equal_0(). */
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3881 if (XTYPE (obj1) != XTYPE (obj2))
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3882 return 0;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3883 if (LRECORDP (obj1))
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3884 {
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3885 const struct lrecord_implementation
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3886 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1),
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3887 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2);
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3888
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3889 return (imp1 == imp2) &&
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3890 /* 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
3891 (imp1->equal && (imp1->equal) (obj1, obj2, depth, 1));
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3892 }
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3893
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3894 return 0;
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3895 }
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
3896
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3897 int
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3898 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
3899 {
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3900 if (foldcase)
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3901 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
3902 else
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3903 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
3904 }
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3905
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 /* Note that we may be calling sub-objects that will use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 internal_equal() (instead of internal_old_equal()). Oh well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 We will get an Ebola note if there's any possibility of confusion,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 but that seems unlikely. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 if (depth > 200)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
3915 stack_overflow ("Stack overflow in equal", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3916 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917 if (HACKEQ_UNSAFE (obj1, obj2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919 /* Note that (equal 20 20.0) should be nil */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920 if (XTYPE (obj1) != XTYPE (obj2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 return internal_equal (obj1, obj2, depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 DEFUN ("equal", Fequal, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 Return t if two Lisp objects have similar structure and contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 They must have the same data type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 Conses are compared by comparing the cars and the cdrs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 Vectors and strings are compared element by element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 Numbers are compared by value. Symbols must match exactly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3933 (object1, object2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3935 return internal_equal (object1, object2, 0) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3938 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
3939 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
3940
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3941 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
3942 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
3943 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
3944
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3945 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
3946 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
3947 `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
3948
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3949 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
3950 `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
3951 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
3952 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
3953 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
3954 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
3955 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
3956 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
3957
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3958 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
3959 (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
3960 `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
3961 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
3962 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
3963 */
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3964 (object1, object2))
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3965 {
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3966 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
3967 }
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
3968
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 Return t if two Lisp objects have similar structure and contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 They must have the same data type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 \(Note, however, that an exception is made for characters and integers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 this is known as the "char-int confoundance disease." See `eq' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 `old-eq'.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 This function is provided only for byte-code compatibility with v19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 Do not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3978 (object1, object2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3980 return internal_old_equal (object1, object2, 0) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
3984 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
3985 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
3986 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
3987 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
3988 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
3989 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
3990
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
3991 /* 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
3992 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
3993 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
3994 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
3995 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
3996
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
3997 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
3998 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
3999 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
4000 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
4001 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
4002 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
4003 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4004 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
4005 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4006
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4007 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
4008 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
4009 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
4010
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4011 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
4012 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
4013 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
4014 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
4015
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4016 arguments: (SEQUENCE ITEM &key (START 0) (END (length SEQUENCE)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 */
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4018 (int nargs, Lisp_Object *args))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4020 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
4021 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
4022 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
4023
5277
d804e621add0 Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5275
diff changeset
4024 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
4025
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4026 CHECK_NATNUM (start);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4027 starting = XINT (start);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4028
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4029 if (!NILP (end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4031 CHECK_NATNUM (end);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4032 ending = XINT (end);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4033 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4034
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4035 retry:
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4036 if (STRINGP (sequence))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4037 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 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
4039 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
4040
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4041 fill_string_range (sequence, item, start, end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 }
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4043 else if (VECTORP (sequence))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4045 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
4046
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4047 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
4048 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
4049
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4050 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
4051 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
4052
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4053 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
4054 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4055 p[ii] = item;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4056 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057 }
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4058 else if (BIT_VECTORP (sequence))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4060 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 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
4062
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 CHECK_BIT (item);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4064 bit = XINT (item);
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4065 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
4066 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
4067
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4068 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
4069 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
4070
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4071 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
4072 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4073 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
4074 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4075 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4076 else if (LISTP (sequence))
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4077 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4078 Elemcount counting = 0;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4079
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4080 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
4081 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4082 if (counting >= starting)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4083 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4084 if (counting < ending)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4085 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4086 XSETCAR (tail, item);
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 else if (counting == ending)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4089 {
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4090 break;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4091 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4092 }
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4093 ++counting;
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4094 }
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4095
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
4096 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
4097 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
4098 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
4099 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 {
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4103 sequence = wrong_type_argument (Qsequencep, sequence);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 }
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
4106 return sequence;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 nconc2 (Lisp_Object arg1, Lisp_Object arg2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 Lisp_Object args[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 args[0] = arg1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115 args[1] = arg2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 GCPRO1 (args[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 gcpro1.nvars = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 RETURN_UNGCPRO (bytecode_nconc2 (args));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124 bytecode_nconc2 (Lisp_Object *args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 if (CONSP (args[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 /* (setcdr (last args[0]) args[1]) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 Lisp_Object tortoise, hare;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
4132 Elemcount count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 for (hare = tortoise = args[0], count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 CONSP (XCDR (hare));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 hare = XCDR (hare), count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4140 if (count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 if (EQ (hare, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 signal_circular_list_error (args[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145 XCDR (hare) = args[1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146 return args[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 else if (NILP (args[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 return args[1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154 args[0] = wrong_type_argument (args[0], Qlistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 DEFUN ("nconc", Fnconc, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 Concatenate any number of lists by altering them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 Only the last argument is not altered, and need not be a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 Also see: `append'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 If the first argument is nil, there is no way to modify it by side
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 effect; therefore, write `(setq foo (nconc foo list))' to be sure of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 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
4166
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3842
diff changeset
4167 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 int argnum = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 /* The modus operandi in Emacs is "caller gc-protects args".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 However, nconc (particularly nconc2 ()) is called many times
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 in Emacs on freshly created stuff (e.g. you see the idiom
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4177 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178 callers out by protecting the args ourselves to save them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179 a lot of temporary-variable grief. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 GCPRO1 (args[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182 gcpro1.nvars = nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 while (argnum < nargs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186 Lisp_Object val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 val = args[argnum];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189 if (CONSP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 /* `val' is the first cons, which will be our return value. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4192 /* `last_cons' will be the cons cell to mutate. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4193 Lisp_Object last_cons = val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194 Lisp_Object tortoise = val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 for (argnum++; argnum < nargs; argnum++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 Lisp_Object next = args[argnum];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 retry_next:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 if (CONSP (next) || argnum == nargs -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 /* (setcdr (last val) next) */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
4203 Elemcount count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4205 for (count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206 CONSP (XCDR (last_cons));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207 last_cons = XCDR (last_cons), count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4209 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211 if (count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213 if (EQ (last_cons, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 signal_circular_list_error (args[argnum-1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 XCDR (last_cons) = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218 else if (NILP (next))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4219 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4220 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 next = wrong_type_argument (Qlistp, next);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 goto retry_next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228 RETURN_UNGCPRO (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 else if (NILP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 argnum++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 else if (argnum == nargs - 1) /* last arg? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 RETURN_UNGCPRO (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 args[argnum] = wrong_type_argument (Qlistp, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4243
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4244 /* 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
4245 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
4246 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
4247 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
4248 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
4249 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
4250
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4251 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
4252 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
4253 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
4254 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
4255 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
4256 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
4257 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4258 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
4259 Qnil);
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4260 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4261
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
4262 /* 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
4263
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4264 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
4265 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
4266 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
4267 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
4268 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
4269 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
4270
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4271 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
4272 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
4273 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
4274 mapcarX.
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4275
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4276 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
4277 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
4278 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
4279 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
4280 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
4281 traversal operation.
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4282
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4283 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
4284 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
4285
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4286 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
4287 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
4288 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
4289 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
4290 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
4291 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
4292 otherwise it will be left alone. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4294 static void
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4295 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
4296 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
4297 Lisp_Object caller)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4298 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4299 Lisp_Object called, *args;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4300 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
4301 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
4302 int i, j;
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4303
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4304 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
4305
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4306 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
4307 args[0] = function;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4308 for (i = 1; i <= nsequences; ++i)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4309 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4310 args[i] = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4311 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4312
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4313 if (vals != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4314 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4315 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
4316 gcpro1.nvars = nsequences + 1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4317 gcpro2.nvars = 0;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4318 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4319 else
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4320 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4321 GCPRO1 (args[0]);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4322 gcpro1.nvars = nsequences + 1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4323 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4324
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4325 /* 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
4326 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
4327 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
4328 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
4329 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
4330 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4331 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
4332 Lisp_Object *val = vals;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4333 for (i = 0; i < call_count; ++i)
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
4334 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4335 *val++ = XCAR (lst);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4336 lst = XCDR (lst);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337 }
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4338 gcpro2.nvars = call_count;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4339
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4340 for (i = 0; i < call_count; ++i)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4341 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4342 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
4343 vals[i] = IGNORE_MULTIPLE_VALUES (Ffuncall (nsequences + 1, args));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4344 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4346 else
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4347 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4348 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
4349 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
4350 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
4351 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4352 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
4353 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4354
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4355 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
4356 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4357 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
4358
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4359 lisp_vals_type
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4360 = (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
4361
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4362 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
4363 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4364 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
4365 = 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
4366 }
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4367 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4368
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4369 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
4370 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4371 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
4372 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4373 switch (sequence_types[j])
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4374 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4375 case lrecord_type_cons:
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4376 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4377 if (!CONSP (sequences[j]))
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4378 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4379 /* 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
4380 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
4381 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
4382 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
4383 callers. */
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4384 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
4385 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4386 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
4387 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
4388 break;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4389 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4390 case lrecord_type_vector:
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4391 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4392 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
4393 break;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4394 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4395 case lrecord_type_string:
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4396 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4397 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
4398 break;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4399 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4400 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
4401 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4402 args[j + 1]
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4403 = 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
4404 i));
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4405 break;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4406 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4407 default:
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4408 ABORT();
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 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4411 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
4412 if (vals != NULL)
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4413 {
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4414 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
4415 gcpro2.nvars += 1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4416 }
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4417 else if (EQ (Qsome, caller))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4418 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4419 if (!NILP (IGNORE_MULTIPLE_VALUES (called)))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4420 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4421 Lisp_Object *result
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4422 = (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
4423 *result = called;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4424 UNGCPRO;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4425 return;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4426 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4427 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4428 else if (EQ (Qevery, caller))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4429 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4430 if (NILP (IGNORE_MULTIPLE_VALUES (called)))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4431 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4432 Lisp_Object *result
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4433 = (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
4434 *result = Qnil;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4435 UNGCPRO;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4436 return;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4437 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4438 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4439 else
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4440 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4441 called = IGNORE_MULTIPLE_VALUES (called);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4442 switch (lisp_vals_type)
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4443 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4444 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
4445 /* Discard the result of funcall. */
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4446 break;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4447 case lrecord_type_cons:
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4448 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4449 if (!CONSP (lisp_vals))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4450 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4451 /* 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
4452 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
4453 relevant part, error. */
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4454 mapping_interaction_error (caller, lisp_vals);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4455 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4456 XSETCAR (lisp_vals, called);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4457 lisp_vals = XCDR (lisp_vals);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4458 break;
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 case lrecord_type_vector:
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4461 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4462 i < XVECTOR_LENGTH (lisp_vals) ?
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4463 (XVECTOR_DATA (lisp_vals)[i] = called) :
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4464 /* Let #'aset error. */
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4465 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
4466 break;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4467 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4468 case lrecord_type_string:
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4469 {
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4470 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
4471 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
4472 break;
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 case lrecord_type_bit_vector:
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4475 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4476 (BITP (called) &&
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4477 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
4478 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
4479 XINT (called)) :
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4480 (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
4481 break;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4482 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4483 default:
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4484 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4485 ABORT();
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4486 break;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4487 }
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 }
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4490 }
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4491
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4492 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
4493 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
4494 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4495 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
4496 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
4497 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4498 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
4499
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4500 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4501 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4502
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4503 /* 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
4504 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
4505 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
4506 static Elemcount
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4507 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
4508 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4509 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
4510 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
4511 int i;
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4512
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4513 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
4514 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4515 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
4516 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4517 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
4518 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
4519 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4520 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
4521 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4522 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4523 else
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4524 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4525 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
4526 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
4527 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
4528 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4529 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4530
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4531 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
4532 {
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4533 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
4534 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4535
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4536 return len;
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4537 }
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4538
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4539 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
4540 Call FUNCTION on each element of SEQUENCE, and concat results to a string.
751
358bd84dc7ff [xemacs-hg @ 2002-02-13 12:55:38 by stephent]
stephent
parents: 665
diff changeset
4541 Between each pair of results, insert SEPARATOR.
358bd84dc7ff [xemacs-hg @ 2002-02-13 12:55:38 by stephent]
stephent
parents: 665
diff changeset
4542
358bd84dc7ff [xemacs-hg @ 2002-02-13 12:55:38 by stephent]
stephent
parents: 665
diff changeset
4543 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR
358bd84dc7ff [xemacs-hg @ 2002-02-13 12:55:38 by stephent]
stephent
parents: 665
diff changeset
4544 results in spaces between the values returned by FUNCTION. SEQUENCE itself
358bd84dc7ff [xemacs-hg @ 2002-02-13 12:55:38 by stephent]
stephent
parents: 665
diff changeset
4545 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
4546
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4547 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
4548 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
4549 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
4550 `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
4551
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4552 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4553 */
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4554 (int nargs, Lisp_Object *args))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4555 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4556 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
4557 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
4558 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
4559 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
4560 Lisp_Object *args0;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4561 EMACS_INT i, nargs0;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4562
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4563 args[2] = sequence;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4564 args[1] = separator;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4565
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4566 len = shortest_length_among_sequences (nargs - 2, args + 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4567
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
4568 if (len == 0) return build_ascstring ("");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4569
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4570 nargs0 = len + len - 1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4571 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
4572
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4573 /* 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
4574 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
4575 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
4576 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
4577 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4578 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
4579 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4580 args0[i] = XCAR (sequence);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4581 sequence = XCDR (sequence);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4582 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4583 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4584 else
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4585 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4586 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
4587 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4589 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
4590 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
4591
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4592 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
4593 args0[i] = separator;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4594
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4595 return Fconcat (nargs0, args0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4596 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4597
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4598 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
4599 Call FUNCTION on each element of SEQUENCE; return a list of the results.
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
4600 The result is a list of the same length as SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4601 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
4602
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4603 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
4604 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
4605 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
4606 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
4607
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4608 arguments: (FUNCTION SEQUENCE &rest SEQUENCES)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4609 */
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4610 (int nargs, Lisp_Object *args))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4611 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4612 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
4613 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
4614 Lisp_Object *args0;
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 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
4617 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
4618
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4619 return Flist ((int) len, args0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4620 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4621
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4622 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
4623 Call FUNCTION on each element of SEQUENCE; return a vector of the results.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4624 The result is a vector of the same length as SEQUENCE.
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
4625 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
4626
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4627 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
4628 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
4629 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
4630 `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
4631
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4632 arguments: (FUNCTION SEQUENCE &rest SEQUENCES)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4633 */
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4634 (int nargs, Lisp_Object *args))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4635 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4636 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
4637 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
4638 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
4639
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4640 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4641 GCPRO1 (result);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4642 /* 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
4643 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
4644 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
4645 Qmapvector);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4646 RETURN_UNGCPRO (result);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4647 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4648
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4649 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
4650 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
4651
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4652 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
4653 together using `nconc'.
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4654
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4655 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
4656 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
4657 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
4658 `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
4659
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4660 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
4661 */
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4662 (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
4663 {
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4664 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
4665 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
4666
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4667 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
4668
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4669 /* #'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
4670 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
4671 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4672
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4673 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
4674 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
4675
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4676 SEQUENCE may be a list, a vector, a bit vector, or a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677 This function is like `mapcar' but does not accumulate the results,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 which is more efficient if you do not use the results.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4679
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4680 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
4681 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
4682 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
4683 `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
4684
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4685 Return SEQUENCE.
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4686
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4687 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
4688 */
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4689 (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
4690 {
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4691 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
4692 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
4693 struct gcpro gcpro1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4694 /* 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
4695 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
4696 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
4697 GCPRO1 (sequence);
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4698 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
4699 RETURN_UNGCPRO (sequence);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4700 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4701
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4702 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
4703 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
4704
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4705 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
4706 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
4707
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4708 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
4709 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
4710
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4711 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
4712 `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
4713 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
4714
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4715 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4716 */
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4717 (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
4718 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4719 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
4720 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
4721 Lisp_Object result = Qnil;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4722 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
4723 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
4724 struct gcpro gcpro1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4725
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4726 if (!NILP (type))
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4727 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4728 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
4729 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4730
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4731 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
4732
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4733 if (EQ (type, Qnil))
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4734 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4735 return result;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4736 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4737
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4738 if (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
4739 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4740 result = Fvector (len, args0);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4741 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4742 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
4743 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4744 result = Fstring (len, args0);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4745 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4746 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
4747 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4748 result = Flist (len, args0);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4749 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4750 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
4751 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4752 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
4753 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4754 else
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4755 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4756 result = Flist (len, args0);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4757 GCPRO1 (result);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4758 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
4759 UNGCPRO;
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
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4762 return result;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4763 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4764
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4765 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
4766 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
4767
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4768 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
4769
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4770 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
4771 \(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
4772 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
4773 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
4774
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4775 Return RESULT-SEQUENCE.
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 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
4778 */
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4779 (int nargs, Lisp_Object *args))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4780 {
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4781 Elemcount len;
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4782 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
4783 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
4784
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4785 args[0] = function;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4786 args[1] = result_sequence;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4787
5273
799742b751c8 Accept circular lists where that is useful in #'mapcar*, #'map* and friends.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5272
diff changeset
4788 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
4789
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4790 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
4791 Qmap_into);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4792
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4793 return result_sequence;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4794 }
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4795
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4796 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
4797 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
4798
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4799 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
4800
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4801 With optional SEQUENCES, call PREDICATE each time with as many arguments as
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4802 there are SEQUENCES (plus one for the element from SEQUENCE).
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4803
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4804 arguments: (PREDICATE SEQUENCE &rest SEQUENCES)
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4805 */
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4806 (int nargs, Lisp_Object *args))
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4807 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4808 Lisp_Object result = Qnil,
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4809 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
4810 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
4811
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4812 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
4813
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4814 return result;
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4815 }
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4816
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4817 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
4818 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
4819
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4820 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
4821 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
4822
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4823 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
4824
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4825 arguments: (PREDICATE SEQUENCE &rest SEQUENCES)
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4826 */
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4827 (int nargs, Lisp_Object *args))
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4828 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4829 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
4830 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
4831
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4832 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
4833
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4834 return result;
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4835 }
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4836
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4837 /* 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
4838 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
4839 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
4840
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4841 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
4842 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
4843
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4844 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
4845 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
4846
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4847 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
4848 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
4849 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
4850
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4851 static Lisp_Object
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4852 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
4853 Lisp_Object caller)
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4854 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4855 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
4856 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
4857 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
4858 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
4859
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4860 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
4861 args[0] = function;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4862 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
4863 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4864 args[i] = Qnil;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4865 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4866
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4867 tortoises = alloca_array (Lisp_Object, nlists);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4868 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
4869
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4870 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
4871 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4872 nconcing[0] = Qnil;
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4873 nconcing[1] = Qnil;
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4874 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
4875 gcpro1.nvars = 1;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4876 gcpro2.nvars = 2;
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4877 gcpro3.nvars = nlists;
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4878 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4879 else
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4880 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4881 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
4882 gcpro1.nvars = 1;
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4883 gcpro2.nvars = nlists;
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4884 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4885
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4886 while (continuing)
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4887 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4888 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
4889 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4890 if (CONSP (lists[j]))
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4891 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4892 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
4893 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
4894 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4895 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
4896 {
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4897 continuing = 0;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4898 break;
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4899 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4900 else
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4901 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4902 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
4903 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4904 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4905 if (!continuing) break;
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
4906 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
4907
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4908 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
4909 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4910 DO_NOTHING;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4911 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4912 else if (EQ (caller, Qmapcon))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4913 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4914 nconcing[1] = funcalled;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4915 accum = bytecode_nconc2 (nconcing);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4916 if (NILP (result))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4917 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4918 result = accum;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4919 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4920 /* 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
4921 once: */
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4922 nconcing[0] = funcalled;
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4923 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4924 else if (NILP (accum))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4925 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4926 accum = result = Fcons (funcalled, Qnil);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4927 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4928 else
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4929 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4930 /* 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
4931 once we're done: */
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4932 XSETCDR (accum, Fcons (funcalled, Qnil));
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4933 accum = XCDR (accum);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4934 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4935
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4936 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
4937 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4938 if (called_count & 1)
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4939 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4940 for (j = 0; j < nlists; ++j)
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4941 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4942 tortoises[j] = XCDR (tortoises[j]);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4943 if (EQ (lists[j], tortoises[j]))
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 signal_circular_list_error (lists[j]);
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 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4948 }
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4949 else
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 for (j = 0; j < nlists; ++j)
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 if (EQ (lists[j], tortoises[j]))
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4954 {
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4955 signal_circular_list_error (lists[j]);
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 }
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 }
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4960 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4961
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4962 RETURN_UNGCPRO (result);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4963 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4964
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4965 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
4966 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
4967 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
4968 the elements themselves."
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4969
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4970 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
4971 */
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4972 (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
4973 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4974 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
4975 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4976
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4977 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
4978 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
4979
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4980 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
4981 */
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4982 (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
4983 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4984 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
4985 }
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4986
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4987 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
4988 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
4989
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4990 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
4991 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
4992
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4993 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
4994 */
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
4995 (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
4996 {
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
4997 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
4998 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4999
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
5000 /* Extra random functions */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5001
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5002 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
5003 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
5004
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5005 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
5006 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
5007 in SEQUENCE.
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5008
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5009 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
5010 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
5011
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5012 :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
5013 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
5014 :from-end is given).
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5015
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5016 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
5017 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
5018 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
5019
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5020 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
5021 */
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5022 (int nargs, Lisp_Object *args))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5023 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5024 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
5025 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
5026
5277
d804e621add0 Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5275
diff changeset
5027 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
5028 (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
5029 (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
5030
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5031 CHECK_SEQUENCE (sequence);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5032 CHECK_NATNUM (start);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5033
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5034 CHECK_KEY_ARGUMENT (key);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5035
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5036 #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
5037 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
5038 #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
5039 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
5040
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5041 starting = XINT (start);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5042 if (!NILP (end))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5043 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5044 CHECK_NATNUM (end);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5045 ending = XINT (end);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5046 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5047
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5048 if (!(starting <= ending))
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5049 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5050 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
5051 }
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5052
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5053 if (VECTORP (sequence))
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 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
5056
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5057 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
5058
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5059 ending = min (ending, vv->size);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5060
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5061 if (!UNBOUNDP (initial_value))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5062 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5063 accum = initial_value;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5064 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5065 else if (ending - starting)
5227
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 if (NILP (from_end))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5068 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5069 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
5070 starting++;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5071 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5072 else
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 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
5075 ending--;
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 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5078
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5079 if (NILP (from_end))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5080 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5081 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
5082 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5083 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
5084 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5085 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5086 else
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 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
5089 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5090 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
5091 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5092 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5093 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5094 else if (BIT_VECTORP (sequence))
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 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
5097
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5098 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
5099
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5100 ending = min (ending, bv->size);
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 if (!UNBOUNDP (initial_value))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5103 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5104 accum = initial_value;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5105 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5106 else if (ending - starting)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5107 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5108 if (NILP (from_end))
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 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
5111 starting++;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5112 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5113 else
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5114 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5115 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
5116 ending--;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5117 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5118 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5119
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5120 if (NILP (from_end))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5121 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5122 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
5123 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5124 accum = CALL2 (function, accum,
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5125 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
5126 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5127 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5128 else
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5129 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5130 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
5131 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5132 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
5133 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
5134 ii))),
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5135 accum);
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 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5138 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5139 else if (STRINGP (sequence))
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 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
5144 Bytecount cursor_offset = 0;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5145 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
5146 const Ibyte *cursor = startp;
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 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
5149 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5150 INC_IBYTEPTR (cursor);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5151 cursor_offset = cursor - startp;
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
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5154 if (!UNBOUNDP (initial_value))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5155 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5156 accum = initial_value;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5157 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5158 else if (ending - starting)
5227
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 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
5161 starting++;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5162 startp = XSTRING_DATA (sequence);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5163 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
5164
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5165 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
5166 || !valid_ibyteptr_p (cursor))
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5167 {
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5168 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
5169 }
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5170
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5171 INC_IBYTEPTR (cursor);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5172 cursor_offset = cursor - startp;
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
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5175 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
5176 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5177 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
5178 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
5179
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5180 startp = XSTRING_DATA (sequence);
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5181 cursor = startp + cursor_offset;
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5182
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5183 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
5184 || !valid_ibyteptr_p (cursor))
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5185 {
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5186 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
5187 }
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 INC_IBYTEPTR (cursor);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5190 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
5191 ++ii;
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5192 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5193
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5194 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
5195 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5196 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
5197 ABORT ();
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5198 }
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5199 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5200 else
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5201 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5202 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
5203 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
5204 const Ibyte *cursor;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5205
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5206 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
5207
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5208 ending = min (ending, len);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5209 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
5210 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
5211
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5212 if (!UNBOUNDP (initial_value))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5213 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5214 accum = initial_value;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5215 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5216 else if (ending - starting)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5217 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5218 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
5219 ending--;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5220 if (ending > 0)
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5221 {
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5222 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
5223
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5224 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
5225 {
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5226 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
5227 }
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5228
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5229 DEC_IBYTEPTR (cursor);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5230 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
5231 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5232 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5233
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5234 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
5235 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5236 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
5237 make_char (itext_ichar (cursor))),
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5238 accum);
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5239 if (ii > 0)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5240 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5241 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
5242
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5243 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
5244 || !valid_ibyteptr_p (cursor))
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5245 {
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5246 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
5247 }
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5248
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5249 DEC_IBYTEPTR (cursor);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5250 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
5251 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5252 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5253 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5254 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5255 else if (LISTP (sequence))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5256 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5257 if (NILP (from_end))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5258 {
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5259 struct gcpro gcpro1;
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5260 Lisp_Object tailed = Qnil;
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5261
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5262 GCPRO1 (tailed);
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5263
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5264 if (!UNBOUNDP (initial_value))
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 accum = initial_value;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5267 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5268 else if (ending - starting)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5269 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5270 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
5271 {
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5272 /* 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
5273 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
5274 tailed = tail;
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5275 if (ii == starting)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5276 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5277 accum = KEY (key, elt);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5278 starting++;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5279 break;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5280 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5281 ++ii;
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5282 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5283 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5284
5275
5a9aa6c40c9b Avoid statement-before-declaration problems with strict C89 builds, fns.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5273
diff changeset
5285 ii = 0;
5a9aa6c40c9b Avoid statement-before-declaration problems with strict C89 builds, fns.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5273
diff changeset
5286
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5287 if (ending - starting)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5288 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5289 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
5290 {
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5291 /* 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
5292 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
5293 reachable. */
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5294 tailed = tail;
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5295 if (ii >= starting)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5296 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5297 if (ii < ending)
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5298 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5299 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
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 (ii == ending)
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 break;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5304 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5305 }
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5306 ++ii;
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5307 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5308 }
5241
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5309
d579d76f3dcc Be more careful about side-effects from Lisp code, #'reduce
Aidan Kehoe <kehoea@parhasard.net>
parents: 5227
diff changeset
5310 UNGCPRO;
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5311
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5312 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
5313 {
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5314 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
5315 ABORT ();
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5316 }
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5317 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5318 else
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5319 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5320 Boolint need_accum = 0;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5321 Lisp_Object *subsequence = NULL;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5322 Elemcount counting = 0, len = 0;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5323 struct gcpro gcpro1;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5324
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5325 len = XINT (Flength (sequence));
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5326 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
5327 ending = min (ending, len);
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5328
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5329 /* :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
5330 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
5331 if (!UNBOUNDP (initial_value))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5332 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5333 accum = initial_value;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5334 if (ending - starting && starting < ending)
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 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
5337 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5338 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5339 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
5340 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5341 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
5342 need_accum = 1;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5343 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5344
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5345 if (ending - starting && starting < ending)
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5346 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5347 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
5348 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5349 if (counting >= starting)
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 if (counting < ending)
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 subsequence[ii++] = elt;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5354 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5355 else if (counting == ending)
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5356 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5357 break;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5358 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5359 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5360 ++counting;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5361 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5362 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5363
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5364 if (subsequence != NULL)
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 len = ending - starting;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5367 /* 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
5368 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
5369 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
5370 reachable via SEQUENCE. */
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5371 GCPRO1 (subsequence[0]);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5372 gcpro1.nvars = len;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5373 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5374
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5375 if (need_accum)
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 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
5378 --len;
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
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5381 for (ii = len; ii != 0;)
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5382 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5383 --ii;
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5384 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
5385 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5386
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5387 if (subsequence != NULL)
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5388 {
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5389 UNGCPRO;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5390 }
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
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5394 /* 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
5395 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
5396 arguments. */
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5397 if (UNBOUNDP (accum))
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5398 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5399 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
5400 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5401
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5402 return accum;
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5403 }
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
5404
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5405 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5406 Destructively replace the list OLD with NEW.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5407 This is like (copy-sequence NEW) except that it reuses the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5408 conses in OLD as much as possible. If OLD and NEW are the same
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5409 length, no consing will take place.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5410 */
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2720
diff changeset
5411 (old, new_))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5412 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
5413 Lisp_Object oldtail = old, prevoldtail = Qnil;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
5414
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2720
diff changeset
5415 EXTERNAL_LIST_LOOP_2 (elt, new_)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5416 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5417 if (!NILP (oldtail))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5418 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5419 CHECK_CONS (oldtail);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
5420 XCAR (oldtail) = elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5421 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5422 else if (!NILP (prevoldtail))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5423 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
5424 XCDR (prevoldtail) = Fcons (elt, Qnil);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5425 prevoldtail = XCDR (prevoldtail);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5426 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5427 else
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
5428 old = oldtail = Fcons (elt, Qnil);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5429
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5430 if (!NILP (oldtail))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5431 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5432 prevoldtail = oldtail;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5433 oldtail = XCDR (oldtail);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5434 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5435 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5436
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5437 if (!NILP (prevoldtail))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5438 XCDR (prevoldtail) = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5439 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5440 old = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5441
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5442 return old;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5443 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5444
5261
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5445 /* 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
5446 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
5447 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
5448 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
5449 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
5450 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
5451 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5452 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
5453 *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
5454 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
5455 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
5456 Elemcount delta;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5457
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5458 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
5459 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5460 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
5461 ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5462 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5463
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5464 pcursor = p;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5465
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5466 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
5467 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5468 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
5469 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5470 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
5471 ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5472 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5473
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5474 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
5475 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5476 else
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5477 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5478 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
5479 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
5480 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5481 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
5482 ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5483 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5484 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5485
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5486 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
5487 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5488 /* 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
5489 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
5490 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5491
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5492 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
5493 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5494 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
5495
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5496 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
5497 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5498 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
5499 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
5500 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
5501 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5502 else
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5503 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5504 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
5505 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
5506 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5507
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5508 if (delta)
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5509 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5510 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
5511 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
5512 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
5513 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
5514 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5515
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5516 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
5517 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5518 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
5519 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5520 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
5521 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
5522 starting++;
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 else
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 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
5528 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5529 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
5530 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
5531 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5532 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5533
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5534 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
5535 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
5536 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
5537 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5538
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5539 return dest;
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5542 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
5543 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
5544
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5545 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
5546 changed.
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 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
5549 :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
5550 information.
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5551
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5552 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
5553 */
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5554 (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
5555 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5556 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
5557 result = sequence1;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5558 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
5559 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
5560 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
5561 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
5562
5277
d804e621add0 Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5275
diff changeset
5563 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
5564 (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
5565
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5566 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
5567 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
5568
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5569 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
5570
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5571 CHECK_NATNUM (start1);
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5572 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
5573 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
5574 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
5575
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5576 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
5577 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5578 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
5579 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
5580
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5581 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
5582 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5583 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
5584 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5585 }
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 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
5588 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5589 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
5590 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
5591
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5592 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
5593 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5594 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
5595 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5596 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5597
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5598 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
5599 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
5600
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5601 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
5602
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5603 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
5604 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5605 sequence1 = Fnthcdr (start1, sequence1);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5606
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5607 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
5608 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5609 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
5610 /* 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
5611 return result;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5612 }
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 ending1 -= starting1;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5615 starting1 = 0;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5616 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5617
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5618 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
5619 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5620 sequence2 = Fnthcdr (start2, sequence2);
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5621
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5622 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
5623 {
5272
66dbef5f8076 Be better about bounds-checking, #'subseq, #'fill; add same, #'reduce.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5262
diff changeset
5624 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
5625 /* 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
5626 return result;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5627 }
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 ending2 -= starting2;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5630 starting2 = 0;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5631 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5632
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5633 if (overwriting)
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5634 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5635 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
5636 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5637 return result;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5638 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5639
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5640 /* 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
5641
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5642 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
5643 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5644 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
5645 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
5646 = 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
5647 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
5648
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5649 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
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 (counting == ending2)
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5652 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5653 break;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5654 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5655
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5656 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
5657 counting++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5658 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5659
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5660 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
5661 /* 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
5662 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
5663 start2 sequence2). */
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5664 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
5665 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
5666 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
5667
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5668 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
5669 && 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
5670 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5671 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
5672 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
5673 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5674 starting2++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5675 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5676 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5677 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
5678 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5679 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
5680 *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
5681 *staging;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5682 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
5683
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5684 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
5685 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5686 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
5687 ii++;
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5690 pcursor = p;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5691
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5692 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
5693 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5694 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
5695 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5696 ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5697 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5698
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5699 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
5700 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5701 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
5702 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
5703 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5704 else
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5705 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5706 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
5707 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
5708 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
5709 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
5710 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
5711 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
5712 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5713 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5714 else
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5715 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5716 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
5717 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
5718 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
5719 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
5720
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5721 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
5722 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
5723
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5724 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
5725 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5726 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
5727 ii++, starting2++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5728 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5729
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5730 ii = 0;
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 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
5733 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5734 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
5735 ii++, starting1++;
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 }
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 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
5740 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5741 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
5742 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
5743 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
5744
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5745 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
5746
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5747 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
5748 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5749 XSETCAR (sequence1,
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5750 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
5751 : Fcar (sequence2));
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5752 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
5753 : Fcdr (sequence1);
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5754 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
5755 : Fcdr (sequence2);
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 shortest_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 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
5760 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5761 if (counting & 1)
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 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
5764 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
5765 }
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 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
5768 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5769 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
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 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
5773 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5774 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
5775 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5776 }
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5779 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
5780 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5781 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
5782 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
5783 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5784 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
5785 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5786 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
5787 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
5788 }
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 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
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 (STRINGP (sequence2))
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 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
5795 *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
5796 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
5797 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
5798
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5799 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
5800 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5801 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
5802 char_count++;
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 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
5806 && 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
5807 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5808 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
5809 CONSP (sequence1) ?
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5810 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
5811 : 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
5812 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
5813 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5814 starting2++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5815 char_count++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5816 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
5817 }
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 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
5820 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5821 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
5822 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
5823 }
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 (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
5826 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5827 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
5828 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
5829 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5830 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5831 else
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5832 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5833 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
5834 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
5835
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5836 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
5837 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
5838 && 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
5839 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5840 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
5841 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
5842 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
5843 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5844 starting2++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5845 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5846
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5847 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
5848 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5849 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
5850 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
5851 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5852 }
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 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
5855 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5856 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
5857 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5858 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
5859 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
5860 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
5861
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5862 check_sequence_range (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
5863 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
5864 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
5865 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
5866
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5867 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
5868 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5869 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
5870 : Fcar (sequence2);
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5871
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5872 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
5873 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
5874 ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5875 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
5876 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5877
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5878 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
5879 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5880 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
5881 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
5882 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5883
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5884 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
5885 staging, cursor);
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
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 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
5890
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5891 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
5892 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
5893
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5894 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
5895 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5896 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
5897 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
5898 : Fcar (sequence2));
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5899 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
5900 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5901 starting2++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5902 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5903
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5904 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
5905 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5906 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
5907 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
5908 }
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 else
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 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
5914 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5915 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
5916 *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
5917 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
5918
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5919 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
5920 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5921 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
5922 ii++;
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5925 p2cursor = p2;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5926 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
5927
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5928 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
5929 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5930 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
5931 ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5932 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5933 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5934
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5935 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
5936 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5937 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
5938 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5939
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5940 /* 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
5941 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
5942 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
5943 p2, p2cursor);
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5944 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5945 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
5946 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5947 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
5948 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
5949 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
5950 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
5951
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5952 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
5953 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
5954
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5955 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
5956 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
5957 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
5958 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
5959
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5960 ii = 0;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5961 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
5962 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5963 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
5964
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5965 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
5966 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
5967 starting2++, ii++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5968 }
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 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
5971 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
5972 staging, cursor);
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5973 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5974 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
5975 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5976 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
5977 *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
5978 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
5979
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5980 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
5981 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
5982
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5983 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
5984 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5985 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
5986 ii++;
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5989 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
5990 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5991 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
5992 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
5993 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
5994 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5995 starting2++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5996 ii++;
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
5999 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
6000 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6001 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
6002 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6003 }
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6004 else
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6005 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6006 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
6007 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
6008
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6009 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
6010 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
6011
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6012 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
6013 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
6014
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6015 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
6016 {
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6017 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
6018 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
6019 starting1++;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6020 starting2++;
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 }
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
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6025 return result;
69f687b3ba9d Move #'replace to C, add bounds-checking to it and to #'fill.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5255
diff changeset
6026 }
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6027
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6028 Lisp_Object
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
6029 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6030 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6031 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
6032 build_ascstring (ascii_string)),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6033 Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6034 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6035
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6036 Lisp_Object
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
6037 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6038 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4797
diff changeset
6039 return Fintern (concat2 (build_ascstring (ascii_string),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6040 Fsymbol_name (symbol)),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6041 Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6042 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6043
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6044
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6045 /* #### this function doesn't belong in this file! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6046
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6047 #ifdef HAVE_GETLOADAVG
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6048 #ifdef HAVE_SYS_LOADAVG_H
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6049 #include <sys/loadavg.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6050 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6051 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6052 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6053 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6054
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6055 DEFUN ("load-average", Fload_average, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6056 Return list of 1 minute, 5 minute and 15 minute load averages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6057 Each of the three load averages is multiplied by 100,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6058 then converted to integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6060 When USE-FLOATS is non-nil, floats will be used instead of integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6061 These floats are not multiplied by 100.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6063 If the 5-minute or 15-minute load averages are not available, return a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6064 shortened list, containing only those averages which are available.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6066 On some systems, this won't work due to permissions on /dev/kmem,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6067 in which case you can't use this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6068 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6069 (use_floats))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6070 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6071 double load_ave[3];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6072 int loads = getloadavg (load_ave, countof (load_ave));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6073 Lisp_Object ret = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6075 if (loads == -2)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6076 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6077 "load-average not implemented for this operating system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6078 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6079 else if (loads < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6080 invalid_operation ("Could not get load-average", lisp_strerror (errno));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6082 while (loads-- > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6083 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6084 Lisp_Object load = (NILP (use_floats) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6085 make_int ((int) (100.0 * load_ave[loads]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6086 : make_float (load_ave[loads]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6087 ret = Fcons (load, ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6088 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6089 return ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6090 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6093 Lisp_Object Vfeatures;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6095 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6096 Return non-nil if feature FEXP is present in this Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6097 Use this to conditionalize execution of lisp code based on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6098 presence or absence of emacs or environment extensions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6099 FEXP can be a symbol, a number, or a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6100 If it is a symbol, that symbol is looked up in the `features' variable,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6101 and non-nil will be returned if found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6102 If it is a number, the function will return non-nil if this Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6103 has an equal or greater version number than FEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6104 If it is a list whose car is the symbol `and', it will return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6105 non-nil if all the features in its cdr are non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6106 If it is a list whose car is the symbol `or', it will return non-nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6107 if any of the features in its cdr are non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6108 If it is a list whose car is the symbol `not', it will return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6109 non-nil if the feature is not present.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6111 Examples:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6113 (featurep 'xemacs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6114 => ; Non-nil on XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6116 (featurep '(and xemacs gnus))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6117 => ; Non-nil on XEmacs with Gnus loaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6119 (featurep '(or tty-frames (and emacs 19.30)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6120 => ; Non-nil if this Emacs supports TTY frames.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6122 (featurep '(or (and xemacs 19.15) (and emacs 19.34)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6123 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6124
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6125 (featurep '(and xemacs 21.02))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6126 => ; Non-nil on XEmacs 21.2 and later.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6127
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6128 NOTE: The advanced arguments of this function (anything other than a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6129 symbol) are not yet supported by FSF Emacs. If you feel they are useful
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6130 for supporting multiple Emacs variants, lobby Richard Stallman at
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6131 <bug-gnu-emacs@gnu.org>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6132 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6133 (fexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6134 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6135 #ifndef FEATUREP_SYNTAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6136 CHECK_SYMBOL (fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6137 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6138 #else /* FEATUREP_SYNTAX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6139 static double featurep_emacs_version;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6141 /* Brute force translation from Erik Naggum's lisp function. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6142 if (SYMBOLP (fexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6144 /* Original definition */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6145 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6146 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6147 else if (INTP (fexp) || FLOATP (fexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6148 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6149 double d = extract_float (fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6151 if (featurep_emacs_version == 0.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6153 featurep_emacs_version = XINT (Vemacs_major_version) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6154 (XINT (Vemacs_minor_version) / 100.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6155 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6156 return featurep_emacs_version >= d ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6157 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6158 else if (CONSP (fexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6159 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6160 Lisp_Object tem = XCAR (fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6161 if (EQ (tem, Qnot))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6162 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6163 Lisp_Object negate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6165 tem = XCDR (fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6166 negate = Fcar (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6167 if (!NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6168 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6169 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6170 return Fsignal (Qinvalid_read_syntax, list1 (tem));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6171 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6172 else if (EQ (tem, Qand))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6174 tem = XCDR (fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6175 /* Use Fcar/Fcdr for error-checking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6176 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6177 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6178 tem = Fcdr (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6180 return NILP (tem) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6181 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6182 else if (EQ (tem, Qor))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6184 tem = XCDR (fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6185 /* Use Fcar/Fcdr for error-checking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6186 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6188 tem = Fcdr (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6190 return NILP (tem) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6191 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6192 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6194 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6196 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6197 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6199 return Fsignal (Qinvalid_read_syntax, list1 (fexp));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6201 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6202 #endif /* FEATUREP_SYNTAX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6204 DEFUN ("provide", Fprovide, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6205 Announce that FEATURE is a feature of the current Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6206 This function updates the value of the variable `features'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6207 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6208 (feature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6209 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6210 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6211 CHECK_SYMBOL (feature);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6212 if (!NILP (Vautoload_queue))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6213 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6214 tem = Fmemq (feature, Vfeatures);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6215 if (NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6216 Vfeatures = Fcons (feature, Vfeatures);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6217 LOADHIST_ATTACH (Fcons (Qprovide, feature));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6218 return feature;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6219 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6220
1067
a0a7ace216fe [xemacs-hg @ 2002-10-24 13:55:42 by youngs]
youngs
parents: 949
diff changeset
6221 DEFUN ("require", Frequire, 1, 3, 0, /*
3842
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6222 Ensure that FEATURE is present in the Lisp environment.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6223 FEATURE is a symbol naming a collection of resources (functions, etc).
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6224 Optional FILENAME is a library from which to load resources; it defaults to
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6225 the print name of FEATURE.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6226 Optional NOERROR, if non-nil, causes require to return nil rather than signal
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6227 `file-error' if loading the library fails.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6228
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6229 If feature FEATURE is present in `features', update `load-history' to reflect
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6230 the require and return FEATURE. Otherwise, try to load it from a library.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6231 The normal messages at start and end of loading are suppressed.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6232 If the library is successfully loaded and it calls `(provide FEATURE)', add
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6233 FEATURE to `features', update `load-history' and return FEATURE.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6234 If the load succeeds but FEATURE is not provided by the library, signal
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6235 `invalid-state'.
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6236
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6237 The byte-compiler treats top-level calls to `require' specially, by evaluating
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6238 them at compile time (and then compiling them normally). Thus a library may
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6239 request that definitions that should be inlined such as macros and defsubsts
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6240 be loaded into its compilation environment. Achieving this in other contexts
1c2a46ea1f78 [xemacs-hg @ 2007-02-22 16:53:20 by stephent]
stephent
parents: 3794
diff changeset
6241 requires an explicit \(eval-and-compile ...\) block.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6242 */
1067
a0a7ace216fe [xemacs-hg @ 2002-10-24 13:55:42 by youngs]
youngs
parents: 949
diff changeset
6243 (feature, filename, noerror))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6244 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6245 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6246 CHECK_SYMBOL (feature);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6247 tem = Fmemq (feature, Vfeatures);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6248 LOADHIST_ATTACH (Fcons (Qrequire, feature));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6249 if (!NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6250 return feature;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6251 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6253 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6255 /* Value saved here is to be restored into Vautoload_queue */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6256 record_unwind_protect (un_autoload, Vautoload_queue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6257 Vautoload_queue = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6258
1067
a0a7ace216fe [xemacs-hg @ 2002-10-24 13:55:42 by youngs]
youngs
parents: 949
diff changeset
6259 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename,
1261
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 1204
diff changeset
6260 noerror, Qrequire, Qnil);
1067
a0a7ace216fe [xemacs-hg @ 2002-10-24 13:55:42 by youngs]
youngs
parents: 949
diff changeset
6261 /* If load failed entirely, return nil. */
a0a7ace216fe [xemacs-hg @ 2002-10-24 13:55:42 by youngs]
youngs
parents: 949
diff changeset
6262 if (NILP (tem))
a0a7ace216fe [xemacs-hg @ 2002-10-24 13:55:42 by youngs]
youngs
parents: 949
diff changeset
6263 return unbind_to_1 (speccount, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6265 tem = Fmemq (feature, Vfeatures);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6266 if (NILP (tem))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6267 invalid_state ("Required feature was not provided", feature);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6269 /* Once loading finishes, don't undo it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6270 Vautoload_queue = Qt;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6271 return unbind_to_1 (speccount, feature);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6273 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6275 /* base64 encode/decode functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6277 Originally based on code from GNU recode. Ported to FSF Emacs by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6278 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6279 subsequently heavily hacked by Hrvoje Niksic. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6281 #define MIME_LINE_LENGTH 72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6283 #define IS_ASCII(Character) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6284 ((Character) < 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6285 #define IS_BASE64(Character) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6286 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6288 /* 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
6289 static Ascbyte base64_value_to_char[64] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6291 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6292 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6293 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6294 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6295 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6296 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6297 '8', '9', '+', '/' /* 60-63 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6298 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6300 /* Table of base64 values for first 128 characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6301 static short base64_char_to_value[128] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6302 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6303 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6304 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6305 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6306 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6307 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6308 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6309 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6310 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6311 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6312 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6313 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6314 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6315 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6316 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6318 /* The following diagram shows the logical steps by which three octets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6319 get transformed into four base64 characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6321 .--------. .--------. .--------.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6322 |aaaaaabb| |bbbbcccc| |ccdddddd|
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6323 `--------' `--------' `--------'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6324 6 2 4 4 2 6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6325 .--------+--------+--------+--------.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6326 |00aaaaaa|00bbbbbb|00cccccc|00dddddd|
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6327 `--------+--------+--------+--------'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6329 .--------+--------+--------+--------.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6330 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD|
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6331 `--------+--------+--------+--------'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6333 The octets are divided into 6 bit chunks, which are then encoded into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6334 base64 characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6335
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
6336 static DECLARE_DOESNT_RETURN (base64_conversion_error (const Ascbyte *,
2268
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 2039
diff changeset
6337 Lisp_Object));
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 2039
diff changeset
6338
575
d5e8f5ad5043 [xemacs-hg @ 2001-05-25 04:22:31 by martinb]
martinb
parents: 563
diff changeset
6339 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
6340 base64_conversion_error (const Ascbyte *reason, Lisp_Object frob)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6341 {
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6342 signal_error (Qbase64_conversion_error, reason, frob);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6343 }
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6344
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6345 #define ADVANCE_INPUT(c, stream) \
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6346 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6347 ((ec > 255) ? \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6348 (base64_conversion_error ("Non-ascii character in base64 input", \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6349 make_char (ec)), 0) \
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6350 : (c = (Ibyte)ec), 1))
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6351
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6352 static Bytebpos
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6353 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6355 EMACS_INT counter = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6356 Ibyte *e = to;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6357 Ichar ec;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6358 unsigned int value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6360 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6361 {
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1067
diff changeset
6362 Ibyte c = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6363 if (!ADVANCE_INPUT (c, istream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6364 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6366 /* Wrap line every 76 characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6367 if (line_break)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6368 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6369 if (counter < MIME_LINE_LENGTH / 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6370 counter++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6371 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6372 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6373 *e++ = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6374 counter = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6375 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6376 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6378 /* Process first byte of a triplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6379 *e++ = base64_value_to_char[0x3f & c >> 2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6380 value = (0x03 & c) << 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6382 /* Process second byte of a triplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6383 if (!ADVANCE_INPUT (c, istream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6384 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6385 *e++ = base64_value_to_char[value];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6386 *e++ = '=';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6387 *e++ = '=';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6388 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6391 *e++ = base64_value_to_char[value | (0x0f & c >> 4)];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6392 value = (0x0f & c) << 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6394 /* Process third byte of a triplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6395 if (!ADVANCE_INPUT (c, istream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6396 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6397 *e++ = base64_value_to_char[value];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6398 *e++ = '=';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6399 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6400 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6402 *e++ = base64_value_to_char[value | (0x03 & c >> 6)];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6403 *e++ = base64_value_to_char[0x3f & c];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6406 return e - to;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6408 #undef ADVANCE_INPUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6410 /* Get next character from the stream, except that non-base64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6411 characters are ignored. This is in accordance with rfc2045. EC
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6412 should be an Ichar, so that it can hold -1 as the value for EOF. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6413 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6414 ec = Lstream_get_ichar (stream); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6415 ++streampos; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6416 /* IS_BASE64 may not be called with negative arguments so check for \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6417 EOF first. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6418 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6419 break; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6420 } while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6422 #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
6423 pos += set_itext_ichar (pos, (Ichar)((Binbyte)(val))); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6424 ++ccnt; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6425 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6426
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6427 static Bytebpos
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6428 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6429 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6430 Charcount ccnt = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6431 Ibyte *e = to;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6432 EMACS_INT streampos = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6434 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6435 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6436 Ichar ec;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6437 unsigned long value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6439 /* Process first byte of a quadruplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6440 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6441 if (ec < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6442 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6443 if (ec == '=')
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6444 base64_conversion_error ("Illegal `=' character while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6445 make_int (streampos));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6446 value = base64_char_to_value[ec] << 18;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6448 /* Process second byte of a quadruplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6449 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6450 if (ec < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6451 base64_conversion_error ("Premature EOF while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6452 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6453 if (ec == '=')
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6454 base64_conversion_error ("Illegal `=' character while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6455 make_int (streampos));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6456 value |= base64_char_to_value[ec] << 12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6457 STORE_BYTE (e, value >> 16, ccnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6458
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6459 /* Process third byte of a quadruplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6460 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6461 if (ec < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6462 base64_conversion_error ("Premature EOF while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6463 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6465 if (ec == '=')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6466 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6467 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6468 if (ec < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6469 base64_conversion_error ("Premature EOF while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6470 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6471 if (ec != '=')
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6472 base64_conversion_error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6473 ("Padding `=' expected but not found while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6474 make_int (streampos));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6475 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6476 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6478 value |= base64_char_to_value[ec] << 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6479 STORE_BYTE (e, 0xff & value >> 8, ccnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6481 /* Process fourth byte of a quadruplet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6482 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6483 if (ec < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6484 base64_conversion_error ("Premature EOF while decoding base64",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6485 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6486 if (ec == '=')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6487 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6489 value |= base64_char_to_value[ec];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6490 STORE_BYTE (e, 0xff & value, ccnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6491 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6493 *ccptr = ccnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6494 return e - to;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6496 #undef ADVANCE_INPUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6497 #undef ADVANCE_INPUT_IGNORE_NONBASE64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6498 #undef STORE_BYTE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6500 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6501 Base64-encode the region between START and END.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6502 Return the length of the encoded text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6503 Optional third argument NO-LINE-BREAK means do not break long lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6504 into shorter lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6505 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6506 (start, end, no_line_break))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6507 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6508 Ibyte *encoded;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6509 Bytebpos encoded_length;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6510 Charcount allength, length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6511 struct buffer *buf = current_buffer;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6512 Charbpos begv, zv, old_pt = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6513 Lisp_Object input;
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
6514 int speccount = specpdl_depth ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6515
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6516 get_buffer_range_char (buf, start, end, &begv, &zv, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6517 barf_if_buffer_read_only (buf, begv, zv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6519 /* We need to allocate enough room for encoding the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6520 We need 33 1/3% more space, plus a newline every 76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6521 characters, and then we round up. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6522 length = zv - begv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6523 allength = length + length/3 + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6524 allength += allength / MIME_LINE_LENGTH + 1 + 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6526 input = make_lisp_buffer_input_stream (buf, begv, zv, 0);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6527 /* We needn't multiply allength with MAX_ICHAR_LEN because all the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6528 base64 characters will be single-byte. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6529 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6530 encoded_length = base64_encode_1 (XLSTREAM (input), encoded,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6531 NILP (no_line_break));
5050
6f2158fa75ed Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents: 5002
diff changeset
6532 assert (encoded_length <= allength);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6533 Lstream_delete (XLSTREAM (input));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6535 /* Now we have encoded the region, so we insert the new contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6536 and delete the old. (Insert first in order to preserve markers.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6537 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0);
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
6538 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6539 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6541 /* Simulate FSF Emacs implementation of this function: if point was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6542 in the region, place it at the beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6543 if (old_pt >= begv && old_pt < zv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6544 BUF_SET_PT (buf, begv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6546 /* We return the length of the encoded text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6547 return make_int (encoded_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6550 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6551 Base64 encode STRING and return the result.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6552 Optional argument NO-LINE-BREAK means do not break long lines
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6553 into shorter lines.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6554 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6555 (string, no_line_break))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6556 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6557 Charcount allength, length;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6558 Bytebpos encoded_length;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6559 Ibyte *encoded;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6560 Lisp_Object input, result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6561 int speccount = specpdl_depth();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6563 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6564
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6565 length = string_char_length (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6566 allength = length + length/3 + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6567 allength += allength / MIME_LINE_LENGTH + 1 + 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6569 input = make_lisp_string_input_stream (string, 0, -1);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6570 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6571 encoded_length = base64_encode_1 (XLSTREAM (input), encoded,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6572 NILP (no_line_break));
5050
6f2158fa75ed Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents: 5002
diff changeset
6573 assert (encoded_length <= allength);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6574 Lstream_delete (XLSTREAM (input));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6575 result = make_string (encoded, encoded_length);
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
6576 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6577 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6580 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6581 Base64-decode the region between START and END.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6582 Return the length of the decoded text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6583 If the region can't be decoded, return nil and don't modify the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6584 Characters out of the base64 alphabet are ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6585 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6586 (start, end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6587 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6588 struct buffer *buf = current_buffer;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6589 Charbpos begv, zv, old_pt = BUF_PT (buf);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6590 Ibyte *decoded;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6591 Bytebpos decoded_length;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6592 Charcount length, cc_decoded_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6593 Lisp_Object input;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6594 int speccount = specpdl_depth();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6595
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
6596 get_buffer_range_char (buf, start, end, &begv, &zv, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6597 barf_if_buffer_read_only (buf, begv, zv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6599 length = zv - begv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6601 input = make_lisp_buffer_input_stream (buf, begv, zv, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6602 /* We need to allocate enough room for decoding the text. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6603 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6604 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
6605 assert (decoded_length <= length * MAX_ICHAR_LEN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6606 Lstream_delete (XLSTREAM (input));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6608 /* Now we have decoded the region, so we insert the new contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6609 and delete the old. (Insert first in order to preserve markers.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6610 BUF_SET_PT (buf, begv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6611 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0);
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
6612 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6613 buffer_delete_range (buf, begv + cc_decoded_length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6614 zv + cc_decoded_length, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6616 /* Simulate FSF Emacs implementation of this function: if point was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6617 in the region, place it at the beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6618 if (old_pt >= begv && old_pt < zv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6619 BUF_SET_PT (buf, begv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6621 return make_int (cc_decoded_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6624 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6625 Base64-decode STRING and return the result.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6626 Characters out of the base64 alphabet are ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6627 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6628 (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6629 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6630 Ibyte *decoded;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
6631 Bytebpos decoded_length;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6632 Charcount length, cc_decoded_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6633 Lisp_Object input, result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6634 int speccount = specpdl_depth();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6636 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6637
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6638 length = string_char_length (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6639 /* We need to allocate enough room for decoding the text. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6640 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6642 input = make_lisp_string_input_stream (string, 0, -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6643 decoded_length = base64_decode_1 (XLSTREAM (input), decoded,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6644 &cc_decoded_length);
5050
6f2158fa75ed Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents: 5002
diff changeset
6645 assert (decoded_length <= length * MAX_ICHAR_LEN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6646 Lstream_delete (XLSTREAM (input));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6648 result = make_string (decoded, decoded_length);
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 826
diff changeset
6649 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6650 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6651 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6653 Lisp_Object Qyes_or_no_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6655 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6656 syms_of_fns (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6657 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
6658 INIT_LISP_OBJECT (bit_vector);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6659
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6660 DEFSYMBOL (Qstring_lessp);
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6661 DEFSYMBOL (Qsort);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6662 DEFSYMBOL (Qmerge);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6663 DEFSYMBOL (Qfill);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6664 DEFSYMBOL (Qidentity);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6665 DEFSYMBOL (Qvector);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6666 DEFSYMBOL (Qarray);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6667 DEFSYMBOL (Qstring);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6668 DEFSYMBOL (Qlist);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6669 DEFSYMBOL (Qbit_vector);
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6670 defsymbol (&QsortX, "sort*");
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
6671 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
6672 DEFSYMBOL (Qreplace);
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
6673
5253
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6674 DEFSYMBOL (Qmapconcat);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6675 defsymbol (&QmapcarX, "mapcar*");
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6676 DEFSYMBOL (Qmapvector);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6677 DEFSYMBOL (Qmapcan);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6678 DEFSYMBOL (Qmapc);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6679 DEFSYMBOL (Qmap);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6680 DEFSYMBOL (Qmap_into);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6681 DEFSYMBOL (Qsome);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6682 DEFSYMBOL (Qevery);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6683 DEFSYMBOL (Qmaplist);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6684 DEFSYMBOL (Qmapl);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6685 DEFSYMBOL (Qmapcon);
b6a398dbb403 Fewer algorithmic complexity surprises, nicer errors, mapcarX(), maplist()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5241
diff changeset
6686
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
6687 DEFKEYWORD (Q_from_end);
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
6688 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
6689 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
6690 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
6691 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
6692 DEFKEYWORD (Q_end2);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6693
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6694 DEFSYMBOL (Qyes_or_no_p);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6695
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 456
diff changeset
6696 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6698 DEFSUBR (Fidentity);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6699 DEFSUBR (Frandom);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6700 DEFSUBR (Flength);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6701 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
6702 DEFSUBR (Flist_length);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6703 DEFSUBR (Fstring_equal);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
6704 DEFSUBR (Fcompare_strings);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6705 DEFSUBR (Fstring_lessp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6706 DEFSUBR (Fstring_modified_tick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6707 DEFSUBR (Fappend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6708 DEFSUBR (Fconcat);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6709 DEFSUBR (Fvconcat);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6710 DEFSUBR (Fbvconcat);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6711 DEFSUBR (Fcopy_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6712 DEFSUBR (Fcopy_sequence);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6713 DEFSUBR (Fcopy_alist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6714 DEFSUBR (Fcopy_tree);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6715 DEFSUBR (Fsubseq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6716 DEFSUBR (Fnthcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6717 DEFSUBR (Fnth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6718 DEFSUBR (Felt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6719 DEFSUBR (Flast);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6720 DEFSUBR (Fbutlast);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6721 DEFSUBR (Fnbutlast);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6722 DEFSUBR (Fmember);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6723 DEFSUBR (Fold_member);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6724 DEFSUBR (Fmemq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6725 DEFSUBR (Fold_memq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6726 DEFSUBR (Fassoc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6727 DEFSUBR (Fold_assoc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6728 DEFSUBR (Fassq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6729 DEFSUBR (Fold_assq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6730 DEFSUBR (Frassoc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6731 DEFSUBR (Fold_rassoc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6732 DEFSUBR (Frassq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6733 DEFSUBR (Fold_rassq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6734 DEFSUBR (Fdelete);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6735 DEFSUBR (Fold_delete);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6736 DEFSUBR (Fdelq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6737 DEFSUBR (Fold_delq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6738 DEFSUBR (Fremassoc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6739 DEFSUBR (Fremassq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6740 DEFSUBR (Fremrassoc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6741 DEFSUBR (Fremrassq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6742 DEFSUBR (Fnreverse);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6743 DEFSUBR (Freverse);
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6744 DEFSUBR (FsortX);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6745 Ffset (intern ("sort"), QsortX);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6746 DEFSUBR (Fmerge);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6747 DEFSUBR (Fplists_eq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6748 DEFSUBR (Fplists_equal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6749 DEFSUBR (Flax_plists_eq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6750 DEFSUBR (Flax_plists_equal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6751 DEFSUBR (Fplist_get);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6752 DEFSUBR (Fplist_put);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6753 DEFSUBR (Fplist_remprop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6754 DEFSUBR (Fplist_member);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6755 DEFSUBR (Fcheck_valid_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6756 DEFSUBR (Fvalid_plist_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6757 DEFSUBR (Fcanonicalize_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6758 DEFSUBR (Flax_plist_get);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6759 DEFSUBR (Flax_plist_put);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6760 DEFSUBR (Flax_plist_remprop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6761 DEFSUBR (Flax_plist_member);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6762 DEFSUBR (Fcanonicalize_lax_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6763 DEFSUBR (Fdestructive_alist_to_plist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6764 DEFSUBR (Fget);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6765 DEFSUBR (Fput);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6766 DEFSUBR (Fremprop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6767 DEFSUBR (Fobject_plist);
5255
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5253
diff changeset
6768 DEFSUBR (Fobject_setplist);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6769 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
6770 DEFSUBR (Fequalp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6771 DEFSUBR (Fold_equal);
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6772 DEFSUBR (Ffill);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6773 Ffset (intern ("fillarray"), Qfill);
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5128
diff changeset
6774
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6775 DEFSUBR (Fnconc);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6776 DEFSUBR (FmapcarX);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6777 DEFSUBR (Fmapvector);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6778 DEFSUBR (Fmapcan);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6779 DEFSUBR (Fmapc);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6780 DEFSUBR (Fmapconcat);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6781 DEFSUBR (Fmap);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6782 DEFSUBR (Fmap_into);
4997
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
6783 DEFSUBR (Fsome);
8800b5350a13 Move #'some, #'every to C, implementing them with mapcarX.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
6784 DEFSUBR (Fevery);
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6785 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
6786 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
6787 DEFSUBR (Fmaplist);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6788 DEFSUBR (Fmapl);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6789 DEFSUBR (Fmapcon);
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4797
diff changeset
6790
5227
fbd1485af104 Move #'reduce to fns.c from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5224
diff changeset
6791 DEFSUBR (Freduce);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6792 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
6793 DEFSUBR (Freplace);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6794 DEFSUBR (Fload_average);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6795 DEFSUBR (Ffeaturep);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6796 DEFSUBR (Frequire);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6797 DEFSUBR (Fprovide);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6798 DEFSUBR (Fbase64_encode_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6799 DEFSUBR (Fbase64_encode_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6800 DEFSUBR (Fbase64_decode_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6801 DEFSUBR (Fbase64_decode_string);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6802
5224
35c2b7e9c03f Add #'substring-no-properties, omitting any extent data.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
6803 DEFSUBR (Fsubstring_no_properties);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6804 DEFSUBR (Fsplit_string_by_char);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6805 DEFSUBR (Fsplit_path); /* #### */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6806 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6807
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6808 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6809 vars_of_fns (void)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6810 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6811 DEFVAR_LISP ("path-separator", &Vpath_separator /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6812 The directory separator in search paths, as a string.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6813 */ );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6814 {
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
6815 Ascbyte c = SEPCHAR;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
6816 Vpath_separator = make_string ((Ibyte *) &c, 1);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 751
diff changeset
6817 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6818 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6820 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6821 init_provide_once (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6822 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6823 DEFVAR_LISP ("features", &Vfeatures /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6824 A list of symbols which are the features of the executing emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6825 Used by `featurep' and `require', and altered by `provide'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6826 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6827 Vfeatures = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6829 Fprovide (intern ("base64"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6830 }