annotate src/fns.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 501cfd01ee6d
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Random utility Lisp functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.0, FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* Note: FSF 19.30 has bool vectors. We have bit vectors. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 /* Hacked on for Mule by Ben Wing, December 1994, January 1995. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 /* Note on some machines this defines `vector' as a typedef,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 so make sure we don't use that name in this file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #undef vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #define vector *****
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
39 #include "sysfile.h"
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
40
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "bytecode.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include "systime.h"
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
48 #include "insdel.h"
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
49 #include "lstream.h"
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
50 #include "opaque.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
140
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 120
diff changeset
52 /* NOTE: This symbol is also used in lread.c */
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 120
diff changeset
53 #define FEATUREP_SYNTAX
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 120
diff changeset
54
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Lisp_Object Qstring_lessp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 Lisp_Object Qidentity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
58 static int internal_old_equal (Lisp_Object, Lisp_Object, int);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
61 mark_bit_vector (Lisp_Object obj)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 {
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
63 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
69 size_t i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
70 Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
71 size_t len = bit_vector_length (v);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
72 size_t last = len;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 if (INTP (Vprint_length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 last = min (len, XINT (Vprint_length));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 write_c_string ("#*", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 for (i = 0; i < last; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if (bit_vector_bit (v, i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 write_c_string ("1", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 write_c_string ("0", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 if (last != len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 write_c_string ("...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
90 bit_vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
92 Lisp_Bit_Vector *v1 = XBIT_VECTOR (obj1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
93 Lisp_Bit_Vector *v2 = XBIT_VECTOR (obj2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
95 return ((bit_vector_length (v1) == bit_vector_length (v2)) &&
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
96 !memcmp (v1->bits, v2->bits,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
97 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) *
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
98 sizeof (long)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 bit_vector_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
104 Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 return HASH2 (bit_vector_length (v),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 memory_hash (v->bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 sizeof (long)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
111 static size_t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
112 size_bit_vector (const void *lheader)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
113 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
114 Lisp_Bit_Vector *v = (Lisp_Bit_Vector *) lheader;
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
115 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, bits,
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
116 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)));
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
117 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
118
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
119 static const struct lrecord_description bit_vector_description[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
120 { XD_LISP_OBJECT, offsetof (Lisp_Bit_Vector, next) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
121 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
122 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
123
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
124
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
125 DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION ("bit-vector", bit_vector,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
126 mark_bit_vector, print_bit_vector, 0,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
127 bit_vector_equal, bit_vector_hash,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
128 bit_vector_description, size_bit_vector,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
129 Lisp_Bit_Vector);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
130
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
131 DEFUN ("identity", Fidentity, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Return the argument unchanged.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
133 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
134 (arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 return arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 extern long get_random (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 extern void seed_random (long arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
142 DEFUN ("random", Frandom, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 Return a pseudo-random number.
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 76
diff changeset
144 All integers representable in Lisp are equally likely.
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 76
diff changeset
145 On most systems, this is 28 bits' worth.
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 76
diff changeset
146 With positive integer argument N, return random number in interval [0,N).
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 With argument t, set the random number seed from the current time and pid.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
148 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
149 (limit))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 EMACS_INT val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 unsigned long denominator;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (EQ (limit, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 seed_random (getpid () + time (NULL));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 if (NATNUMP (limit) && !ZEROP (limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 /* Try to take our random number from the higher bits of VAL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 not the lower, since (says Gentzel) the low bits of `random'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 are less random than the higher ones. We do this by using the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 quotient rather than the remainder. At the high end of the RNG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 it's possible to get a quotient larger than limit; discarding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 these values eliminates the bias that would otherwise appear
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 when using a large limit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 denominator = ((unsigned long)1 << VALBITS) / XINT (limit);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 val = get_random () / denominator;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 while (val >= XINT (limit));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 val = get_random ();
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
172
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
173 return make_int (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 /* Random data-structure functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 /* #### Delete this shit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 /* Charcount is a misnomer here as we might be dealing with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 length of a vector or list, but emphasizes that we're not dealing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 with Bytecounts in strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 static Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 length_with_bytecode_hack (Lisp_Object seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 if (!COMPILED_FUNCTIONP (seq))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
189 return XINT (Flength (seq));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
192 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (seq);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
193
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
194 return (f->flags.interactivep ? COMPILED_INTERACTIVE :
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
195 f->flags.domainp ? COMPILED_DOMAIN :
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
196 COMPILED_DOC_STRING)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
197 + 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #endif /* LOSING_BYTECODE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
204 check_losing_bytecode (const char *function, Lisp_Object seq)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 if (COMPILED_FUNCTIONP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 error_with_frob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (seq,
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
209 "As of 20.3, `%s' no longer works with compiled-function objects",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
213 DEFUN ("length", Flength, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 Return the length of vector, bit vector, list or string SEQUENCE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
215 */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
216 (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 retry:
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
219 if (STRINGP (sequence))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
220 return make_int (XSTRING_CHAR_LENGTH (sequence));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
221 else if (CONSP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
223 size_t len;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
224 GET_EXTERNAL_LIST_LENGTH (sequence, len);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
225 return make_int (len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
227 else if (VECTORP (sequence))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
228 return make_int (XVECTOR_LENGTH (sequence));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
229 else if (NILP (sequence))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
230 return Qzero;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
231 else if (BIT_VECTORP (sequence))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
232 return make_int (bit_vector_length (XBIT_VECTOR (sequence)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
235 check_losing_bytecode ("length", sequence);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
236 sequence = wrong_type_argument (Qsequencep, sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
241 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 Return the length of a list, but avoid error or infinite loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 This function never gets an error. If LIST is not really a list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 it returns 0. If LIST is circular, it returns a finite value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 which is at least the number of distinct elements.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
246 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
247 (list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
249 Lisp_Object hare, tortoise;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
250 size_t len;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
251
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
252 for (hare = tortoise = list, len = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
253 CONSP (hare) && (! EQ (hare, tortoise) || len == 0);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
254 hare = XCDR (hare), len++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
256 if (len & 1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
257 tortoise = XCDR (tortoise);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
260 return make_int (len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 /*** string functions. ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
265 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
266 Return t if two strings have identical contents.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 Case is significant. Text properties are ignored.
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 223
diff changeset
268 \(Under XEmacs, `equal' also ignores text properties and extents in
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 223
diff changeset
269 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 223
diff changeset
270 `equal' is the same as in XEmacs, in that respect.)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 Symbols are also allowed; their print names are used instead.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
272 */
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 223
diff changeset
273 (s1, s2))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
275 Bytecount len;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
276 Lisp_String *p1, *p2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 if (SYMBOLP (s1))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
279 p1 = XSYMBOL (s1)->name;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
280 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
281 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
282 CHECK_STRING (s1);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
283 p1 = XSTRING (s1);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
284 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
285
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (SYMBOLP (s2))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
287 p2 = XSYMBOL (s2)->name;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
288 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
289 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
290 CHECK_STRING (s2);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
291 p2 = XSTRING (s2);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
292 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
293
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
294 return (((len = string_length (p1)) == string_length (p2)) &&
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
295 !memcmp (string_data (p1), string_data (p2), len)) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
299 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
300 Return t if first arg string is less than second in lexicographic order.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
301 If I18N2 support (but not Mule support) was compiled in, ordering is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
302 determined by the locale. (Case is significant for the default C locale.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
303 In all other cases, comparison is simply done on a character-by-
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
304 character basis using the numeric value of a character. (Note that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
305 this may not produce particularly meaningful results under Mule if
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
306 characters from different charsets are being compared.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
307
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 Symbols are also allowed; their print names are used instead.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
309
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
310 The reason that the I18N2 locale-specific collation is not used under
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
311 Mule is that the locale model of internationalization does not handle
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
312 multiple charsets and thus has no hope of working properly under Mule.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
313 What we really should do is create a collation table over all built-in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
314 charsets. This is extremely difficult to do from scratch, however.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
315
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
316 Unicode is a good first step towards solving this problem. In fact,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
317 it is quite likely that a collation table exists (or will exist) for
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
318 Unicode. When Unicode support is added to XEmacs/Mule, this problem
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
319 may be solved.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
320 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
321 (s1, s2))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
323 Lisp_String *p1, *p2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 Charcount end, len2;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
325 int i;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 if (SYMBOLP (s1))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
328 p1 = XSYMBOL (s1)->name;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
329 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
330 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
331 CHECK_STRING (s1);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
332 p1 = XSTRING (s1);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
333 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
334
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 if (SYMBOLP (s2))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
336 p2 = XSYMBOL (s2)->name;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
337 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
338 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
339 CHECK_STRING (s2);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
340 p2 = XSTRING (s2);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
341 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
342
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
343 end = string_char_length (p1);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
344 len2 = string_char_length (p2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 if (end > len2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 end = len2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
348 #if defined (I18N2) && !defined (MULE)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
349 /* There is no hope of this working under Mule. Even if we converted
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
350 the data into an external format so that strcoll() processed it
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
351 properly, it would still not work because strcoll() does not
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
352 handle multiple locales. This is the fundamental flaw in the
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
353 locale model. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
354 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
355 Bytecount bcend = charcount_to_bytecount (string_data (p1), end);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
356 /* Compare strings using collation order of locale. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
357 /* Need to be tricky to handle embedded nulls. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
358
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
359 for (i = 0; i < bcend; i += strlen((char *) string_data (p1) + i) + 1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
360 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
361 int val = strcoll ((char *) string_data (p1) + i,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
362 (char *) string_data (p2) + i);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
363 if (val < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
364 return Qt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
365 if (val > 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
366 return Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
367 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
368 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
369 #else /* not I18N2, or MULE */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
370 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
371 Bufbyte *ptr1 = string_data (p1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
372 Bufbyte *ptr2 = string_data (p2);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
373
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
374 /* #### It is not really necessary to do this: We could compare
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
375 byte-by-byte and still get a reasonable comparison, since this
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
376 would compare characters with a charset in the same way. With
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
377 a little rearrangement of the leading bytes, we could make most
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
378 inter-charset comparisons work out the same, too; even if some
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
379 don't, this is not a big deal because inter-charset comparisons
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
380 aren't really well-defined anyway. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
381 for (i = 0; i < end; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
382 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
383 if (charptr_emchar (ptr1) != charptr_emchar (ptr2))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
384 return charptr_emchar (ptr1) < charptr_emchar (ptr2) ? Qt : Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
385 INC_CHARPTR (ptr1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
386 INC_CHARPTR (ptr2);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
387 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
388 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
389 #endif /* not I18N2, or MULE */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
390 /* Can't do i < len2 because then comparison between "foo" and "foo^@"
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
391 won't work right in I18N2 case */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
392 return end < len2 ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
395 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 Return STRING's tick counter, incremented for each change to the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 Each string has a tick counter which is incremented each time the contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 of the string are changed (e.g. with `aset'). It wraps around occasionally.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
399 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
400 (string))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
402 Lisp_String *s;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 s = XSTRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 if (CONSP (s->plist) && INTP (XCAR (s->plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 return XCAR (s->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 return Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 bump_string_modiff (Lisp_Object str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
415 Lisp_String *s = XSTRING (str);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 Lisp_Object *ptr = &s->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 /* #### remove the `string-translatable' property from the string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 if there is one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 /* skip over extent info if it's there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ptr = &XCDR (*ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 XSETINT (XCAR (*ptr), 1+XINT (XCAR (*ptr)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 *ptr = Fcons (make_int (1), *ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 static Lisp_Object concat (int nargs, Lisp_Object *args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 enum concat_target_type target_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 int last_special);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 concat2 (Lisp_Object s1, Lisp_Object s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 return concat (2, args, c_string, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 concat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 Lisp_Object args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 args[2] = s3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 return concat (3, args, c_string, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 vconcat2 (Lisp_Object s1, Lisp_Object s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 return concat (2, args, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 vconcat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Lisp_Object args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 args[2] = s3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 return concat (3, args, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
475 DEFUN ("append", Fappend, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 Concatenate all the arguments and make the result a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 The result is a list whose elements are the elements of all the arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 Each argument may be a list, vector, bit vector, or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 The last argument is not copied, just used as the tail of the new list.
201
eb5470882647 Import from CVS: tag r20-3b27
cvs
parents: 195
diff changeset
480 Also see: `nconc'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
481 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
482 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 return concat (nargs, args, c_cons, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
487 DEFUN ("concat", Fconcat, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 Concatenate all the arguments and make the result a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 The result is a string whose elements are the elements of all the arguments.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
490 Each argument may be a string or a list or vector of characters.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 284
diff changeset
492 As of XEmacs 21.0, this function does NOT accept individual integers
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 284
diff changeset
493 as arguments. Old code that relies on, for example, (concat "foo" 50)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 284
diff changeset
494 returning "foo50" will fail. To fix such code, either apply
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 284
diff changeset
495 `int-to-string' to the integer argument, or use `format'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
496 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
497 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 return concat (nargs, args, c_string, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
502 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 Concatenate all the arguments and make the result a vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 The result is a vector whose elements are the elements of all the arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 Each argument may be a list, vector, bit vector, or string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
506 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
507 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 return concat (nargs, args, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
512 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Concatenate all the arguments and make the result a bit vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 The result is a bit vector whose elements are the elements of all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 arguments. Each argument may be a list, vector, bit vector, or string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
516 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
517 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 return concat (nargs, args, c_bit_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
522 /* Copy a (possibly dotted) list. LIST must be a cons.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
523 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
524 static Lisp_Object
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
525 copy_list (Lisp_Object list)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
526 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
527 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
528 Lisp_Object last = list_copy;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
529 Lisp_Object hare, tortoise;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
530 size_t len;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
531
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
532 for (tortoise = hare = XCDR (list), len = 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
533 CONSP (hare);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
534 hare = XCDR (hare), len++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
535 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
536 XCDR (last) = Fcons (XCAR (hare), XCDR (hare));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
537 last = XCDR (last);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
538
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
539 if (len < CIRCULAR_LIST_SUSPICION_LENGTH)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
540 continue;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
541 if (len & 1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
542 tortoise = XCDR (tortoise);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
543 if (EQ (tortoise, hare))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
544 signal_circular_list_error (list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
545 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
546
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
547 return list_copy;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
548 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
549
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
550 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
551 Return a copy of list LIST, which may be a dotted list.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
552 The elements of LIST are not copied; they are shared
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 with the original.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
554 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
555 (list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 again:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
558 if (NILP (list)) return list;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
559 if (CONSP (list)) return copy_list (list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
560
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
561 list = wrong_type_argument (Qlistp, list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
562 goto again;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
563 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
564
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
565 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
566 Return a copy of list, vector, bit vector or string SEQUENCE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
567 The elements of a list or vector are not copied; they are shared
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
568 with the original. SEQUENCE may be a dotted list.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
569 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
570 (sequence))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
571 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
572 again:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
573 if (NILP (sequence)) return sequence;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
574 if (CONSP (sequence)) return copy_list (sequence);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
575 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
576 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
577 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
578
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
579 check_losing_bytecode ("copy-sequence", sequence);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
580 sequence = wrong_type_argument (Qsequencep, sequence);
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
581 goto again;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 struct merge_string_extents_struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 Lisp_Object string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 Bytecount entry_offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 Bytecount entry_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 concat (int nargs, Lisp_Object *args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 enum concat_target_type target_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 int last_special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 Lisp_Object tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 int toindex;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 int argnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 Lisp_Object last_tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 Lisp_Object prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 struct merge_string_extents_struct *args_mse = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 Bufbyte *string_result = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 Bufbyte *string_result_ptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 /* The modus operandi in Emacs is "caller gc-protects args".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 However, concat is called many times in Emacs on freshly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 created stuff. So we help those callers out by protecting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 the args ourselves to save them a lot of temporary-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 grief. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 GCPRO1 (args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 gcpro1.nvars = nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 /* #### if the result is a string and any of the strings have a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 for the `string-translatable' property, then concat should also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 concat the args but use the `string-translatable' strings, and store
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 the result in the returned string's `string-translatable' property. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 if (target_type == c_string)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
623 args_mse = alloca_array (struct merge_string_extents_struct, nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 /* In append, the last arg isn't treated like the others */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 if (last_special && nargs > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 nargs--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 last_tail = args[nargs];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 last_tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 /* Check and coerce the arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 Lisp_Object seq = args[argnum];
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
638 if (LISTP (seq))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 else if (COMPILED_FUNCTIONP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 /* Urk! We allow this, for "compatibility"... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 #endif
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 278
diff changeset
647 #if 0 /* removed for XEmacs 21 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 else if (INTP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 /* This is too revolting to think about but maintains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 compatibility with FSF (and lots and lots of old code). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 args[argnum] = Fnumber_to_string (seq);
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 278
diff changeset
652 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 check_losing_bytecode ("concat", seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 args[argnum] = wrong_type_argument (Qsequencep, seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
658
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 if (args_mse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 if (STRINGP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 args_mse[argnum].string = seq;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 args_mse[argnum].string = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 /* Charcount is a misnomer here as we might be dealing with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 length of a vector or list, but emphasizes that we're not dealing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 with Bytecounts in strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 Charcount total_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 for (argnum = 0, total_length = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 Charcount thislen = length_with_bytecode_hack (args[argnum]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 Charcount thislen = XINT (Flength (args[argnum]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 total_length += thislen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 switch (target_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 case c_cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 if (total_length == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 /* In append, if all but last arg are nil, return last arg */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 RETURN_UNGCPRO (last_tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 val = Fmake_list (make_int (total_length), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 case c_vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 val = make_vector (total_length, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 case c_bit_vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 val = make_bit_vector (total_length, Qzero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 case c_string:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 /* We don't make the string yet because we don't know the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 actual number of bytes. This loop was formerly written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 to call Fmake_string() here and then call set_string_char()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 for each char. This seems logical enough but is waaaaaaaay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 slow -- set_string_char() has to scan the whole string up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 to the place where the substitution is called for in order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 to find the place to change, and may have to do some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 realloc()ing in order to make the char fit properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 O(N^2) yuckage. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 string_result = (Bufbyte *) alloca (total_length * MAX_EMCHAR_LEN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 string_result_ptr = string_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 if (CONSP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 tail = val, toindex = -1; /* -1 in toindex is flag we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 making a list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 toindex = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 Charcount thisleni = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 Charcount thisindex = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 Lisp_Object seq = args[argnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 Bufbyte *string_source_ptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 Bufbyte *string_prev_result_ptr = string_result_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 if (!CONSP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 thisleni = length_with_bytecode_hack (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 thisleni = XINT (Flength (seq));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 if (STRINGP (seq))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
743 string_source_ptr = XSTRING_DATA (seq);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 Lisp_Object elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 /* We've come to the end of this arg, so exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 if (NILP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 /* Fetch next element of `seq' arg into `elt' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 if (CONSP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 {
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
756 elt = XCAR (seq);
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
757 seq = XCDR (seq);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 if (thisindex >= thisleni)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 if (STRINGP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 elt = make_char (charptr_emchar (string_source_ptr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 INC_CHARPTR (string_source_ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 else if (VECTORP (seq))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
770 elt = XVECTOR_DATA (seq)[thisindex];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 else if (BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 thisindex));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 elt = Felt (seq, make_int (thisindex));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 thisindex++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 /* Store into result */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 if (toindex < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 /* toindex negative means we are making a list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 XCAR (tail) = elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 tail = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 else if (VECTORP (val))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
788 XVECTOR_DATA (val)[toindex++] = elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 else if (BIT_VECTORP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 CHECK_BIT (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 CHECK_CHAR_COERCE_INT (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 string_result_ptr += set_charptr_emchar (string_result_ptr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 XCHAR (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 if (args_mse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 args_mse[argnum].entry_offset =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 string_prev_result_ptr - string_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 args_mse[argnum].entry_length =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 string_result_ptr - string_prev_result_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 /* Now we finally make the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 if (target_type == c_string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 val = make_string (string_result, string_result_ptr - string_result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 if (STRINGP (args_mse[argnum].string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 copy_string_extents (val, args_mse[argnum].string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 args_mse[argnum].entry_offset, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 args_mse[argnum].entry_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 if (!NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 XCDR (prev) = last_tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
826 RETURN_UNGCPRO (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
829 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 Return a copy of ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 This is an alist which represents the same mapping from objects to objects,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 but does not share the alist structure with ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 The objects mapped (cars and cdrs of elements of the alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 are shared, however.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 Elements of ALIST that are not conses are also shared.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
836 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
837 (alist))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
839 Lisp_Object tail;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
840
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 if (NILP (alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 return alist;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
843 CHECK_CONS (alist);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
844
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 alist = concat (1, &alist, c_cons, 0);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
846 for (tail = alist; CONSP (tail); tail = XCDR (tail))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
848 Lisp_Object car = XCAR (tail);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 if (CONSP (car))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
851 XCAR (tail) = Fcons (XCAR (car), XCDR (car));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 return alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
856 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 Return a copy of a list and substructures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 The argument is copied, and any lists contained within it are copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 recursively. Circularities and shared substructures are not preserved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 Second arg VECP causes vectors to be copied, too. Strings and bit vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 are not copied.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
862 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
863 (arg, vecp))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 if (CONSP (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 rest = arg = Fcopy_sequence (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 while (CONSP (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 Lisp_Object elt = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 if (CONSP (elt) || VECTORP (elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 XCAR (rest) = Fcopy_tree (elt, vecp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 XCDR (rest) = Fcopy_tree (XCDR (rest), vecp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 rest = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 else if (VECTORP (arg) && ! NILP (vecp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
882 int i = XVECTOR_LENGTH (arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 int j;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 arg = Fcopy_sequence (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 for (j = 0; j < i; j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
887 Lisp_Object elt = XVECTOR_DATA (arg) [j];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 if (CONSP (elt) || VECTORP (elt))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
890 XVECTOR_DATA (arg) [j] = Fcopy_tree (elt, vecp);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 return arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
896 DEFUN ("substring", Fsubstring, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 Return a substring of STRING, starting at index FROM and ending before TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 TO may be nil or omitted; then the substring runs to the end of STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 If FROM or TO is negative, it counts from the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 Relevant parts of the string-extent-data are copied in the new string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
901 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
902 (string, from, to))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 Charcount ccfr, ccto;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
905 Bytecount bfr, blen;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 CHECK_INT (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 get_string_range_char (string, from, to, &ccfr, &ccto,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 GB_HISTORICAL_STRING_BEHAVIOR);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
912 bfr = charcount_to_bytecount (XSTRING_DATA (string), ccfr);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
913 blen = charcount_to_bytecount (XSTRING_DATA (string) + bfr, ccto - ccfr);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
914 val = make_string (XSTRING_DATA (string) + bfr, blen);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 /* Copy any applicable extent information into the new string: */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
916 copy_string_extents (val, string, 0, bfr, blen);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
917 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
920 DEFUN ("subseq", Fsubseq, 2, 3, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
921 Return the subsequence of SEQUENCE starting at START and ending before END.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
922 END may be omitted; then the subsequence runs to the end of SEQUENCE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
923 If START or END is negative, it counts from the end.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
924 The returned subsequence is always of the same type as SEQUENCE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
925 If SEQUENCE is a string, relevant parts of the string-extent-data
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
926 are copied to the new string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
927 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
928 (sequence, start, end))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
930 EMACS_INT len, s, e;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
931
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
932 if (STRINGP (sequence))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
933 return Fsubstring (sequence, start, end);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
934
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
935 len = XINT (Flength (sequence));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
936
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
937 CHECK_INT (start);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
938 s = XINT (start);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
939 if (s < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
940 s = len + s;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
941
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
942 if (NILP (end))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
943 e = len;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
946 CHECK_INT (end);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
947 e = XINT (end);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
948 if (e < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
949 e = len + e;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
951
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
952 if (!(0 <= s && s <= e && e <= len))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
953 args_out_of_range_3 (sequence, make_int (s), make_int (e));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
954
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
955 if (VECTORP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
957 Lisp_Object result = make_vector (e - s, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
958 EMACS_INT i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
959 Lisp_Object *in_elts = XVECTOR_DATA (sequence);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
960 Lisp_Object *out_elts = XVECTOR_DATA (result);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
962 for (i = s; i < e; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
963 out_elts[i - s] = in_elts[i];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
966 else if (LISTP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 Lisp_Object result = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
969 EMACS_INT i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
970
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
971 sequence = Fnthcdr (make_int (s), sequence);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
972
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
973 for (i = s; i < e; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
975 result = Fcons (Fcar (sequence), result);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
976 sequence = Fcdr (sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 return Fnreverse (result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
981 else if (BIT_VECTORP (sequence))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
982 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
983 Lisp_Object result = make_bit_vector (e - s, Qzero);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
984 EMACS_INT i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
985
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
986 for (i = s; i < e; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
987 set_bit_vector_bit (XBIT_VECTOR (result), i - s,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
988 bit_vector_bit (XBIT_VECTOR (sequence), i));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
989 return result;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
990 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
991 else
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
992 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
993 abort (); /* unreachable, since Flength (sequence) did not get
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
994 an error */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
995 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
996 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1000 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1001 Take cdr N times on LIST, and return the result.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1002 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1003 (n, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1005 REGISTER size_t i;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1006 REGISTER Lisp_Object tail = list;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1007 CHECK_NATNUM (n);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1008 for (i = XINT (n); i; i--)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1010 if (CONSP (tail))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1011 tail = XCDR (tail);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1012 else if (NILP (tail))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1013 return Qnil;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1014 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1015 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1016 tail = wrong_type_argument (Qlistp, tail);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1017 i++;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1018 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1020 return tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1023 DEFUN ("nth", Fnth, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 Return the Nth element of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 N counts from zero. If LIST is not that long, nil is returned.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1026 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1027 (n, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 return Fcar (Fnthcdr (n, list));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1032 DEFUN ("elt", Felt, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 Return element of SEQUENCE at index N.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1034 */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1035 (sequence, n))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 retry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 CHECK_INT_COERCE_CHAR (n); /* yuck! */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1039 if (LISTP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1041 Lisp_Object tem = Fnthcdr (n, sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 /* #### Utterly, completely, fucking disgusting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 * #### The whole point of "elt" is that it operates on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 * #### sequences, and does error- (bounds-) checking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 if (CONSP (tem))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1047 return XCAR (tem);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 /* This is The Way It Has Always Been. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 #else
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1053 /* This is The Way Mly and Cltl2 say It Should Be. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1054 args_out_of_range (sequence, n);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1057 else if (STRINGP (sequence) ||
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1058 VECTORP (sequence) ||
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1059 BIT_VECTORP (sequence))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1060 return Faref (sequence, n);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 #ifdef LOSING_BYTECODE
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1062 else if (COMPILED_FUNCTIONP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1064 EMACS_INT idx = XINT (n);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 if (idx < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 lose:
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1068 args_out_of_range (sequence, n);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 /* Utter perversity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1072 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 switch (idx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 case COMPILED_ARGLIST:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1076 return compiled_function_arglist (f);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1077 case COMPILED_INSTRUCTIONS:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1078 return compiled_function_instructions (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 case COMPILED_CONSTANTS:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1080 return compiled_function_constants (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 case COMPILED_STACK_DEPTH:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1082 return compiled_function_stack_depth (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 case COMPILED_DOC_STRING:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1084 return compiled_function_documentation (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 case COMPILED_DOMAIN:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1086 return compiled_function_domain (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 case COMPILED_INTERACTIVE:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1088 if (f->flags.interactivep)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1089 return compiled_function_interactive (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 /* if we return nil, can't tell interactive with no args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 from noninteractive. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 #endif /* LOSING_BYTECODE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1101 check_losing_bytecode ("elt", sequence);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1102 sequence = wrong_type_argument (Qsequencep, sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1107 DEFUN ("last", Flast, 1, 2, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1108 Return the tail of list LIST, of length N (default 1).
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1109 LIST may be a dotted list, but not a circular list.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1110 Optional argument N must be a non-negative integer.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1111 If N is zero, then the atom that terminates the list is returned.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1112 If N is greater than the length of LIST, then LIST itself is returned.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1113 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1114 (list, n))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1115 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1116 EMACS_INT int_n, count;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1117 Lisp_Object retval, tortoise, hare;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1118
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1119 CHECK_LIST (list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1120
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1121 if (NILP (n))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1122 int_n = 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1123 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1124 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1125 CHECK_NATNUM (n);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1126 int_n = XINT (n);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1127 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1128
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1129 for (retval = tortoise = hare = list, count = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1130 CONSP (hare);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1131 hare = XCDR (hare),
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1132 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0),
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1133 count++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1134 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1135 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1136
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1137 if (count & 1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1138 tortoise = XCDR (tortoise);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1139 if (EQ (hare, tortoise))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1140 signal_circular_list_error (list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1141 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1142
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1143 return retval;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1144 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1145
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1146 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1147 Modify LIST to remove the last N (default 1) elements.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1148 If LIST has N or fewer elements, nil is returned and LIST is unmodified.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1149 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1150 (list, n))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1151 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1152 EMACS_INT int_n;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1153
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1154 CHECK_LIST (list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1155
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1156 if (NILP (n))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1157 int_n = 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1158 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1159 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1160 CHECK_NATNUM (n);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1161 int_n = XINT (n);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1162 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1163
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1164 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1165 Lisp_Object last_cons = list;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1166
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1167 EXTERNAL_LIST_LOOP_1 (list)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1168 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1169 if (int_n-- < 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1170 last_cons = XCDR (last_cons);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1171 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1172
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1173 if (int_n >= 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1174 return Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1175
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1176 XCDR (last_cons) = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1177 return list;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1178 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1179 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1180
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1181 DEFUN ("butlast", Fbutlast, 1, 2, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1182 Return a copy of LIST with the last N (default 1) elements removed.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1183 If LIST has N or fewer elements, nil is returned.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1184 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1185 (list, n))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1186 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1187 int int_n;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1188
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1189 CHECK_LIST (list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1190
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1191 if (NILP (n))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1192 int_n = 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1193 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1194 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1195 CHECK_NATNUM (n);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1196 int_n = XINT (n);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1197 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1198
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1199 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1200 Lisp_Object retval = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1201 Lisp_Object tail = list;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1202
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1203 EXTERNAL_LIST_LOOP_1 (list)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1204 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1205 if (--int_n < 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1206 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1207 retval = Fcons (XCAR (tail), retval);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1208 tail = XCDR (tail);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1209 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1210 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1211
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1212 return Fnreverse (retval);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1213 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1214 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1215
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1216 DEFUN ("member", Fmember, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 The value is actually the tail of LIST whose car is ELT.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1219 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1220 (elt, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1222 Lisp_Object list_elt, tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1223 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1225 if (internal_equal (elt, list_elt, 0))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1226 return tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1231 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1232 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1233 The value is actually the tail of LIST whose car is ELT.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1234 This function is provided only for byte-code compatibility with v19.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1235 Do not use it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1236 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1237 (elt, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1238 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1239 Lisp_Object list_elt, tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1240 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1241 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1242 if (internal_old_equal (elt, list_elt, 0))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1243 return tail;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1244 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1245 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1246 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1247
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1248 DEFUN ("memq", Fmemq, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 The value is actually the tail of LIST whose car is ELT.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1251 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1252 (elt, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1254 Lisp_Object list_elt, tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1255 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1257 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1258 return tail;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1259 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1260 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1261 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1262
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1263 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1264 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1265 The value is actually the tail of LIST whose car is ELT.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1266 This function is provided only for byte-code compatibility with v19.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1267 Do not use it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1268 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1269 (elt, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1270 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1271 Lisp_Object list_elt, tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1272 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1273 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1274 if (HACKEQ_UNSAFE (elt, list_elt))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1275 return tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 memq_no_quit (Lisp_Object elt, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1283 Lisp_Object list_elt, tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1284 LIST_LOOP_3 (list_elt, list, tail)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1286 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1287 return tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1292 DEFUN ("assoc", Fassoc, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 Return non-nil if KEY is `equal' to the car of an element of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 The value is actually the element of LIST whose car equals KEY.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1295 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1296 (key, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 /* This function can GC. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1299 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1300 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1302 if (internal_equal (key, elt_car, 0))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1303 return elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1308 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1309 Return non-nil if KEY is `old-equal' to the car of an element of LIST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1310 The value is actually the element of LIST whose car equals KEY.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1311 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1312 (key, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1313 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1314 /* This function can GC. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1315 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1316 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1317 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1318 if (internal_old_equal (key, elt_car, 0))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1319 return elt;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1320 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1321 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1322 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1323
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 assoc_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 specbind (Qinhibit_quit, Qt);
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
1329 return unbind_to (speccount, Fassoc (key, list));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1332 DEFUN ("assq", Fassq, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 Return non-nil if KEY is `eq' to the car of an element of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 The value is actually the element of LIST whose car is KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 Elements of LIST that are not conses are ignored.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1336 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1337 (key, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1339 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1340 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1342 if (EQ_WITH_EBOLA_NOTICE (key, elt_car))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1343 return elt;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1344 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1345 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1346 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1347
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1348 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1349 Return non-nil if KEY is `old-eq' to the car of an element of LIST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1350 The value is actually the element of LIST whose car is KEY.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1351 Elements of LIST that are not conses are ignored.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1352 This function is provided only for byte-code compatibility with v19.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1353 Do not use it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1354 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1355 (key, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1356 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1357 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1358 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1359 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1360 if (HACKEQ_UNSAFE (key, elt_car))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1361 return elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 /* Like Fassq but never report an error and do not allow quits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 Use only on lists known never to be circular. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 assq_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 /* This cannot GC. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1373 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1374 LIST_LOOP_2 (elt, list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1376 Lisp_Object elt_car = XCAR (elt);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1377 if (EQ_WITH_EBOLA_NOTICE (key, elt_car))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1378 return elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1383 DEFUN ("rassoc", Frassoc, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 Return non-nil if KEY is `equal' to the cdr of an element of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 The value is actually the element of LIST whose cdr equals KEY.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1386 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1387 (key, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1389 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1390 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1392 if (internal_equal (key, elt_cdr, 0))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1393 return elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1398 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1399 Return non-nil if KEY is `old-equal' to the cdr of an element of LIST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1400 The value is actually the element of LIST whose cdr equals KEY.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1401 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1402 (key, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1403 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1404 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1405 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1406 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1407 if (internal_old_equal (key, elt_cdr, 0))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1408 return elt;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1409 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1410 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1411 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1412
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1413 DEFUN ("rassq", Frassq, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 Return non-nil if KEY is `eq' to the cdr of an element of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 The value is actually the element of LIST whose cdr is KEY.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1416 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1417 (key, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1419 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1420 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1422 if (EQ_WITH_EBOLA_NOTICE (key, elt_cdr))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1423 return elt;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1424 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1425 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1426 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1427
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1428 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1429 Return non-nil if KEY is `old-eq' to the cdr of an element of LIST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1430 The value is actually the element of LIST whose cdr is KEY.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1431 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1432 (key, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1433 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1434 Lisp_Object elt, elt_car, elt_cdr;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1435 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, list)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1436 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1437 if (HACKEQ_UNSAFE (key, elt_cdr))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
1438 return elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1443 /* Like Frassq, but caller must ensure that LIST is properly
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1444 nil-terminated and ebola-free. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 rassq_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1448 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1449 LIST_LOOP_2 (elt, list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1451 Lisp_Object elt_cdr = XCDR (elt);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1452 if (EQ_WITH_EBOLA_NOTICE (key, elt_cdr))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1453 return elt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1459 DEFUN ("delete", Fdelete, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 Delete by side effect any occurrences of ELT as a member of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 The modified LIST is returned. Comparison is done with `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 If the first member of LIST is ELT, there is no way to remove it by side
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 effect; therefore, write `(setq foo (delete element foo))' to be sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 of changing the value of `foo'.
201
eb5470882647 Import from CVS: tag r20-3b27
cvs
parents: 195
diff changeset
1465 Also see: `remove'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1466 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1467 (elt, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1469 Lisp_Object list_elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1470 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1471 (internal_equal (elt, list_elt, 0)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1475 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1476 Delete by side effect any occurrences of ELT as a member of LIST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1477 The modified LIST is returned. Comparison is done with `old-equal'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1478 If the first member of LIST is ELT, there is no way to remove it by side
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1479 effect; therefore, write `(setq foo (old-delete element foo))' to be sure
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1480 of changing the value of `foo'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1481 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1482 (elt, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1483 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1484 Lisp_Object list_elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1485 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1486 (internal_old_equal (elt, list_elt, 0)));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1487 return list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1488 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1489
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1490 DEFUN ("delq", Fdelq, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 Delete by side effect any occurrences of ELT as a member of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 The modified LIST is returned. Comparison is done with `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 If the first member of LIST is ELT, there is no way to remove it by side
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 effect; therefore, write `(setq foo (delq element foo))' to be sure of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 changing the value of `foo'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1496 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1497 (elt, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1499 Lisp_Object list_elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1500 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1501 (EQ_WITH_EBOLA_NOTICE (elt, list_elt)));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1502 return list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1503 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1504
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1505 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1506 Delete by side effect any occurrences of ELT as a member of LIST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1507 The modified LIST is returned. Comparison is done with `old-eq'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1508 If the first member of LIST is ELT, there is no way to remove it by side
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1509 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1510 changing the value of `foo'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1511 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1512 (elt, list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
1513 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1514 Lisp_Object list_elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1515 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1516 (HACKEQ_UNSAFE (elt, list_elt)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1520 /* Like Fdelq, but caller must ensure that LIST is properly
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1521 nil-terminated and ebola-free. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 delq_no_quit (Lisp_Object elt, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1526 Lisp_Object list_elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1527 LIST_LOOP_DELETE_IF (list_elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1528 (EQ_WITH_EBOLA_NOTICE (elt, list_elt)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 /* Be VERY careful with this. This is like delq_no_quit() but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 also calls free_cons() on the removed conses. You must be SURE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 that no pointers to the freed conses remain around (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 someone else is pointing to part of the list). This function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 is useful on internal lists that are used frequently and where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 the actual list doesn't escape beyond known code bounds. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1542 REGISTER Lisp_Object tail = list;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1543 REGISTER Lisp_Object prev = Qnil;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1544
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1545 while (!NILP (tail))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1547 REGISTER Lisp_Object tem = XCAR (tail);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1548 if (EQ (elt, tem))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1550 Lisp_Object cons_to_free = tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 list = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 XCDR (prev) = XCDR (tail);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1555 tail = XCDR (tail);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1556 free_cons (XCONS (cons_to_free));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1559 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1560 prev = tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1561 tail = XCDR (tail);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1562 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1567 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 Delete by side effect any elements of LIST whose car is `equal' to KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 The modified LIST is returned. If the first member of LIST has a car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 that is `equal' to KEY, there is no way to remove it by side effect;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 therefore, write `(setq foo (remassoc key foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 the value of `foo'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1573 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1574 (key, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1576 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1577 EXTERNAL_LIST_LOOP_DELETE_IF (elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1578 (CONSP (elt) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1579 internal_equal (key, XCAR (elt), 0)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 remassoc_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 specbind (Qinhibit_quit, Qt);
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
1588 return unbind_to (speccount, Fremassoc (key, list));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1591 DEFUN ("remassq", Fremassq, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 Delete by side effect any elements of LIST whose car is `eq' to KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 The modified LIST is returned. If the first member of LIST has a car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 that is `eq' to KEY, there is no way to remove it by side effect;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 therefore, write `(setq foo (remassq key foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 the value of `foo'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1597 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1598 (key, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1600 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1601 EXTERNAL_LIST_LOOP_DELETE_IF (elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1602 (CONSP (elt) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1603 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 /* no quit, no errors; be careful */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 remassq_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1612 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1613 LIST_LOOP_DELETE_IF (elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1614 (CONSP (elt) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1615 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1619 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 Delete by side effect any elements of LIST whose cdr is `equal' to VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 The modified LIST is returned. If the first member of LIST has a car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 that is `equal' to VALUE, there is no way to remove it by side effect;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 the value of `foo'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1625 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1626 (value, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1628 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1629 EXTERNAL_LIST_LOOP_DELETE_IF (elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1630 (CONSP (elt) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1631 internal_equal (value, XCDR (elt), 0)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1635 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 Delete by side effect any elements of LIST whose cdr is `eq' to VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 The modified LIST is returned. If the first member of LIST has a car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 that is `eq' to VALUE, there is no way to remove it by side effect;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 therefore, write `(setq foo (remrassq value foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 the value of `foo'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1641 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1642 (value, list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1644 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1645 EXTERNAL_LIST_LOOP_DELETE_IF (elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1646 (CONSP (elt) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1647 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1651 /* Like Fremrassq, fast and unsafe; be careful */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 remrassq_no_quit (Lisp_Object value, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1655 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1656 LIST_LOOP_DELETE_IF (elt, list,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1657 (CONSP (elt) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1658 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1662 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1663 Reverse LIST by destructively modifying cdr pointers.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1664 Return the beginning of the reversed list.
201
eb5470882647 Import from CVS: tag r20-3b27
cvs
parents: 195
diff changeset
1665 Also see: `reverse'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1666 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1667 (list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 struct gcpro gcpro1, gcpro2;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1670 REGISTER Lisp_Object prev = Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1671 REGISTER Lisp_Object tail = list;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 /* We gcpro our args; see `nconc' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 GCPRO2 (prev, tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1677 REGISTER Lisp_Object next;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1678 CONCHECK_CONS (tail);
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1679 next = XCDR (tail);
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1680 XCDR (tail) = prev;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 tail = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 return prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1688 DEFUN ("reverse", Freverse, 1, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1689 Reverse LIST, copying. Return the beginning of the reversed list.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 See also the function `nreverse', which is used more often.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1691 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1692 (list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1694 Lisp_Object reversed_list = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1695 Lisp_Object elt;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1696 EXTERNAL_LIST_LOOP_2 (elt, list)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1697 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1698 reversed_list = Fcons (elt, reversed_list);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1699 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1700 return reversed_list;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1703 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1704 Lisp_Object lisp_arg,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 int (*pred_fn) (Lisp_Object, Lisp_Object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 Lisp_Object lisp_arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 list_sort (Lisp_Object list,
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1710 Lisp_Object lisp_arg,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 int (*pred_fn) (Lisp_Object, Lisp_Object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 Lisp_Object lisp_arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 struct gcpro gcpro1, gcpro2, gcpro3;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1715 Lisp_Object back, tem;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1716 Lisp_Object front = list;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1717 Lisp_Object len = Flength (list);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1718 int length = XINT (len);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
1719
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 if (length < 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 XSETINT (len, (length / 2) - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 tem = Fnthcdr (len, list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 back = Fcdr (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 Fsetcdr (tem, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 GCPRO3 (front, back, lisp_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 front = list_sort (front, lisp_arg, pred_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 back = list_sort (back, lisp_arg, pred_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 return list_merge (front, back, lisp_arg, pred_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 static int
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1737 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 Lisp_Object pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 Lisp_Object tmp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 /* prevents the GC from happening in call2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 /* Emacs' GC doesn't actually relocate pointers, so this probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 isn't strictly necessary */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 record_unwind_protect (restore_gc_inhibit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 make_int (gc_currently_forbidden));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 gc_currently_forbidden = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 tmp = call2 (pred, obj1, obj2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1752 if (NILP (tmp))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1758 DEFUN ("sort", Fsort, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 Sort LIST, stably, comparing elements using PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 Returns the sorted list. LIST is modified by side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 PREDICATE is called with two elements of LIST, and should return T
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
1762 if the first element is "less" than the second.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1763 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1764 (list, pred))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 return list_sort (list, pred, merge_pred_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 Lisp_Object
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1770 merge (Lisp_Object org_l1, Lisp_Object org_l2,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 Lisp_Object pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 return list_merge (org_l1, org_l2, pred, merge_pred_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 static Lisp_Object
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1778 list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1779 Lisp_Object lisp_arg,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 Lisp_Object value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 Lisp_Object l1, l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 l1 = org_l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 l2 = org_l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 value = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 /* It is sufficient to protect org_l1 and org_l2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 When l1 and l2 are updated, we copy the new values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 back into the org_ vars. */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1796
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 GCPRO4 (org_l1, org_l2, lisp_arg, value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 if (NILP (l1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 return l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 Fsetcdr (tail, l2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 if (NILP (l2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 return l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 Fsetcdr (tail, l1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 tem = l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 l1 = Fcdr (l1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 org_l1 = l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 tem = l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 l2 = Fcdr (l2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 org_l2 = l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 value = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 Fsetcdr (tail, tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 tail = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 /* property-list functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 /* For properties of text, we need to do order-insensitive comparison of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 plists. That is, we need to compare two plists such that they are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 same if they have the same set of keys, and equivalent values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 So (a 1 b 2) would be equal to (b 2 a 1).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 LAXP means use `equal' for comparisons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1851 int
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 int laxp, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1855 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 int la, lb, m, i, fill;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 Lisp_Object *keys, *vals;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 char *flags;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 if (NILP (a) && NILP (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 Fcheck_valid_plist (a);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 Fcheck_valid_plist (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 la = XINT (Flength (a));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 lb = XINT (Flength (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 m = (la > lb ? la : lb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 fill = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
1871 keys = alloca_array (Lisp_Object, m);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
1872 vals = alloca_array (Lisp_Object, m);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
1873 flags = alloca_array (char, m);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 /* First extract the pairs from A. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 Lisp_Object k = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 Lisp_Object v = XCAR (XCDR (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 /* Maybe be Ebolified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 if (nil_means_not_present && NILP (v)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 keys [fill] = k;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 vals [fill] = v;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 flags[fill] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 fill++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 /* Now iterate over B, and stop if we find something that's not in A,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 or that doesn't match. As we match, mark them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 Lisp_Object k = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 Lisp_Object v = XCAR (XCDR (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 /* Maybe be Ebolified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 if (nil_means_not_present && NILP (v)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 for (i = 0; i < fill; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 if (!laxp ? EQ (k, keys [i]) : internal_equal (k, keys [i], depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1899 if (eqp
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1900 /* We narrowly escaped being Ebolified here. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1901 ? !EQ_WITH_EBOLA_NOTICE (v, vals [i])
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1902 : !internal_equal (v, vals [i], depth))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 /* a property in B has a different value than in A */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 goto MISMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 flags [i] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 if (i == fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 /* there are some properties in B that are not in A */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 goto MISMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 /* Now check to see that all the properties in A were also in B */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 for (i = 0; i < fill; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 if (flags [i] == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 goto MISMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 /* Ok. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 MISMATCH:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1925 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 Return non-nil if property lists A and B are `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 A property list is an alternating list of keywords and values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 This function does order-insensitive comparisons of the property lists:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 Comparison between values is done using `eq'. See also `plists-equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 a nil value is ignored. This feature is a virus that has infected
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1933 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1934 compatibility.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1935 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1936 (a, b, nil_means_not_present))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1942 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 Return non-nil if property lists A and B are `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 A property list is an alternating list of keywords and values. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 function does order-insensitive comparisons of the property lists: For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 Comparison between values is done using `equal'. See also `plists-eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 a nil value is ignored. This feature is a virus that has infected
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1950 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1951 compatibility.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1952 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1953 (a, b, nil_means_not_present))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1960 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 Return non-nil if lax property lists A and B are `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 A property list is an alternating list of keywords and values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 This function does order-insensitive comparisons of the property lists:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 Comparison between values is done using `eq'. See also `plists-equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 A lax property list is like a regular one except that comparisons between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 keywords is done using `equal' instead of `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 a nil value is ignored. This feature is a virus that has infected
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1970 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1971 compatibility.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1972 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1973 (a, b, nil_means_not_present))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1979 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 Return non-nil if lax property lists A and B are `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 A property list is an alternating list of keywords and values. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 function does order-insensitive comparisons of the property lists: For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 Comparison between values is done using `equal'. See also `plists-eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 A lax property list is like a regular one except that comparisons between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 keywords is done using `equal' instead of `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 a nil value is ignored. This feature is a virus that has infected
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1989 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1990 compatibility.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1991 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1992 (a, b, nil_means_not_present))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 /* Return the value associated with key PROPERTY in property list PLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 Return nil if key not found. This function is used for internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 property lists that cannot be directly manipulated by the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 internal_plist_get (Lisp_Object plist, Lisp_Object property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2006 Lisp_Object tail;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2007
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2008 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2010 if (EQ (XCAR (tail), property))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2011 return XCAR (XCDR (tail));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 /* Set PLIST's value for PROPERTY to VALUE. Analogous to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 internal_plist_get(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 internal_plist_put (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 Lisp_Object value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2024 Lisp_Object tail;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2025
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2026 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2028 if (EQ (XCAR (tail), property))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2030 XCAR (XCDR (tail)) = value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 *plist = Fcons (property, Fcons (value, *plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 internal_remprop (Lisp_Object *plist, Lisp_Object property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2041 Lisp_Object tail, prev;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2042
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2043 for (tail = *plist, prev = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2044 !NILP (tail);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 tail = XCDR (XCDR (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2047 if (EQ (XCAR (tail), property))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2049 if (NILP (prev))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2050 *plist = XCDR (XCDR (tail));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2051 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2052 XCDR (XCDR (prev)) = XCDR (XCDR (tail));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2055 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2056 prev = tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 /* Called on a malformed property list. BADPLACE should be some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 place where truncating will form a good list -- i.e. we shouldn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 result in a list with an odd length. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 if (ERRB_EQ (errb, ERROR_ME))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 if (ERRB_EQ (errb, ERROR_ME_WARN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 warn_when_safe_lispobj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (Qlist, Qwarning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 list2 (build_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 ("Malformed property list -- list has been truncated"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 *plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 *badplace = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 /* Called on a circular property list. BADPLACE should be some place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 where truncating will result in an even-length list, as above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 If doesn't particularly matter where we truncate -- anywhere we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 truncate along the entire list will break the circularity, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 it will create a terminus and the list currently doesn't have one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 if (ERRB_EQ (errb, ERROR_ME))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 /* #### Eek, this will probably result in another error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 when PLIST is printed out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 return Fsignal (Qcircular_property_list, list1 (*plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 if (ERRB_EQ (errb, ERROR_ME_WARN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 warn_when_safe_lispobj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (Qlist, Qwarning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 list2 (build_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 ("Circular property list -- list has been truncated"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 *plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 *badplace = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 /* Advance the tortoise pointer by two (one iteration of a property-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 loop) and the hare pointer by four and verify that no malformations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 or circularities exist. If so, return zero and store a value into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 RETVAL that should be returned by the calling function. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 return 1. See external_plist_get().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 advance_plist_pointers (Lisp_Object *plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 Lisp_Object **tortoise, Lisp_Object **hare,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 Error_behavior errb, Lisp_Object *retval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 Lisp_Object *tortsave = *tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 /* Note that our "fixing" may be more brutal than necessary,
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2131 but it's the user's own problem, not ours, if they went in and
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 manually fucked up a plist. */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2133
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 for (i = 0; i < 2; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 /* This is a standard iteration of a defensive-loop-checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 loop. We just do it twice because we want to advance past
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 both the property and its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 If the pointer indirection is confusing you, remember that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 one level of indirection on the hare and tortoise pointers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 is only due to pass-by-reference for this function. The other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 level is so that the plist can be fixed in place. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 /* When we reach the end of a well-formed plist, **HARE is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 nil. In that case, we don't do anything at all except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 advance TORTOISE by one. Otherwise, we advance HARE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 by two (making sure it's OK to do so), then advance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 TORTOISE by one (it will always be OK to do so because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 the HARE is always ahead of the TORTOISE and will have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 already verified the path), then make sure TORTOISE and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 HARE don't contain the same non-nil object -- if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 TORTOISE and the HARE ever meet, then obviously we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 in a circularity, and if we're in a circularity, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 the TORTOISE and the HARE can't cross paths without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 meeting, since the HARE only gains one step over the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 TORTOISE per iteration. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 if (!NILP (**hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 Lisp_Object *haresave = *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 if (!CONSP (**hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 *retval = bad_bad_bunny (plist, haresave, errb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 *hare = &XCDR (**hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 /* In a non-plist, we'd check here for a nil value for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 **HARE, which is OK (it just means the list has an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 odd number of elements). In a plist, it's not OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 for the list to have an odd number of elements. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 if (!CONSP (**hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 *retval = bad_bad_bunny (plist, haresave, errb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 *hare = &XCDR (**hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 *tortoise = &XCDR (**tortoise);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 if (!NILP (**hare) && EQ (**tortoise, **hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 *retval = bad_bad_turtle (plist, tortsave, errb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 /* Return the value of PROPERTY from PLIST, or Qunbound if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 property is not on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 PLIST is a Lisp-accessible property list, meaning that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 has to be checked for malformations and circularities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 function will never signal an error; and if ERRB is ERROR_ME_WARN,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 on finding a malformation or a circularity, it issues a warning and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 attempts to silently fix the problem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 A pointer to PLIST is passed in so that PLIST can be successfully
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 "fixed" even if the error is at the beginning of the plist. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 external_plist_get (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 int laxp, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 Lisp_Object *tortoise = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 Lisp_Object *hare = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 Lisp_Object *tortsave = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 /* We do the standard tortoise/hare march. We isolate the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 grungy stuff to do this in advance_plist_pointers(), though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 To us, all this function does is advance the tortoise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 pointer by two and the hare pointer by four and make sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 everything's OK. We first advance the pointers and then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 check if a property matched; this ensures that our
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 check for a matching property is safe. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 return retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 if (!laxp ? EQ (XCAR (*tortsave), property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 : internal_equal (XCAR (*tortsave), property, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 return XCAR (XCDR (*tortsave));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 /* Set PLIST's value for PROPERTY to VALUE, given a possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 malformed or circular plist. Analogous to external_plist_get(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 external_plist_put (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 Lisp_Object value, int laxp, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 Lisp_Object *tortoise = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 Lisp_Object *hare = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 Lisp_Object *tortsave = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 if (!laxp ? EQ (XCAR (*tortsave), property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 : internal_equal (XCAR (*tortsave), property, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 XCAR (XCDR (*tortsave)) = value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 *plist = Fcons (property, Fcons (value, *plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 external_remprop (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 int laxp, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 Lisp_Object *tortoise = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 Lisp_Object *hare = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 Lisp_Object *tortsave = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 if (!laxp ? EQ (XCAR (*tortsave), property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 : internal_equal (XCAR (*tortsave), property, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 /* Now you see why it's so convenient to have that level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 of indirection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 *tortsave = XCDR (XCDR (*tortsave));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2295 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 Extract a value from a property list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 PLIST is a property list, which is a list of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 corresponding to the given PROP, or DEFAULT if PROP is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 one of the properties on the list.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2301 */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2302 (plist, prop, default_))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 Lisp_Object val = external_plist_get (&plist, prop, 0, ERROR_ME);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2305 return UNBOUNDP (val) ? default_ : val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2308 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 Change value in PLIST of PROP to VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 PROP2 VALUE2 ...). PROP is usually a symbol and VAL is any object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 If PROP is already a property on the list, its value is set to VAL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 otherwise the new PROP VAL pair is added. The new plist is returned;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 use `(setq x (plist-put x prop val))' to be sure to use the new value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 The PLIST is modified by side effects.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2316 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2317 (plist, prop, val))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 external_plist_put (&plist, prop, val, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 return plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2323 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 Remove from PLIST the property PROP and its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 PLIST is a property list, which is a list of the form \(PROP1 VALUE1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 PROP2 VALUE2 ...). PROP is usually a symbol. The new plist is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 returned; use `(setq x (plist-remprop x prop val))' to be sure to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 the new value. The PLIST is modified by side effects.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2329 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2330 (plist, prop))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 external_remprop (&plist, prop, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 return plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2336 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 Return t if PROP has a value specified in PLIST.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2338 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2339 (plist, prop))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2341 Lisp_Object val = Fplist_get (plist, prop, Qunbound);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2342 return UNBOUNDP (val) ? Qnil : Qt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2345 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 Given a plist, signal an error if there is anything wrong with it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 This means that it's a malformed or circular plist.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2348 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2349 (plist))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 Lisp_Object *tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 Lisp_Object *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 start_over:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 tortoise = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 hare = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 goto start_over;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2369
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2370 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 Given a plist, return non-nil if its format is correct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 If it returns nil, `check-valid-plist' will signal an error when given
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2373 the plist; that means it's a malformed or circular plist.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2374 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2375 (plist))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 Lisp_Object *tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 Lisp_Object *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 tortoise = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 hare = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2395 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 Destructively remove any duplicate entries from a plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 In such cases, the first entry applies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 a nil value is removed. This feature is a virus that has infected
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2401 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2402 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 return value may not be EQ to the passed-in value, so make sure to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 `setq' the value back into where it came from.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2407 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2408 (plist, nil_means_not_present))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 Lisp_Object head = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 Fcheck_valid_plist (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 while (!NILP (plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 Lisp_Object prop = Fcar (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 Lisp_Object next = Fcdr (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 CHECK_CONS (next); /* just make doubly sure we catch any errors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 if (EQ (head, plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 head = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 /* external_remprop returns 1 if it removed any property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 We have to loop till it didn't remove anything, in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 the property occurs many times. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2430 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2431 DO_NOTHING;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2438 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 Extract a value from a lax property list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2442 VALUE1 PROP2 VALUE2...), where comparisons between properties is done
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 using `equal' instead of `eq'. This function returns the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 corresponding to the given PROP, or DEFAULT if PROP is not one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 properties on the list.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2446 */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2447 (lax_plist, prop, default_))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 Lisp_Object val = external_plist_get (&lax_plist, prop, 1, ERROR_ME);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2450 return UNBOUNDP (val) ? default_ : val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2453 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 Change value in LAX-PLIST of PROP to VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2456 VALUE1 PROP2 VALUE2...), where comparisons between properties is done
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 using `equal' instead of `eq'. PROP is usually a symbol and VAL is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 any object. If PROP is already a property on the list, its value is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 set to VAL, otherwise the new PROP VAL pair is added. The new plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 is returned; use `(setq x (lax-plist-put x prop val))' to be sure to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 use the new value. The LAX-PLIST is modified by side effects.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2462 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2463 (lax_plist, prop, val))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 external_plist_put (&lax_plist, prop, val, 1, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 return lax_plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2469 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 Remove from LAX-PLIST the property PROP and its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2472 VALUE1 PROP2 VALUE2...), where comparisons between properties is done
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 using `equal' instead of `eq'. PROP is usually a symbol. The new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 plist is returned; use `(setq x (lax-plist-remprop x prop val))' to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 sure to use the new value. The LAX-PLIST is modified by side effects.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2476 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2477 (lax_plist, prop))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 external_remprop (&lax_plist, prop, 1, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 return lax_plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2483 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 Return t if PROP has a value specified in LAX-PLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2486 VALUE1 PROP2 VALUE2...), where comparisons between properties is done
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 using `equal' instead of `eq'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2488 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2489 (lax_plist, prop))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 return UNBOUNDP (Flax_plist_get (lax_plist, prop, Qunbound)) ? Qnil : Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2494 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 Destructively remove any duplicate entries from a lax plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 In such cases, the first entry applies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 a nil value is removed. This feature is a virus that has infected
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2500 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2501 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 return value may not be EQ to the passed-in value, so make sure to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 `setq' the value back into where it came from.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2506 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2507 (lax_plist, nil_means_not_present))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 Lisp_Object head = lax_plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 Fcheck_valid_plist (lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 while (!NILP (lax_plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 Lisp_Object prop = Fcar (lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 Lisp_Object next = Fcdr (lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 CHECK_CONS (next); /* just make doubly sure we catch any errors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 if (EQ (head, lax_plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 head = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 lax_plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 /* external_remprop returns 1 if it removed any property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 We have to loop till it didn't remove anything, in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 the property occurs many times. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2529 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2530 DO_NOTHING;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 lax_plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 /* In C because the frame props stuff uses it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2539 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 Convert association list ALIST into the equivalent property-list form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 The plist is returned. This converts from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 \((a . 1) (b . 2) (c . 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 \(a 1 b 2 c 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 The original alist is destroyed in the process of constructing the plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 See also `alist-to-plist'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2551 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2552 (alist))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 Lisp_Object head = alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 while (!NILP (alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 /* remember the alist element. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 Lisp_Object el = Fcar (alist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 Fsetcar (alist, Fcar (el));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 Fsetcar (el, Fcdr (el));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 Fsetcdr (el, Fcdr (alist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 Fsetcdr (alist, el);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 alist = Fcdr (Fcdr (alist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2570 DEFUN ("get", Fget, 2, 3, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2571 Return the value of OBJECT's PROPERTY property.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2572 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 If there is no such property, return optional third arg DEFAULT
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2574 \(which defaults to `nil'). OBJECT can be a symbol, string, extent,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2575 face, or glyph. See also `put', `remprop', and `object-plist'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2576 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2577 (object, property, default_))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 /* Various places in emacs call Fget() and expect it not to quit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 so don't quit. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2581 Lisp_Object val;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2582
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2583 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2584 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2586 signal_simple_error ("Object type has no properties", object);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2587
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2588 return UNBOUNDP (val) ? default_ : val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2591 DEFUN ("put", Fput, 3, 3, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2592 Set OBJECT's PROPERTY to VALUE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2593 It can be subsequently retrieved with `(get OBJECT PROPERTY)'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2594 OBJECT can be a symbol, face, extent, or string.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 For a string, no properties currently have predefined meanings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 For the predefined properties for extents, see `set-extent-property'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 For the predefined properties for faces, see `set-face-property'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 See also `get', `remprop', and `object-plist'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2599 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2600 (object, property, value))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2602 CHECK_LISP_WRITEABLE (object);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2603
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2604 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2606 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2607 (object, property, value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2608 signal_simple_error ("Can't set property on object", property);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2611 signal_simple_error ("Object type has no settable properties", object);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2616 DEFUN ("remprop", Fremprop, 2, 2, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2617 Remove, from OBJECT's property list, PROPERTY and its corresponding value.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2618 OBJECT can be a symbol, string, extent, face, or glyph. Return non-nil
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2619 if the property list was actually modified (i.e. if PROPERTY was present
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2620 in the property list). See also `get', `put', and `object-plist'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2621 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2622 (object, property))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2624 int ret = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2625
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2626 CHECK_LISP_WRITEABLE (object);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2627
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2628 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2630 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2631 if (ret == -1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2632 signal_simple_error ("Can't remove property from object", property);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2635 signal_simple_error ("Object type has no removable properties", object);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2636
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2637 return ret ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2640 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2641 Return a property list of OBJECT's properties.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2642 For a symbol, this is equivalent to `symbol-plist'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2643 OBJECT can be a symbol, string, extent, face, or glyph.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2644 Do not modify the returned property list directly;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2645 this may or may not have the desired effects. Use `put' instead.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2646 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2647 (object))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2649 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2650 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 signal_simple_error ("Object type has no properties", object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2659 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 if (depth > 200)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 error ("Stack overflow in equal");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 QUIT;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2664 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
2665 return 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 /* Note that (equal 20 20.0) should be nil */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2667 if (XTYPE (obj1) != XTYPE (obj2))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
2668 return 0;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2669 if (LRECORDP (obj1))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2671 const struct lrecord_implementation
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2672 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1),
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2673 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2674
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2675 return (imp1 == imp2) &&
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 /* EQ-ness of the objects was noticed above */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2677 (imp1->equal && (imp1->equal) (obj1, obj2, depth));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
2680 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2683 /* Note that we may be calling sub-objects that will use
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2684 internal_equal() (instead of internal_old_equal()). Oh well.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2685 We will get an Ebola note if there's any possibility of confusion,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2686 but that seems unlikely. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2687
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2688 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2689 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2690 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2691 if (depth > 200)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2692 error ("Stack overflow in equal");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2693 QUIT;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2694 if (HACKEQ_UNSAFE (obj1, obj2))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
2695 return 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2696 /* Note that (equal 20 20.0) should be nil */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2697 if (XTYPE (obj1) != XTYPE (obj2))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
2698 return 0;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2699
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2700 return internal_equal (obj1, obj2, depth);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2701 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2702
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2703 DEFUN ("equal", Fequal, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2704 Return t if two Lisp objects have similar structure and contents.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 They must have the same data type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 Conses are compared by comparing the cars and the cdrs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 Vectors and strings are compared element by element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 Numbers are compared by value. Symbols must match exactly.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2709 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2710 (obj1, obj2))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2712 return internal_equal (obj1, obj2, 0) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2715 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2716 Return t if two Lisp objects have similar structure and contents.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2717 They must have the same data type.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2718 \(Note, however, that an exception is made for characters and integers;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
2719 this is known as the "char-int confoundance disease." See `eq' and
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2720 `old-eq'.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2721 This function is provided only for byte-code compatibility with v19.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2722 Do not use it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2723 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2724 (obj1, obj2))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2725 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2726 return internal_old_equal (obj1, obj2, 0) ? Qt : Qnil;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2727 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
2728
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2730 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2731 Destructively modify ARRAY by replacing each element with ITEM.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 ARRAY is a vector, bit vector, or string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2733 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2734 (array, item))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 retry:
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2737 if (STRINGP (array))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2738 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2739 Lisp_String *s = XSTRING (array);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2740 Bytecount old_bytecount = string_length (s);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2741 Bytecount new_bytecount;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2742 Bytecount item_bytecount;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2743 Bufbyte item_buf[MAX_EMCHAR_LEN];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2744 Bufbyte *p;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2745 Bufbyte *end;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2746
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2747 CHECK_CHAR_COERCE_INT (item);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2748 CHECK_LISP_WRITEABLE (array);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2749
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2750 item_bytecount = set_charptr_emchar (item_buf, XCHAR (item));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2751 new_bytecount = item_bytecount * string_char_length (s);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2752
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2753 resize_string (s, -1, new_bytecount - old_bytecount);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2754
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2755 for (p = string_data (s), end = p + new_bytecount;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2756 p < end;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2757 p += item_bytecount)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2758 memcpy (p, item_buf, item_bytecount);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2759 *p = '\0';
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2760
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2761 bump_string_modiff (array);
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2762 }
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2763 else if (VECTORP (array))
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2764 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2765 Lisp_Object *p = XVECTOR_DATA (array);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2766 int len = XVECTOR_LENGTH (array);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2767 CHECK_LISP_WRITEABLE (array);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2768 while (len--)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2769 *p++ = item;
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2770 }
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
2771 else if (BIT_VECTORP (array))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2773 Lisp_Bit_Vector *v = XBIT_VECTOR (array);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2774 int len = bit_vector_length (v);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2775 int bit;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 CHECK_BIT (item);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2777 CHECK_LISP_WRITEABLE (array);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2778 bit = XINT (item);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2779 while (len--)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2780 set_bit_vector_bit (v, len, bit);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 array = wrong_type_argument (Qarrayp, array);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 return array;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 Lisp_Object
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2791 nconc2 (Lisp_Object arg1, Lisp_Object arg2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 Lisp_Object args[2];
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2794 struct gcpro gcpro1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2795 args[0] = arg1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2796 args[1] = arg2;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2797
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2798 GCPRO1 (args[0]);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2799 gcpro1.nvars = 2;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2800
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2801 RETURN_UNGCPRO (bytecode_nconc2 (args));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2802 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2803
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2804 Lisp_Object
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2805 bytecode_nconc2 (Lisp_Object *args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2806 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2807 retry:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2808
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2809 if (CONSP (args[0]))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2810 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2811 /* (setcdr (last args[0]) args[1]) */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2812 Lisp_Object tortoise, hare;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2813 int count;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2814
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2815 for (hare = tortoise = args[0], count = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2816 CONSP (XCDR (hare));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2817 hare = XCDR (hare), count++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2818 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2819 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2820
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2821 if (count & 1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2822 tortoise = XCDR (tortoise);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2823 if (EQ (hare, tortoise))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2824 signal_circular_list_error (args[0]);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2825 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2826 XCDR (hare) = args[1];
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2827 return args[0];
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2828 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2829 else if (NILP (args[0]))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2830 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2831 return args[1];
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2832 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2833 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2834 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2835 args[0] = wrong_type_argument (args[0], Qlistp);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2836 goto retry;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2837 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2840 DEFUN ("nconc", Fnconc, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 Concatenate any number of lists by altering them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 Only the last argument is not altered, and need not be a list.
201
eb5470882647 Import from CVS: tag r20-3b27
cvs
parents: 195
diff changeset
2843 Also see: `append'.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2844 If the first argument is nil, there is no way to modify it by side
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2845 effect; therefore, write `(setq foo (nconc foo list))' to be sure of
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2846 changing the value of `foo'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2847 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2848 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2850 int argnum = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 /* The modus operandi in Emacs is "caller gc-protects args".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 However, nconc (particularly nconc2 ()) is called many times
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 in Emacs on freshly created stuff (e.g. you see the idiom
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 callers out by protecting the args ourselves to save them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 a lot of temporary-variable grief. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 GCPRO1 (args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 gcpro1.nvars = nargs;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2862
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2863 while (argnum < nargs)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 {
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2865 Lisp_Object val;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2866 retry:
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2867 val = args[argnum];
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2868 if (CONSP (val))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2869 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2870 /* `val' is the first cons, which will be our return value. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2871 /* `last_cons' will be the cons cell to mutate. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2872 Lisp_Object last_cons = val;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2873 Lisp_Object tortoise = val;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2874
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2875 for (argnum++; argnum < nargs; argnum++)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2876 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2877 Lisp_Object next = args[argnum];
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2878 retry_next:
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2879 if (CONSP (next) || argnum == nargs -1)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2880 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2881 /* (setcdr (last val) next) */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2882 int count;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2883
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2884 for (count = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2885 CONSP (XCDR (last_cons));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2886 last_cons = XCDR (last_cons), count++)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2887 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2888 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2889
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2890 if (count & 1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2891 tortoise = XCDR (tortoise);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2892 if (EQ (last_cons, tortoise))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2893 signal_circular_list_error (args[argnum-1]);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2894 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
2895 XCDR (last_cons) = next;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2896 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2897 else if (NILP (next))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2898 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2899 continue;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2900 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2901 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2902 {
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2903 next = wrong_type_argument (Qlistp, next);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2904 goto retry_next;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2905 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2906 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2907 RETURN_UNGCPRO (val);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2908 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2909 else if (NILP (val))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2910 argnum++;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2911 else if (argnum == nargs - 1) /* last arg? */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2912 RETURN_UNGCPRO (val);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2913 else
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2914 {
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2915 args[argnum] = wrong_type_argument (Qlistp, val);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2916 goto retry;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2917 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
2919 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2923 /* This is the guts of several mapping functions.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2924 Apply FUNCTION to each element of SEQUENCE, one by one,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2925 storing the results into elements of VALS, a C vector of Lisp_Objects.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2926 LENI is the length of VALS, which should also be the length of SEQUENCE.
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2927
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2928 If VALS is a null pointer, do not accumulate the results. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2931 mapcar1 (size_t leni, Lisp_Object *vals,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2932 Lisp_Object function, Lisp_Object sequence)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 {
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2934 Lisp_Object result;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2935 Lisp_Object args[2];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 int i;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2937 struct gcpro gcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 if (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 {
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2941 GCPRO1 (vals[0]);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2942 gcpro1.nvars = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2945 args[0] = function;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2946
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2947 if (LISTP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2949 /* A devious `function' could either:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2950 - insert garbage into the list in front of us, causing XCDR to crash
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2951 - amputate the list behind us using (setcdr), causing the remaining
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2952 elts to lose their GCPRO status.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2953
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2954 if (vals != 0) we avoid this by copying the elts into the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2955 `vals' array. By a stroke of luck, `vals' is exactly large
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2956 enough to hold the elts left to be traversed as well as the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2957 results computed so far.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2958
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2959 if (vals == 0) we don't have any free space available and
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2960 don't want to eat up any more stack with alloca().
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2961 So we use EXTERNAL_LIST_LOOP_3 and GCPRO the tail. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2962
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2963 if (vals)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2965 Lisp_Object *val = vals;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2966 Lisp_Object elt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2967
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2968 LIST_LOOP_2 (elt, sequence)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2969 *val++ = elt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2970
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2971 gcpro1.nvars = leni;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2972
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2973 for (i = 0; i < leni; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2974 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2975 args[1] = vals[i];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2976 vals[i] = Ffuncall (2, args);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2977 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2978 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2979 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2980 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2981 Lisp_Object elt, tail;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2982 struct gcpro ngcpro1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2983
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2984 NGCPRO1 (tail);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2985
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2986 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2987 EXTERNAL_LIST_LOOP_3 (elt, sequence, tail)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2988 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2989 args[1] = elt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2990 Ffuncall (2, args);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2991 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2992 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2993
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2994 NUNGCPRO;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2995 }
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2996 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2997 else if (VECTORP (sequence))
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
2998 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2999 Lisp_Object *objs = XVECTOR_DATA (sequence);
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3000 for (i = 0; i < leni; i++)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3001 {
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3002 args[1] = *objs++;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3003 result = Ffuncall (2, args);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3004 if (vals) vals[gcpro1.nvars++] = result;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3005 }
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3006 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3007 else if (STRINGP (sequence))
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3008 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3009 /* The string data of `sequence' might be relocated during GC. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3010 Bytecount slen = XSTRING_LENGTH (sequence);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3011 Bufbyte *p = alloca_array (Bufbyte, slen);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3012 Bufbyte *end = p + slen;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3013
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3014 memcpy (p, XSTRING_DATA (sequence), slen);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3015
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3016 while (p < end)
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3017 {
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3018 args[1] = make_char (charptr_emchar (p));
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3019 INC_CHARPTR (p);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3020 result = Ffuncall (2, args);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3021 if (vals) vals[gcpro1.nvars++] = result;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3024 else if (BIT_VECTORP (sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3026 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 for (i = 0; i < leni; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 {
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3029 args[1] = make_int (bit_vector_bit (v, i));
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3030 result = Ffuncall (2, args);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3031 if (vals) vals[gcpro1.nvars++] = result;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 }
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3034 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3035 abort (); /* unreachable, since Flength (sequence) did not get an error */
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3036
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3037 if (vals)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
3038 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3041 DEFUN ("mapconcat", Fmapconcat, 3, 3, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3042 Apply FUNCTION to each element of SEQUENCE, and concat the results as strings.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3043 In between each pair of results, insert SEPARATOR. Thus, using " " as
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3044 SEPARATOR results in spaces between the values returned by FUNCTION.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3045 SEQUENCE may be a list, a vector, a bit vector, or a string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3046 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3047 (function, sequence, separator))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3049 size_t len = XINT (Flength (sequence));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 int i;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3052 int nargs = len + len - 1;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3053
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3054 if (len == 0) return build_string ("");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
3056 args = alloca_array (Lisp_Object, nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3058 mapcar1 (len, args, function, sequence);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3060 for (i = len - 1; i >= 0; i--)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 args[i + i] = args[i];
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3062
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 for (i = 1; i < nargs; i += 2)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3064 args[i] = separator;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 return Fconcat (nargs, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3069 DEFUN ("mapcar", Fmapcar, 2, 2, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3070 Apply FUNCTION to each element of SEQUENCE; return a list of the results.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3071 The result is a list of the same length as SEQUENCE.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 SEQUENCE may be a list, a vector, a bit vector, or a string.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3073 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3074 (function, sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3076 size_t len = XINT (Flength (sequence));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
3077 Lisp_Object *args = alloca_array (Lisp_Object, len);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3078
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3079 mapcar1 (len, args, function, sequence);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3080
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3081 return Flist (len, args);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3084 DEFUN ("mapvector", Fmapvector, 2, 2, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3085 Apply FUNCTION to each element of SEQUENCE; return a vector of the results.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3086 The result is a vector of the same length as SEQUENCE.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3087 SEQUENCE may be a list, a vector, a bit vector, or a string.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3088 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3089 (function, sequence))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3090 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3091 size_t len = XINT (Flength (sequence));
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3092 Lisp_Object result = make_vector (len, Qnil);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3093 struct gcpro gcpro1;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3094
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3095 GCPRO1 (result);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3096 mapcar1 (len, XVECTOR_DATA (result), function, sequence);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3097 UNGCPRO;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3098
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
3099 return result;
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3100 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3101
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3102 DEFUN ("mapc-internal", Fmapc_internal, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 Apply FUNCTION to each element of SEQUENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 SEQUENCE may be a list, a vector, a bit vector, or a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 This function is like `mapcar' but does not accumulate the results,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 which is more efficient if you do not use the results.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3107
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3108 The difference between this and `mapc' is that `mapc' supports all
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3109 the spiffy Common Lisp arguments. You should normally use `mapc'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3110 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3111 (function, sequence))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3113 mapcar1 (XINT (Flength (sequence)), 0, function, sequence);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3114
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3115 return sequence;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3119
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3120
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3121 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /*
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3122 Destructively replace the list OLD with NEW.
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3123 This is like (copy-sequence NEW) except that it reuses the
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3124 conses in OLD as much as possible. If OLD and NEW are the same
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3125 length, no consing will take place.
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3126 */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3127 (old, new))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3128 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3129 Lisp_Object tail, oldtail = old, prevoldtail = Qnil;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3130
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3131 EXTERNAL_LIST_LOOP (tail, new)
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3132 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3133 if (!NILP (oldtail))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3134 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3135 CHECK_CONS (oldtail);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3136 XCAR (oldtail) = XCAR (tail);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3137 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3138 else if (!NILP (prevoldtail))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3139 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3140 XCDR (prevoldtail) = Fcons (XCAR (tail), Qnil);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3141 prevoldtail = XCDR (prevoldtail);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3142 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3143 else
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3144 old = oldtail = Fcons (XCAR (tail), Qnil);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3145
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3146 if (!NILP (oldtail))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3147 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3148 prevoldtail = oldtail;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3149 oldtail = XCDR (oldtail);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3150 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3151 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3152
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3153 if (!NILP (prevoldtail))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3154 XCDR (prevoldtail) = Qnil;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3155 else
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3156 old = Qnil;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3157
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3158 return old;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3159 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3160
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3161
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 /* #### this function doesn't belong in this file! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3164 DEFUN ("load-average", Fload_average, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 Return list of 1 minute, 5 minute and 15 minute load averages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 Each of the three load averages is multiplied by 100,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 then converted to integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3169 When USE-FLOATS is non-nil, floats will be used instead of integers.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3170 These floats are not multiplied by 100.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3171
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 If the 5-minute or 15-minute load averages are not available, return a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 shortened list, containing only those averages which are available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3175 On some systems, this won't work due to permissions on /dev/kmem,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3176 in which case you can't use this.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3177 */
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3178 (use_floats))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3180 double load_ave[3];
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3181 int loads = getloadavg (load_ave, countof (load_ave));
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3182 Lisp_Object ret = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 if (loads == -2)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3185 error ("load-average not implemented for this operating system");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 else if (loads < 0)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3187 signal_simple_error ("Could not get load-average",
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3188 lisp_strerror (errno));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3189
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3190 while (loads-- > 0)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3191 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3192 Lisp_Object load = (NILP (use_floats) ?
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3193 make_int ((int) (100.0 * load_ave[loads]))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3194 : make_float (load_ave[loads]));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3195 ret = Fcons (load, ret);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3196 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3197 return ret;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 Lisp_Object Vfeatures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3203 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /*
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3204 Return non-nil if feature FEXP is present in this Emacs.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3205 Use this to conditionalize execution of lisp code based on the
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3206 presence or absence of emacs or environment extensions.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3207 FEXP can be a symbol, a number, or a list.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3208 If it is a symbol, that symbol is looked up in the `features' variable,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3209 and non-nil will be returned if found.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3210 If it is a number, the function will return non-nil if this Emacs
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3211 has an equal or greater version number than FEXP.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3212 If it is a list whose car is the symbol `and', it will return
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3213 non-nil if all the features in its cdr are non-nil.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3214 If it is a list whose car is the symbol `or', it will return non-nil
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3215 if any of the features in its cdr are non-nil.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3216 If it is a list whose car is the symbol `not', it will return
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3217 non-nil if the feature is not present.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3218
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3219 Examples:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3220
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3221 (featurep 'xemacs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3222 => ; Non-nil on XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3223
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3224 (featurep '(and xemacs gnus))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3225 => ; Non-nil on XEmacs with Gnus loaded.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3226
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3227 (featurep '(or tty-frames (and emacs 19.30)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3228 => ; Non-nil if this Emacs supports TTY frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3229
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3230 (featurep '(or (and xemacs 19.15) (and emacs 19.34)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3231 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3232
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3233 (featurep '(and xemacs 21.02))
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3234 => ; Non-nil on XEmacs 21.2 and later.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3235
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3236 NOTE: The advanced arguments of this function (anything other than a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3237 symbol) are not yet supported by FSF Emacs. If you feel they are useful
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3238 for supporting multiple Emacs variants, lobby Richard Stallman at
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3239 <bug-gnu-emacs@gnu.org>.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3240 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3241 (fexp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3242 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3243 #ifndef FEATUREP_SYNTAX
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3244 CHECK_SYMBOL (fexp);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3245 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3246 #else /* FEATUREP_SYNTAX */
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3247 static double featurep_emacs_version;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3248
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3249 /* Brute force translation from Erik Naggum's lisp function. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3250 if (SYMBOLP (fexp))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3251 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3252 /* Original definition */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3253 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3254 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3255 else if (INTP (fexp) || FLOATP (fexp))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3256 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3257 double d = extract_float (fexp);
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3258
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3259 if (featurep_emacs_version == 0.0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3260 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 165
diff changeset
3261 featurep_emacs_version = XINT (Vemacs_major_version) +
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 165
diff changeset
3262 (XINT (Vemacs_minor_version) / 100.0);
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3263 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3264 return featurep_emacs_version >= d ? Qt : Qnil;
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3265 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3266 else if (CONSP (fexp))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3267 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3268 Lisp_Object tem = XCAR (fexp);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3269 if (EQ (tem, Qnot))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3270 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3271 Lisp_Object negate;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3272
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3273 tem = XCDR (fexp);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3274 negate = Fcar (tem);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3275 if (!NILP (tem))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3276 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil;
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3277 else
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3278 return Fsignal (Qinvalid_read_syntax, list1 (tem));
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3279 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3280 else if (EQ (tem, Qand))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3281 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3282 tem = XCDR (fexp);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3283 /* Use Fcar/Fcdr for error-checking. */
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3284 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3285 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3286 tem = Fcdr (tem);
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3287 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3288 return NILP (tem) ? Qt : Qnil;
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3289 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3290 else if (EQ (tem, Qor))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3291 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3292 tem = XCDR (fexp);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3293 /* Use Fcar/Fcdr for error-checking. */
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3294 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3295 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 201
diff changeset
3296 tem = Fcdr (tem);
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3297 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3298 return NILP (tem) ? Qnil : Qt;
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3299 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3300 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3301 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3302 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp)));
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3303 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3304 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3305 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3306 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 241
diff changeset
3307 return Fsignal (Qinvalid_read_syntax, list1 (fexp));
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3308 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3309 }
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 165
diff changeset
3310 #endif /* FEATUREP_SYNTAX */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3312 DEFUN ("provide", Fprovide, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 Announce that FEATURE is a feature of the current Emacs.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3314 This function updates the value of the variable `features'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3315 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3316 (feature))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 CHECK_SYMBOL (feature);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 if (!NILP (Vautoload_queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 tem = Fmemq (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 Vfeatures = Fcons (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 LOADHIST_ATTACH (Fcons (Qprovide, feature));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 return feature;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3329 DEFUN ("require", Frequire, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 If feature FEATURE is not loaded, load it from FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 If FEATURE is not a member of the list `features', then the feature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 is not loaded; so load the file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 If FILENAME is omitted, the printname of FEATURE is used as the file name.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3334 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3335 (feature, file_name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 CHECK_SYMBOL (feature);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 tem = Fmemq (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 LOADHIST_ATTACH (Fcons (Qrequire, feature));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 if (!NILP (tem))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
3342 return feature;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 /* Value saved here is to be restored into Vautoload_queue */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 record_unwind_protect (un_autoload, Vautoload_queue);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 Vautoload_queue = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 call4 (Qload, NILP (file_name) ? Fsymbol_name (feature) : file_name,
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
3352 Qnil, Qt, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 tem = Fmemq (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 error ("Required feature %s was not provided",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 string_data (XSYMBOL (feature)->name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 /* Once loading finishes, don't undo it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 Vautoload_queue = Qt;
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 140
diff changeset
3361 return unbind_to (speccount, feature);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 }
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3364
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3365 /* base64 encode/decode functions.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3366
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3367 Originally based on code from GNU recode. Ported to FSF Emacs by
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3368 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3369 subsequently heavily hacked by Hrvoje Niksic. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3370
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3371 #define MIME_LINE_LENGTH 72
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3372
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3373 #define IS_ASCII(Character) \
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3374 ((Character) < 128)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3375 #define IS_BASE64(Character) \
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3376 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3378 /* Table of characters coding the 64 values. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3379 static char base64_value_to_char[64] =
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3380 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3381 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3382 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3383 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3384 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3385 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3386 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3387 '8', '9', '+', '/' /* 60-63 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3388 };
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3389
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3390 /* Table of base64 values for first 128 characters. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3391 static short base64_char_to_value[128] =
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3392 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3393 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3394 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3395 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3396 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3397 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3398 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3399 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3400 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3401 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3402 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3403 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3404 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3405 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3406 };
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3407
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3408 /* The following diagram shows the logical steps by which three octets
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3409 get transformed into four base64 characters.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3410
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3411 .--------. .--------. .--------.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3412 |aaaaaabb| |bbbbcccc| |ccdddddd|
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3413 `--------' `--------' `--------'
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3414 6 2 4 4 2 6
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3415 .--------+--------+--------+--------.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3416 |00aaaaaa|00bbbbbb|00cccccc|00dddddd|
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3417 `--------+--------+--------+--------'
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3418
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3419 .--------+--------+--------+--------.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3420 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD|
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3421 `--------+--------+--------+--------'
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3422
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3423 The octets are divided into 6 bit chunks, which are then encoded into
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3424 base64 characters. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3425
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3426 #define ADVANCE_INPUT(c, stream) \
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3427 ((ec = Lstream_get_emchar (stream)) == -1 ? 0 : \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3428 ((ec > 255) ? \
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3429 (signal_simple_error ("Non-ascii character in base64 input", \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3430 make_char (ec)), 0) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3431 : (c = (Bufbyte)ec), 1))
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3432
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3433 static Bytind
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3434 base64_encode_1 (Lstream *istream, Bufbyte *to, int line_break)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3435 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3436 EMACS_INT counter = 0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3437 Bufbyte *e = to;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3438 Emchar ec;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3439 unsigned int value;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3440
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3441 while (1)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3442 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3443 Bufbyte c;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3444 if (!ADVANCE_INPUT (c, istream))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3445 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3446
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3447 /* Wrap line every 76 characters. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3448 if (line_break)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3449 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3450 if (counter < MIME_LINE_LENGTH / 4)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3451 counter++;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3452 else
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3453 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3454 *e++ = '\n';
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3455 counter = 1;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3456 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3457 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3458
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3459 /* Process first byte of a triplet. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3460 *e++ = base64_value_to_char[0x3f & c >> 2];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3461 value = (0x03 & c) << 4;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3462
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3463 /* Process second byte of a triplet. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3464 if (!ADVANCE_INPUT (c, istream))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3465 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3466 *e++ = base64_value_to_char[value];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3467 *e++ = '=';
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3468 *e++ = '=';
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3469 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3470 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3471
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3472 *e++ = base64_value_to_char[value | (0x0f & c >> 4)];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3473 value = (0x0f & c) << 2;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3474
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3475 /* Process third byte of a triplet. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3476 if (!ADVANCE_INPUT (c, istream))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3477 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3478 *e++ = base64_value_to_char[value];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3479 *e++ = '=';
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3480 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3481 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3482
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3483 *e++ = base64_value_to_char[value | (0x03 & c >> 6)];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3484 *e++ = base64_value_to_char[0x3f & c];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3485 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3486
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3487 return e - to;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3488 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3489 #undef ADVANCE_INPUT
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3490
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3491 /* Get next character from the stream, except that non-base64
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3492 characters are ignored. This is in accordance with rfc2045. EC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3493 should be an Emchar, so that it can hold -1 as the value for EOF. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3494 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3495 ec = Lstream_get_emchar (stream); \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3496 ++streampos; \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3497 /* IS_BASE64 may not be called with negative arguments so check for \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3498 EOF first. */ \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3499 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3500 break; \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3501 } while (1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3502
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3503 #define STORE_BYTE(pos, val, ccnt) do { \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3504 pos += set_charptr_emchar (pos, (Emchar)((unsigned char)(val))); \
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3505 ++ccnt; \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3506 } while (0)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3507
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3508 static Bytind
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3509 base64_decode_1 (Lstream *istream, Bufbyte *to, Charcount *ccptr)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3510 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3511 Charcount ccnt = 0;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3512 Bufbyte *e = to;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3513 EMACS_INT streampos = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3514
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3515 while (1)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3516 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3517 Emchar ec;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3518 unsigned long value;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3519
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3520 /* Process first byte of a quadruplet. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3521 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3522 if (ec < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3523 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3524 if (ec == '=')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3525 signal_simple_error ("Illegal `=' character while decoding base64",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3526 make_int (streampos));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3527 value = base64_char_to_value[ec] << 18;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3528
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3529 /* Process second byte of a quadruplet. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3530 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3531 if (ec < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3532 error ("Premature EOF while decoding base64");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3533 if (ec == '=')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3534 signal_simple_error ("Illegal `=' character while decoding base64",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3535 make_int (streampos));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3536 value |= base64_char_to_value[ec] << 12;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3537 STORE_BYTE (e, value >> 16, ccnt);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3538
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3539 /* Process third byte of a quadruplet. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3540 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3541 if (ec < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3542 error ("Premature EOF while decoding base64");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3543
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3544 if (ec == '=')
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3545 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3546 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3547 if (ec < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3548 error ("Premature EOF while decoding base64");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3549 if (ec != '=')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3550 signal_simple_error ("Padding `=' expected but not found while decoding base64",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3551 make_int (streampos));
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3552 continue;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3553 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3554
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3555 value |= base64_char_to_value[ec] << 6;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3556 STORE_BYTE (e, 0xff & value >> 8, ccnt);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3557
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3558 /* Process fourth byte of a quadruplet. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3559 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3560 if (ec < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3561 error ("Premature EOF while decoding base64");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3562 if (ec == '=')
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3563 continue;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3564
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3565 value |= base64_char_to_value[ec];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3566 STORE_BYTE (e, 0xff & value, ccnt);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3567 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3568
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3569 *ccptr = ccnt;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3570 return e - to;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3571 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3572 #undef ADVANCE_INPUT
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3573 #undef ADVANCE_INPUT_IGNORE_NONBASE64
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3574 #undef STORE_BYTE
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3575
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3576 static Lisp_Object
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3577 free_malloced_ptr (Lisp_Object unwind_obj)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3578 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3579 void *ptr = (void *)get_opaque_ptr (unwind_obj);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3580 xfree (ptr);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3581 free_opaque_ptr (unwind_obj);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3582 return Qnil;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3583 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3584
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3585 /* Don't use alloca for regions larger than this, lest we overflow
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3586 the stack. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3587 #define MAX_ALLOCA 65536
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3588
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3589 /* We need to setup proper unwinding, because there is a number of
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3590 ways these functions can blow up, and we don't want to have memory
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3591 leaks in those cases. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3592 #define XMALLOC_OR_ALLOCA(ptr, len, type) do { \
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3593 size_t XOA_len = (len); \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3594 if (XOA_len > MAX_ALLOCA) \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3595 { \
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3596 ptr = xnew_array (type, XOA_len); \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3597 record_unwind_protect (free_malloced_ptr, \
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3598 make_opaque_ptr ((void *)ptr)); \
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3599 } \
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3600 else \
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3601 ptr = alloca_array (type, XOA_len); \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3602 } while (0)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3603
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3604 #define XMALLOC_UNBIND(ptr, len, speccount) do { \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3605 if ((len) > MAX_ALLOCA) \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3606 unbind_to (speccount, Qnil); \
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3607 } while (0)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3608
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3609 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /*
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3610 Base64-encode the region between BEG and END.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3611 Return the length of the encoded text.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3612 Optional third argument NO-LINE-BREAK means do not break long lines
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3613 into shorter lines.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3614 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3615 (beg, end, no_line_break))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3616 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3617 Bufbyte *encoded;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3618 Bytind encoded_length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3619 Charcount allength, length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3620 struct buffer *buf = current_buffer;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3621 Bufpos begv, zv, old_pt = BUF_PT (buf);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3622 Lisp_Object input;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3623 int speccount = specpdl_depth();
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3624
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3625 get_buffer_range_char (buf, beg, end, &begv, &zv, 0);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3626 barf_if_buffer_read_only (buf, begv, zv);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3627
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3628 /* We need to allocate enough room for encoding the text.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3629 We need 33 1/3% more space, plus a newline every 76
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3630 characters, and then we round up. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3631 length = zv - begv;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3632 allength = length + length/3 + 1;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3633 allength += allength / MIME_LINE_LENGTH + 1 + 6;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3634
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3635 input = make_lisp_buffer_input_stream (buf, begv, zv, 0);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3636 /* We needn't multiply allength with MAX_EMCHAR_LEN because all the
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3637 base64 characters will be single-byte. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3638 XMALLOC_OR_ALLOCA (encoded, allength, Bufbyte);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3639 encoded_length = base64_encode_1 (XLSTREAM (input), encoded,
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3640 NILP (no_line_break));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3641 if (encoded_length > allength)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3642 abort ();
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3643 Lstream_delete (XLSTREAM (input));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3644
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3645 /* Now we have encoded the region, so we insert the new contents
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3646 and delete the old. (Insert first in order to preserve markers.) */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3647 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3648 XMALLOC_UNBIND (encoded, allength, speccount);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3649 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3650
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3651 /* Simulate FSF Emacs implementation of this function: if point was
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3652 in the region, place it at the beginning. */
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3653 if (old_pt >= begv && old_pt < zv)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3654 BUF_SET_PT (buf, begv);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3655
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3656 /* We return the length of the encoded text. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3657 return make_int (encoded_length);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3658 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3659
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
3660 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /*
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3661 Base64 encode STRING and return the result.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3662 */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
3663 (string, no_line_break))
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3664 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3665 Charcount allength, length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3666 Bytind encoded_length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3667 Bufbyte *encoded;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3668 Lisp_Object input, result;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3669 int speccount = specpdl_depth();
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3670
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3671 CHECK_STRING (string);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3672
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3673 length = XSTRING_CHAR_LENGTH (string);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
3674 allength = length + length/3 + 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
3675 allength += allength / MIME_LINE_LENGTH + 1 + 6;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3676
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3677 input = make_lisp_string_input_stream (string, 0, -1);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3678 XMALLOC_OR_ALLOCA (encoded, allength, Bufbyte);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
3679 encoded_length = base64_encode_1 (XLSTREAM (input), encoded,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
3680 NILP (no_line_break));
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3681 if (encoded_length > allength)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3682 abort ();
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3683 Lstream_delete (XLSTREAM (input));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3684 result = make_string (encoded, encoded_length);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3685 XMALLOC_UNBIND (encoded, allength, speccount);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3686 return result;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3687 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3688
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3689 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /*
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3690 Base64-decode the region between BEG and END.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3691 Return the length of the decoded text.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3692 If the region can't be decoded, return nil and don't modify the buffer.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3693 Characters out of the base64 alphabet are ignored.
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3694 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3695 (beg, end))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3696 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3697 struct buffer *buf = current_buffer;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3698 Bufpos begv, zv, old_pt = BUF_PT (buf);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3699 Bufbyte *decoded;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3700 Bytind decoded_length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3701 Charcount length, cc_decoded_length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3702 Lisp_Object input;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3703 int speccount = specpdl_depth();
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3704
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3705 get_buffer_range_char (buf, beg, end, &begv, &zv, 0);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3706 barf_if_buffer_read_only (buf, begv, zv);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3707
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3708 length = zv - begv;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3709
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3710 input = make_lisp_buffer_input_stream (buf, begv, zv, 0);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3711 /* We need to allocate enough room for decoding the text. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3712 XMALLOC_OR_ALLOCA (decoded, length * MAX_EMCHAR_LEN, Bufbyte);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3713 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, &cc_decoded_length);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3714 if (decoded_length > length * MAX_EMCHAR_LEN)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3715 abort ();
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3716 Lstream_delete (XLSTREAM (input));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3717
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3718 /* Now we have decoded the region, so we insert the new contents
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3719 and delete the old. (Insert first in order to preserve markers.) */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3720 BUF_SET_PT (buf, begv);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3721 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3722 XMALLOC_UNBIND (decoded, length * MAX_EMCHAR_LEN, speccount);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3723 buffer_delete_range (buf, begv + cc_decoded_length,
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3724 zv + cc_decoded_length, 0);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3725
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3726 /* Simulate FSF Emacs implementation of this function: if point was
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3727 in the region, place it at the beginning. */
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3728 if (old_pt >= begv && old_pt < zv)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3729 BUF_SET_PT (buf, begv);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3730
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3731 return make_int (cc_decoded_length);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3732 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3733
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3734 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /*
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3735 Base64-decode STRING and return the result.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3736 Characters out of the base64 alphabet are ignored.
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3737 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3738 (string))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3739 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3740 Bufbyte *decoded;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3741 Bytind decoded_length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3742 Charcount length, cc_decoded_length;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3743 Lisp_Object input, result;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3744 int speccount = specpdl_depth();
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3745
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3746 CHECK_STRING (string);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3747
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3748 length = XSTRING_CHAR_LENGTH (string);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3749 /* We need to allocate enough room for decoding the text. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3750 XMALLOC_OR_ALLOCA (decoded, length * MAX_EMCHAR_LEN, Bufbyte);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3751
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3752 input = make_lisp_string_input_stream (string, 0, -1);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3753 decoded_length = base64_decode_1 (XLSTREAM (input), decoded,
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3754 &cc_decoded_length);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3755 if (decoded_length > length * MAX_EMCHAR_LEN)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3756 abort ();
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3757 Lstream_delete (XLSTREAM (input));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3758
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3759 result = make_string (decoded, decoded_length);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3760 XMALLOC_UNBIND (decoded, length * MAX_EMCHAR_LEN, speccount);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3761 return result;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3762 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 Lisp_Object Qyes_or_no_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 syms_of_fns (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 {
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
3769 INIT_LRECORD_IMPLEMENTATION (bit_vector);
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
3770
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 defsymbol (&Qstring_lessp, "string-lessp");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 defsymbol (&Qidentity, "identity");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 defsymbol (&Qyes_or_no_p, "yes-or-no-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3775 DEFSUBR (Fidentity);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3776 DEFSUBR (Frandom);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3777 DEFSUBR (Flength);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3778 DEFSUBR (Fsafe_length);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3779 DEFSUBR (Fstring_equal);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3780 DEFSUBR (Fstring_lessp);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3781 DEFSUBR (Fstring_modified_tick);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3782 DEFSUBR (Fappend);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3783 DEFSUBR (Fconcat);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3784 DEFSUBR (Fvconcat);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3785 DEFSUBR (Fbvconcat);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3786 DEFSUBR (Fcopy_list);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3787 DEFSUBR (Fcopy_sequence);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3788 DEFSUBR (Fcopy_alist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3789 DEFSUBR (Fcopy_tree);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3790 DEFSUBR (Fsubstring);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3791 DEFSUBR (Fsubseq);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3792 DEFSUBR (Fnthcdr);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3793 DEFSUBR (Fnth);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3794 DEFSUBR (Felt);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3795 DEFSUBR (Flast);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3796 DEFSUBR (Fbutlast);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3797 DEFSUBR (Fnbutlast);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3798 DEFSUBR (Fmember);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3799 DEFSUBR (Fold_member);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3800 DEFSUBR (Fmemq);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3801 DEFSUBR (Fold_memq);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3802 DEFSUBR (Fassoc);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3803 DEFSUBR (Fold_assoc);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3804 DEFSUBR (Fassq);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3805 DEFSUBR (Fold_assq);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3806 DEFSUBR (Frassoc);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3807 DEFSUBR (Fold_rassoc);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3808 DEFSUBR (Frassq);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3809 DEFSUBR (Fold_rassq);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3810 DEFSUBR (Fdelete);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3811 DEFSUBR (Fold_delete);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3812 DEFSUBR (Fdelq);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3813 DEFSUBR (Fold_delq);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3814 DEFSUBR (Fremassoc);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3815 DEFSUBR (Fremassq);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3816 DEFSUBR (Fremrassoc);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3817 DEFSUBR (Fremrassq);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3818 DEFSUBR (Fnreverse);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3819 DEFSUBR (Freverse);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3820 DEFSUBR (Fsort);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3821 DEFSUBR (Fplists_eq);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3822 DEFSUBR (Fplists_equal);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3823 DEFSUBR (Flax_plists_eq);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3824 DEFSUBR (Flax_plists_equal);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3825 DEFSUBR (Fplist_get);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3826 DEFSUBR (Fplist_put);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3827 DEFSUBR (Fplist_remprop);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3828 DEFSUBR (Fplist_member);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3829 DEFSUBR (Fcheck_valid_plist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3830 DEFSUBR (Fvalid_plist_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3831 DEFSUBR (Fcanonicalize_plist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3832 DEFSUBR (Flax_plist_get);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3833 DEFSUBR (Flax_plist_put);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3834 DEFSUBR (Flax_plist_remprop);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3835 DEFSUBR (Flax_plist_member);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3836 DEFSUBR (Fcanonicalize_lax_plist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3837 DEFSUBR (Fdestructive_alist_to_plist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3838 DEFSUBR (Fget);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3839 DEFSUBR (Fput);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3840 DEFSUBR (Fremprop);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3841 DEFSUBR (Fobject_plist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3842 DEFSUBR (Fequal);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 50
diff changeset
3843 DEFSUBR (Fold_equal);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3844 DEFSUBR (Ffillarray);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3845 DEFSUBR (Fnconc);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3846 DEFSUBR (Fmapcar);
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
3847 DEFSUBR (Fmapvector);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3848 DEFSUBR (Fmapc_internal);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3849 DEFSUBR (Fmapconcat);
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3850 DEFSUBR (Freplace_list);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3851 DEFSUBR (Fload_average);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3852 DEFSUBR (Ffeaturep);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3853 DEFSUBR (Frequire);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3854 DEFSUBR (Fprovide);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3855 DEFSUBR (Fbase64_encode_region);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3856 DEFSUBR (Fbase64_encode_string);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3857 DEFSUBR (Fbase64_decode_region);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3858 DEFSUBR (Fbase64_decode_string);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 init_provide_once (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 DEFVAR_LISP ("features", &Vfeatures /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 A list of symbols which are the features of the executing emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 Used by `featurep' and `require', and altered by `provide'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 Vfeatures = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3869
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3870 Fprovide (intern ("base64"));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 }