annotate src/fns.c @ 408:501cfd01ee6d r21-2-34

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