annotate src/fns.c @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 9ee227acff29
children 859a2309aef8
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "bytecode.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Lisp_Object Qstring_lessp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 Lisp_Object Qidentity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 static Lisp_Object mark_bit_vector (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 static void print_bit_vector (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 static int bit_vector_equal (Lisp_Object o1, Lisp_Object o2, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 static unsigned long bit_vector_hash (Lisp_Object obj, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bit-vector", bit_vector,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 mark_bit_vector, print_bit_vector, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 bit_vector_equal, bit_vector_hash,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 struct Lisp_Bit_Vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 mark_bit_vector (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 return (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 struct Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 int len = bit_vector_length (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 int last = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 if (INTP (Vprint_length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 last = min (len, XINT (Vprint_length));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 write_c_string ("#*", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 for (i = 0; i < last; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if (bit_vector_bit (v, i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 write_c_string ("1", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 write_c_string ("0", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 if (last != len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 write_c_string ("...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 bit_vector_equal (Lisp_Object o1, Lisp_Object o2, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 struct Lisp_Bit_Vector *v1 = XBIT_VECTOR (o1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 struct Lisp_Bit_Vector *v2 = XBIT_VECTOR (o2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 if (bit_vector_length (v1) != bit_vector_length (v2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 return !memcmp (v1->bits, v2->bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 bit_vector_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 struct Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 return HASH2 (bit_vector_length (v),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 memory_hash (v->bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 sizeof (long)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 Return the argument unchanged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 Lisp_Object arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 return arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 extern long get_random (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 extern void seed_random (long arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 DEFUN ("random", Frandom, Srandom, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 Return a pseudo-random number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 All integers representable in Lisp are equally likely.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 On most systems, this is 28 bits' worth.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 With positive integer argument N, return random number in interval [0,N).\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 With argument t, set the random number seed from the current time and pid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 Lisp_Object limit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 EMACS_INT val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 Lisp_Object lispy_val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 unsigned long denominator;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 if (EQ (limit, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 seed_random (getpid () + time (NULL));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 if (NATNUMP (limit) && !ZEROP (limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 /* Try to take our random number from the higher bits of VAL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 not the lower, since (says Gentzel) the low bits of `random'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 are less random than the higher ones. We do this by using the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 quotient rather than the remainder. At the high end of the RNG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 it's possible to get a quotient larger than limit; discarding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 these values eliminates the bias that would otherwise appear
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 when using a large limit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 denominator = ((unsigned long)1 << VALBITS) / XINT (limit);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 val = get_random () / denominator;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 while (val >= XINT (limit));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 val = get_random ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 XSETINT (lispy_val, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 return lispy_val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 /* Random data-structure functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 /* #### Delete this shit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 /* Charcount is a misnomer here as we might be dealing with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 length of a vector or list, but emphasizes that we're not dealing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 with Bytecounts in strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 static Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 length_with_bytecode_hack (Lisp_Object seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 if (!COMPILED_FUNCTIONP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 return (XINT (Flength (seq)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 int intp = b->flags.interactivep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 int domainp = b->flags.domainp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 if (intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 return (COMPILED_INTERACTIVE + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 else if (domainp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 return (COMPILED_DOMAIN + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 return (COMPILED_DOC_STRING + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 #endif /* LOSING_BYTECODE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 check_losing_bytecode (CONST char *function, Lisp_Object seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 if (COMPILED_FUNCTIONP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 error_with_frob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (seq,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 "As of 19.14, `%s' no longer works with compiled-function objects",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 DEFUN ("length", Flength, Slength, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Return the length of vector, bit vector, list or string SEQUENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 retry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (STRINGP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 return (make_int (string_char_length (XSTRING (obj))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 else if (VECTORP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 return (make_int (vector_length (XVECTOR (obj))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 else if (BIT_VECTORP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 return (make_int (bit_vector_length (XBIT_VECTOR (obj))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 else if (CONSP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 for (i = 0, tail = obj; !NILP (tail); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 return (make_int (i));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 else if (NILP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 return (Qzero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 check_losing_bytecode ("length", obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 obj = wrong_type_argument (Qsequencep, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 /* This does not check for quits. That is safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 since it must terminate. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 Return the length of a list, but avoid error or infinite loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 This function never gets an error. If LIST is not really a list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 it returns 0. If LIST is circular, it returns a finite value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 which is at least the number of distinct elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 Lisp_Object tail, halftail, length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 int len = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 /* halftail is used to detect circular lists. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 halftail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 for (tail = list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 if (EQ (tail, halftail) && len != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 len++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 if ((len & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 halftail = XCDR (halftail);
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 XSETINT (length, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 return length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 /*** string functions. ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 DEFUN ("string-equal", Fstring_equal, Sstring_equal, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 T if two strings have identical contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 Case is significant. Text properties are ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (Under XEmacs, `equal' also ignores text properties and extents in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 strings, but this is not the case under FSF Emacs.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 Symbols are also allowed; their print names are used instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (s1, s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 Lisp_Object s1, s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 if (SYMBOLP (s1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 XSETSTRING (s1, XSYMBOL (s1)->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (SYMBOLP (s2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 XSETSTRING (s2, XSYMBOL (s2)->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 CHECK_STRING (s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 CHECK_STRING (s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
291 len = XSTRING_LENGTH (s1);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
292 if (len != XSTRING_LENGTH (s2) ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
293 memcmp (XSTRING_DATA (s1), XSTRING_DATA (s2), len))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 DEFUN ("string-lessp", Fstring_lessp, Sstring_lessp, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 T if first arg string is less than second in lexicographic order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 If I18N2 support was compiled in, ordering is determined by the locale.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 Case is significant for the default C locale.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 Symbols are also allowed; their print names are used instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (s1, s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Lisp_Object s1, s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 struct Lisp_String *p1, *p2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 Charcount end, len2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 if (SYMBOLP (s1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 XSETSTRING (s1, XSYMBOL (s1)->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 if (SYMBOLP (s2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 XSETSTRING (s2, XSYMBOL (s2)->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 CHECK_STRING (s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 CHECK_STRING (s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 p1 = XSTRING (s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 p2 = XSTRING (s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 end = string_char_length (XSTRING (s1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 len2 = string_char_length (XSTRING (s2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 if (end > len2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 end = len2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 #ifdef I18N2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 Bytecount bcend = charcount_to_bytecount (string_data (p1), end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 /* Compare strings using collation order of locale. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 /* Need to be tricky to handle embedded nulls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 for (i = 0; i < bcend; i += strlen((char *) string_data (p1) + i) + 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 int val = strcoll ((char *) string_data (p1) + i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (char *) string_data (p2) + i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 if (val < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if (val > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 #else /* not I18N2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 for (i = 0; i < end; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 if (string_char (p1, i) != string_char (p2, i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 return string_char (p1, i) < string_char (p2, i) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 #endif /* not I18N2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 /* Can't do i < len2 because then comparison between "foo" and "foo^@"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 won't work right in I18N2 case */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 return ((end < len2) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 DEFUN ("string-modified-tick", Fstring_modified_tick, Sstring_modified_tick,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 Return STRING's tick counter, incremented for each change to the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Each string has a tick counter which is incremented each time the contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 of the string are changed (e.g. with `aset'). It wraps around occasionally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 Lisp_Object string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 struct Lisp_String *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 s = XSTRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 if (CONSP (s->plist) && INTP (XCAR (s->plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 return XCAR (s->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 return Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 bump_string_modiff (Lisp_Object str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 struct Lisp_String *s = XSTRING (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 Lisp_Object *ptr = &s->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 /* #### remove the `string-translatable' property from the string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 if there is one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 /* skip over extent info if it's there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ptr = &XCDR (*ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 XSETINT (XCAR (*ptr), 1+XINT (XCAR (*ptr)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 *ptr = Fcons (make_int (1), *ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 static Lisp_Object concat (int nargs, Lisp_Object *args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 enum concat_target_type target_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 int last_special);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 concat2 (Lisp_Object s1, Lisp_Object s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 return concat (2, args, c_string, 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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 concat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 Lisp_Object args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 args[2] = s3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 return concat (3, args, c_string, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 vconcat2 (Lisp_Object s1, Lisp_Object s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 return concat (2, args, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 vconcat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 Lisp_Object args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 args[2] = s3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 return concat (3, args, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 DEFUN ("append", Fappend, Sappend, 0, MANY, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 Concatenate all the arguments and make the result a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 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
440 Each argument may be a list, vector, bit vector, or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 The last argument is not copied, just used as the tail of the new list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (nargs, args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 return concat (nargs, args, c_cons, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 DEFUN ("concat", Fconcat, Sconcat, 0, MANY, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 Concatenate all the arguments and make the result a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 The result is a string whose elements are the elements of all the arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 Each argument may be a string or a list or vector of characters (integers).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 Do not use individual integers as arguments!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 The behavior of `concat' in that case will be changed later!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 If your program passes an integer as an argument to `concat',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 you should change it right away not to do so.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (nargs, args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 return concat (nargs, args, c_string, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 DEFUN ("vconcat", Fvconcat, Svconcat, 0, MANY, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Concatenate all the arguments and make the result a vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 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
470 Each argument may be a list, vector, bit vector, or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (nargs, args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 return concat (nargs, args, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 DEFUN ("bvconcat", Fbvconcat, Sbvconcat, 0, MANY, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 Concatenate all the arguments and make the result a bit vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 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
482 arguments. Each argument may be a list, vector, bit vector, or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (nargs, args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 return concat (nargs, args, c_bit_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 DEFUN ("copy-sequence", Fcopy_sequence, Scopy_sequence, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 Return a copy of a list, vector, bit vector or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 The elements of a list or vector are not copied; they are shared
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 with the original.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 Lisp_Object arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 again:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 if (NILP (arg)) return arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 /* We handle conses separately because concat() is big and hairy and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 doesn't handle (copy-sequence '(a b . c)) and it's easier to redo this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 than to fix concat() without worrying about breaking other things.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 if (CONSP (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 Lisp_Object rest = arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 Lisp_Object head, tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 while (CONSP (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 Lisp_Object new = Fcons (XCAR (rest), XCDR (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 head = tail = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 XCDR (tail) = new, tail = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 rest = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 if (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 XCDR (tail) = rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 else if (STRINGP (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 return concat (1, &arg, c_string, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 else if (VECTORP (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 return concat (1, &arg, c_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 else if (BIT_VECTORP (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 return concat (1, &arg, c_bit_vector, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 check_losing_bytecode ("copy-sequence", arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 arg = wrong_type_argument (Qsequencep, arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 goto again;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 struct merge_string_extents_struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 Lisp_Object string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 Bytecount entry_offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 Bytecount entry_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 concat (int nargs, Lisp_Object *args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 enum concat_target_type target_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 int last_special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 Lisp_Object tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 int toindex;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 int argnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 Lisp_Object last_tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 Lisp_Object prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 struct merge_string_extents_struct *args_mse = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 Bufbyte *string_result = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 Bufbyte *string_result_ptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 /* The modus operandi in Emacs is "caller gc-protects args".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 However, concat is called many times in Emacs on freshly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 created stuff. So we help those callers out by protecting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 the args ourselves to save them a lot of temporary-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 grief. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 GCPRO1 (args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 gcpro1.nvars = nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 /* #### 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
572 for the `string-translatable' property, then concat should also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 concat the args but use the `string-translatable' strings, and store
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 the result in the returned string's `string-translatable' property. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 if (target_type == c_string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 args_mse = ((struct merge_string_extents_struct *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 alloca (nargs *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 sizeof (struct merge_string_extents_struct)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 /* In append, the last arg isn't treated like the others */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 if (last_special && nargs > 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 nargs--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 last_tail = args[nargs];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 last_tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 /* Check and coerce the arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 Lisp_Object seq = args[argnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 if (CONSP (seq) || NILP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 else if (COMPILED_FUNCTIONP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 /* Urk! We allow this, for "compatibility"... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 else if (INTP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 /* This is too revolting to think about but maintains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 compatibility with FSF (and lots and lots of old code). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 args[argnum] = Fnumber_to_string (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 check_losing_bytecode ("concat", seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 args[argnum] = wrong_type_argument (Qsequencep, seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 if (args_mse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 if (STRINGP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 args_mse[argnum].string = seq;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 args_mse[argnum].string = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 /* Charcount is a misnomer here as we might be dealing with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 length of a vector or list, but emphasizes that we're not dealing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 with Bytecounts in strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 Charcount total_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 for (argnum = 0, total_length = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 Charcount thislen = length_with_bytecode_hack (args[argnum]);
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 Charcount thislen = XINT (Flength (args[argnum]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 total_length += thislen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 switch (target_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 case c_cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 if (total_length == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 /* In append, if all but last arg are nil, return last arg */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 RETURN_UNGCPRO (last_tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 val = Fmake_list (make_int (total_length), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 case c_vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 val = make_vector (total_length, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 case c_bit_vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 val = make_bit_vector (total_length, Qzero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 case c_string:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 /* We don't make the string yet because we don't know the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 actual number of bytes. This loop was formerly written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 to call Fmake_string() here and then call set_string_char()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 for each char. This seems logical enough but is waaaaaaaay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 slow -- set_string_char() has to scan the whole string up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 to the place where the substitution is called for in order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 to find the place to change, and may have to do some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 realloc()ing in order to make the char fit properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 O(N^2) yuckage. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 string_result = (Bufbyte *) alloca (total_length * MAX_EMCHAR_LEN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 string_result_ptr = string_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 abort ();
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 if (CONSP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 tail = val, toindex = -1; /* -1 in toindex is flag we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 making a list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 toindex = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 Charcount thisleni = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 Charcount thisindex = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 Lisp_Object seq = args[argnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 Bufbyte *string_source_ptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 Bufbyte *string_prev_result_ptr = string_result_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 if (!CONSP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 thisleni = length_with_bytecode_hack (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 thisleni = XINT (Flength (seq));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 if (STRINGP (seq))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
699 string_source_ptr = XSTRING_DATA (seq);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 Lisp_Object elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 /* We've come to the end of this arg, so exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 if (NILP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 /* Fetch next element of `seq' arg into `elt' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 if (CONSP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 elt = Fcar (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 seq = Fcdr (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 if (thisindex >= thisleni)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 if (STRINGP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 elt = make_char (charptr_emchar (string_source_ptr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 INC_CHARPTR (string_source_ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 else if (VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 elt = vector_data (XVECTOR (seq))[thisindex];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 else if (BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 thisindex));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 elt = Felt (seq, make_int (thisindex));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 thisindex++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 /* Store into result */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 if (toindex < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 /* toindex negative means we are making a list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 XCAR (tail) = elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 tail = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 else if (VECTORP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 vector_data (XVECTOR (val))[toindex++] = elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 else if (BIT_VECTORP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 CHECK_BIT (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 CHECK_CHAR_COERCE_INT (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 string_result_ptr += set_charptr_emchar (string_result_ptr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 XCHAR (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 if (args_mse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 args_mse[argnum].entry_offset =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 string_prev_result_ptr - string_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 args_mse[argnum].entry_length =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 string_result_ptr - string_prev_result_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 /* Now we finally make the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 if (target_type == c_string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 val = make_string (string_result, string_result_ptr - string_result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 if (STRINGP (args_mse[argnum].string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 copy_string_extents (val, args_mse[argnum].string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 args_mse[argnum].entry_offset, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 args_mse[argnum].entry_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 if (!NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 XCDR (prev) = last_tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 RETURN_UNGCPRO (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 Return a copy of ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 This is an alist which represents the same mapping from objects to objects,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 but does not share the alist structure with ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 The objects mapped (cars and cdrs of elements of the alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 are shared, however.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 Elements of ALIST that are not conses are also shared.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 Lisp_Object alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 CHECK_LIST (alist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 if (NILP (alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 return alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 alist = concat (1, &alist, c_cons, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 for (tem = alist; CONSP (tem); tem = XCDR (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 Lisp_Object car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 car = XCAR (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 if (CONSP (car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 XCAR (tem) = Fcons (XCAR (car), XCDR (car));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 return alist;
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 DEFUN ("copy-tree", Fcopy_tree, Scopy_tree, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 Return a copy of a list and substructures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 The argument is copied, and any lists contained within it are copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 recursively. Circularities and shared substructures are not preserved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 Second arg VECP causes vectors to be copied, too. Strings and bit vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 are not copied.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (arg, vecp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 Lisp_Object arg, vecp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 if (CONSP (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 rest = arg = Fcopy_sequence (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 while (CONSP (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 Lisp_Object elt = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 if (CONSP (elt) || VECTORP (elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 XCAR (rest) = Fcopy_tree (elt, vecp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 XCDR (rest) = Fcopy_tree (XCDR (rest), vecp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 rest = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 else if (VECTORP (arg) && ! NILP (vecp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 int i = vector_length (XVECTOR (arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 int j;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 arg = Fcopy_sequence (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 for (j = 0; j < i; j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 Lisp_Object elt = vector_data (XVECTOR (arg)) [j];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 if (CONSP (elt) || VECTORP (elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 vector_data (XVECTOR (arg)) [j] = Fcopy_tree (elt, vecp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 return arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 Return a substring of STRING, starting at index FROM and ending before TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 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
857 If FROM or TO is negative, it counts from the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 Relevant parts of the string-extent-data are copied in the new string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (string, from, to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 Lisp_Object string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 Lisp_Object from, to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 Charcount ccfr, ccto;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 Bytecount bfr, bto;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 /* Historically, FROM could not be omitted. Whatever ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 CHECK_INT (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 get_string_range_char (string, from, to, &ccfr, &ccto,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 GB_HISTORICAL_STRING_BEHAVIOR);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
873 bfr = charcount_to_bytecount (XSTRING_DATA (string), ccfr);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
874 bto = charcount_to_bytecount (XSTRING_DATA (string), ccto);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
875 val = make_string (XSTRING_DATA (string) + bfr, bto - bfr);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 /* Copy any applicable extent information into the new string: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 copy_string_extents (val, string, 0, bfr, bto - bfr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 DEFUN ("subseq", Fsubseq, Ssubseq, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 Return a subsequence of SEQ, starting at index FROM and ending before TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 TO may be nil or omitted; then the subsequence runs to the end of SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 If FROM or TO is negative, it counts from the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 The resulting subsequence is always the same type as the original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 If SEQ is a string, relevant parts of the string-extent-data are copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 in the new string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (seq, from, to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 Lisp_Object seq;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 Lisp_Object from, to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 int len, f, t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 if (STRINGP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 return Fsubstring (seq, from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 if (CONSP (seq) || NILP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 else if (VECTORP (seq) || BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 check_losing_bytecode ("subseq", seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 seq = wrong_type_argument (Qsequencep, seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 len = XINT (Flength (seq));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 CHECK_INT (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 f = XINT (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 if (f < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 f = len + f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 if (NILP (to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 t = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 CHECK_INT (to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 t = XINT (to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 if (t < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 t = len + t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 if (!(0 <= f && f <= t && t <= len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 args_out_of_range_3 (seq, make_int (f), make_int (t));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 if (VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 Lisp_Object result = make_vector (t - f, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 Lisp_Object *in_elts = vector_data (XVECTOR (seq));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 Lisp_Object *out_elts = vector_data (XVECTOR (result));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 for (i = f; i < t; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 out_elts[i - f] = in_elts[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 if (CONSP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 Lisp_Object result = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 seq = Fnthcdr (make_int (f), seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 for (i = f; i < t; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 result = Fcons (Fcar (seq), result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 seq = Fcdr (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 return Fnreverse (result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 /* bit vector */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 Lisp_Object result = make_bit_vector (t - f, Qzero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 for (i = f; i < t; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 set_bit_vector_bit (XBIT_VECTOR (result), i - f,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 bit_vector_bit (XBIT_VECTOR (seq), i));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 Take cdr N times on LIST, returns the result.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (n, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 Lisp_Object n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 REGISTER int i, num;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 CHECK_INT (n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 num = XINT (n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 for (i = 0; i < num && !NILP (list); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 list = Fcdr (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 DEFUN ("nth", Fnth, Snth, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 Return the Nth element of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 N counts from zero. If LIST is not that long, nil is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (n, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 Lisp_Object n, list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 return Fcar (Fnthcdr (n, list));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 DEFUN ("elt", Felt, Selt, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 Return element of SEQUENCE at index N.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (seq, n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 Lisp_Object seq, n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 retry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 CHECK_INT_COERCE_CHAR (n); /* yuck! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 if (CONSP (seq) || NILP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 Lisp_Object tem = Fnthcdr (n, seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 /* #### Utterly, completely, fucking disgusting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 * #### The whole point of "elt" is that it operates on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 * #### sequences, and does error- (bounds-) checking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 if (CONSP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 return (XCAR (tem));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 /* This is The Way It Has Always Been. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 /* This is The Way Mly Says It Should Be. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 args_out_of_range (seq, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 else if (STRINGP (seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 || VECTORP (seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 || BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 return (Faref (seq, n));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 #ifdef LOSING_BYTECODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 else if (COMPILED_FUNCTIONP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 int idx = XINT (n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 if (idx < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 lose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 args_out_of_range (seq, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 /* Utter perversity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 switch (idx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 case COMPILED_ARGLIST:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 return (b->arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 case COMPILED_BYTECODE:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 return (b->bytecodes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 case COMPILED_CONSTANTS:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 return (b->constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 case COMPILED_STACK_DEPTH:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 return (make_int (b->maxdepth));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 case COMPILED_DOC_STRING:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 return (compiled_function_documentation (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 case COMPILED_DOMAIN:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 return (compiled_function_domain (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 case COMPILED_INTERACTIVE:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 if (b->flags.interactivep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 return (compiled_function_interactive (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 /* if we return nil, can't tell interactive with no args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 from noninteractive. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 #endif /* LOSING_BYTECODE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 check_losing_bytecode ("elt", seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 seq = wrong_type_argument (Qsequencep, seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 DEFUN ("member", Fmember, Smember, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 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
1074 The value is actually the tail of LIST whose car is ELT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (elt, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 Lisp_Object elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 REGISTER Lisp_Object tail, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 for (tail = list; !NILP (tail); tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 tem = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 if (! NILP (Fequal (elt, tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 return tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 DEFUN ("memq", Fmemq, Smemq, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 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
1093 The value is actually the tail of LIST whose car is ELT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (elt, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 Lisp_Object elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 REGISTER Lisp_Object tail, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 for (tail = list; !NILP (tail); tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 tem = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 if (HACKEQ_UNSAFE (elt, tem)) return tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 memq_no_quit (Lisp_Object elt, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 REGISTER Lisp_Object tail, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 for (tail = list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 tem = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 if (HACKEQ_UNSAFE (elt, tem)) return tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 DEFUN ("assoc", Fassoc, Sassoc, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 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
1123 The value is actually the element of LIST whose car equals KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (key, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 /* This function can GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 REGISTER Lisp_Object tail, elt, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 for (tail = list; !NILP (tail); tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 if (!CONSP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 tem = Fequal (Fcar (elt), key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 if (!NILP (tem)) return elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 assoc_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 specbind (Qinhibit_quit, Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 return (unbind_to (speccount, Fassoc (key, list)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 DEFUN ("assq", Fassq, Sassq, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 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
1152 The value is actually the element of LIST whose car is KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 Elements of LIST that are not conses are ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (key, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 REGISTER Lisp_Object tail, elt, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 for (tail = list; !NILP (tail); tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 if (!CONSP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 tem = Fcar (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 if (HACKEQ_UNSAFE (key, tem)) return elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 /* Like Fassq but never report an error and do not allow quits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 Use only on lists known never to be circular. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 assq_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 REGISTER Lisp_Object tail, elt, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 for (tail = list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 elt = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 if (!CONSP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 tem = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 if (HACKEQ_UNSAFE (key, tem)) return elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 DEFUN ("rassoc", Frassoc, Srassoc, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 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
1191 The value is actually the element of LIST whose cdr equals KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (key, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 REGISTER Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 for (tail = list; !NILP (tail); tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 REGISTER Lisp_Object elt, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 if (!CONSP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 tem = Fequal (Fcdr (elt), key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 if (!NILP (tem)) return elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 DEFUN ("rassq", Frassq, Srassq, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 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
1212 The value is actually the element of LIST whose cdr is KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (key, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 REGISTER Lisp_Object tail, elt, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 for (tail = list; !NILP (tail); tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 if (!CONSP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 tem = Fcdr (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 if (HACKEQ_UNSAFE (key, tem)) return elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 QUIT;
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 rassq_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 REGISTER Lisp_Object tail, elt, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 for (tail = list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 elt = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 if (!CONSP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 tem = XCDR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 if (HACKEQ_UNSAFE (key, tem)) return elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 DEFUN ("delete", Fdelete, Sdelete, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 Delete by side effect any occurrences of ELT as a member of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 The modified LIST is returned. Comparison is done with `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 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
1249 effect; therefore, write `(setq foo (delete element foo))' to be sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 of changing the value of `foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (elt, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 Lisp_Object elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 if (!NILP (Fequal (elt, Fcar (tail))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 list = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 Fsetcdr (prev, Fcdr (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 DEFUN ("delq", Fdelq, Sdelq, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 Delete by side effect any occurrences of ELT as a member of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 The modified LIST is returned. Comparison is done with `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 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
1281 effect; therefore, write `(setq foo (delq element foo))' to be sure of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 changing the value of `foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (elt, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 Lisp_Object elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 tem = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 if (HACKEQ_UNSAFE (elt, tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 list = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 Fsetcdr (prev, Fcdr (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 /* no quit, no errors; be careful */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 delq_no_quit (Lisp_Object elt, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 while (CONSP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 tem = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 if (HACKEQ_UNSAFE (elt, tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 list = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 XCDR (prev) = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 tail = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 /* Be VERY careful with this. This is like delq_no_quit() but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 also calls free_cons() on the removed conses. You must be SURE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 that no pointers to the freed conses remain around (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 someone else is pointing to part of the list). This function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 is useful on internal lists that are used frequently and where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 the actual list doesn't escape beyond known code bounds. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 while (CONSP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 Lisp_Object cons_to_free = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 tem = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 if (HACKEQ_UNSAFE (elt, tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 list = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 XCDR (prev) = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 cons_to_free = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 tail = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 if (!NILP (cons_to_free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 free_cons (XCONS (cons_to_free));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 DEFUN ("remassoc", Fremassoc, Sremassoc, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 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
1376 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
1377 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
1378 therefore, write `(setq foo (remassoc key foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 the value of `foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (key, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 Lisp_Object elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 if (CONSP (elt) && ! NILP (Fequal (key, Fcar (elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 list = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 Fsetcdr (prev, Fcdr (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 remassoc_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 specbind (Qinhibit_quit, Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 return (unbind_to (speccount, Fremassoc (key, list)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 DEFUN ("remassq", Fremassq, Sremassq, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 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
1417 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
1418 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
1419 therefore, write `(setq foo (remassq key foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 the value of `foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (key, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 Lisp_Object elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 if (CONSP (elt) && HACKEQ_UNSAFE (key, Fcar (elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 list = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 Fsetcdr (prev, Fcdr (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 /* no quit, no errors; be careful */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 remassq_no_quit (Lisp_Object key, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 while (CONSP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 tem = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 if (CONSP (tem) && HACKEQ_UNSAFE (key, XCAR (tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 list = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 XCDR (prev) = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 tail = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 DEFUN ("remrassoc", Fremrassoc, Sremrassoc, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 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
1477 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
1478 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
1479 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 the value of `foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (value, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 Lisp_Object value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 Lisp_Object elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 if (CONSP (elt) && ! NILP (Fequal (value, Fcdr (elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 list = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 Fsetcdr (prev, Fcdr (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 DEFUN ("remrassq", Fremrassq, Sremrassq, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 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
1510 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
1511 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
1512 therefore, write `(setq foo (remrassq value foo))' to be sure of changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 the value of `foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (value, list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 Lisp_Object value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 Lisp_Object elt = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 if (CONSP (elt) && HACKEQ_UNSAFE (value, Fcdr (elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 list = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 Fsetcdr (prev, Fcdr (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 /* no quit, no errors; be careful */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 remrassq_no_quit (Lisp_Object value, Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 REGISTER Lisp_Object tail, prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 while (CONSP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 tem = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 if (CONSP (tem) && HACKEQ_UNSAFE (value, XCDR (tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 if (NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 list = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 XCDR (prev) = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 tail = XCDR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 DEFUN ("nreverse", Fnreverse, Snreverse, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 Reverse LIST by modifying cdr pointers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 Returns the beginning of the reversed list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 Lisp_Object prev, tail, next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 /* We gcpro our args; see `nconc' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 tail = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 GCPRO2 (prev, tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 while (!NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 next = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 Fsetcdr (tail, prev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 prev = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 tail = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 return prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 DEFUN ("reverse", Freverse, Sreverse, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 Reverse LIST, copying. Returns the beginning of the reversed list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 See also the function `nreverse', which is used more often.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 Lisp_Object list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 Lisp_Object length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 Lisp_Object *vec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 length = Flength (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 vec = (Lisp_Object *) alloca (XINT (length) * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 for (i = XINT (length) - 1, tail = list; i >= 0; i--, tail = Fcdr (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 vec[i] = Fcar (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 return Flist (XINT (length), vec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 Lisp_Object lisp_arg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 int (*pred_fn) (Lisp_Object, Lisp_Object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 Lisp_Object lisp_arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 list_sort (Lisp_Object list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 Lisp_Object lisp_arg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 int (*pred_fn) (Lisp_Object, Lisp_Object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 Lisp_Object lisp_arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 Lisp_Object front, back;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 Lisp_Object len, tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 front = list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 len = Flength (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 length = XINT (len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 if (length < 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 return list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 XSETINT (len, (length / 2) - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 tem = Fnthcdr (len, list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 back = Fcdr (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 Fsetcdr (tem, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 GCPRO3 (front, back, lisp_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 front = list_sort (front, lisp_arg, pred_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 back = list_sort (back, lisp_arg, pred_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 return list_merge (front, back, lisp_arg, pred_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 Lisp_Object pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 Lisp_Object tmp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 /* prevents the GC from happening in call2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 /* Emacs' GC doesn't actually relocate pointers, so this probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 isn't strictly necessary */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 record_unwind_protect (restore_gc_inhibit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 make_int (gc_currently_forbidden));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 gc_currently_forbidden = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 tmp = call2 (pred, obj1, obj2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 if (NILP (tmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 DEFUN ("sort", Fsort, Ssort, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 Sort LIST, stably, comparing elements using PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 Returns the sorted list. LIST is modified by side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 PREDICATE is called with two elements of LIST, and should return T
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 if the first element is \"less\" than the second.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (list, pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 Lisp_Object list, pred;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 return list_sort (list, pred, merge_pred_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 merge (Lisp_Object org_l1, Lisp_Object org_l2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 Lisp_Object pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 return list_merge (org_l1, org_l2, pred, merge_pred_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 list_merge (Lisp_Object org_l1, Lisp_Object org_l2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 Lisp_Object lisp_arg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 Lisp_Object value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 Lisp_Object l1, l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 l1 = org_l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 l2 = org_l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 value = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 /* It is sufficient to protect org_l1 and org_l2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 When l1 and l2 are updated, we copy the new values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 back into the org_ vars. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 GCPRO4 (org_l1, org_l2, lisp_arg, value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 if (NILP (l1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 return l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 Fsetcdr (tail, l2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 if (NILP (l2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 return l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 Fsetcdr (tail, l1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 tem = l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 l1 = Fcdr (l1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 org_l1 = l1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 tem = l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 l2 = Fcdr (l2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 org_l2 = l2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 value = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 Fsetcdr (tail, tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 tail = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 /* property-list functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 /* For properties of text, we need to do order-insensitive comparison of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 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
1759 same if they have the same set of keys, and equivalent values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 So (a 1 b 2) would be equal to (b 2 a 1).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 LAXP means use `equal' for comparisons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 int laxp, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 int eqp = (depth == -1); /* -1 as depth means us eq, not equal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 int la, lb, m, i, fill;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 Lisp_Object *keys, *vals;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 char *flags;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 if (NILP (a) && NILP (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 Fcheck_valid_plist (a);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 Fcheck_valid_plist (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 la = XINT (Flength (a));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 lb = XINT (Flength (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 m = (la > lb ? la : lb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 fill = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 keys = (Lisp_Object *) alloca (m * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 vals = (Lisp_Object *) alloca (m * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 flags = (char *) alloca (m * sizeof (char));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 /* First extract the pairs from A. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 Lisp_Object k = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 Lisp_Object v = XCAR (XCDR (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 /* Maybe be Ebolified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 if (nil_means_not_present && NILP (v)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 keys [fill] = k;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 vals [fill] = v;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 flags[fill] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 fill++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 /* 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
1802 or that doesn't match. As we match, mark them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 Lisp_Object k = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 Lisp_Object v = XCAR (XCDR (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 /* Maybe be Ebolified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 if (nil_means_not_present && NILP (v)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 for (i = 0; i < fill; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 if (!laxp ? EQ (k, keys [i]) : internal_equal (k, keys [i], depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 if ((eqp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 /* Ebolified here too, sigh ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 ? !HACKEQ_UNSAFE (v, vals [i])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 : !internal_equal (v, vals [i], depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 /* a property in B has a different value than in A */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 goto MISMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 flags [i] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 if (i == fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 /* there are some properties in B that are not in A */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 goto MISMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 /* 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
1828 for (i = 0; i < fill; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 if (flags [i] == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 goto MISMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 /* Ok. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 MISMATCH:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 return 1;
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 DEFUN ("plists-eq", Fplists_eq, Splists_eq, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 Return non-nil if property lists A and B are `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 A property list is an alternating list of keywords and values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 This function does order-insensitive comparisons of the property lists:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 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
1844 Comparison between values is done using `eq'. See also `plists-equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 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
1846 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
1847 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1848 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (a, b, nil_means_not_present)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 Lisp_Object a, b, nil_means_not_present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 DEFUN ("plists-equal", Fplists_equal, Splists_equal, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 Return non-nil if property lists A and B are `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 A property list is an alternating list of keywords and values. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 function does order-insensitive comparisons of the property lists: For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 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
1862 Comparison between values is done using `equal'. See also `plists-eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 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
1864 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
1865 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1866 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (a, b, nil_means_not_present)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 Lisp_Object a, b, nil_means_not_present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 DEFUN ("lax-plists-eq", Flax_plists_eq, Slax_plists_eq, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 Return non-nil if lax property lists A and B are `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 A property list is an alternating list of keywords and values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 This function does order-insensitive comparisons of the property lists:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 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
1881 Comparison between values is done using `eq'. See also `plists-equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 A lax property list is like a regular one except that comparisons between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 keywords is done using `equal' instead of `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 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
1885 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
1886 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1887 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (a, b, nil_means_not_present)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 Lisp_Object a, b, nil_means_not_present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 DEFUN ("lax-plists-equal", Flax_plists_equal, Slax_plists_equal, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 Return non-nil if lax property lists A and B are `equal'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 A property list is an alternating list of keywords and values. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 function does order-insensitive comparisons of the property lists: For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 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
1901 Comparison between values is done using `equal'. See also `plists-eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 A lax property list is like a regular one except that comparisons between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 keywords is done using `equal' instead of `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 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
1905 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
1906 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1907 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (a, b, nil_means_not_present)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 Lisp_Object a, b, nil_means_not_present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 /* Return the value associated with key PROPERTY in property list PLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 Return nil if key not found. This function is used for internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 property lists that cannot be directly manipulated by the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 internal_plist_get (Lisp_Object plist, Lisp_Object property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 Lisp_Object tail = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 struct Lisp_Cons *c = XCONS (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 if (EQ (c->car, property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 return XCAR (c->cdr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 /* Set PLIST's value for PROPERTY to VALUE. Analogous to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 internal_plist_get(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 internal_plist_put (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 Lisp_Object value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 Lisp_Object tail = *plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 for (; !NILP (tail); tail = XCDR (XCDR (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 struct Lisp_Cons *c = XCONS (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 if (EQ (c->car, property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 XCAR (c->cdr) = value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 *plist = Fcons (property, Fcons (value, *plist));
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 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 internal_remprop (Lisp_Object *plist, Lisp_Object property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 Lisp_Object tail = *plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 if (NILP (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 if (EQ (XCAR (tail), property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 *plist = XCDR (XCDR (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 for (tail = XCDR (tail); !NILP (XCDR (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 tail = XCDR (XCDR (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 struct Lisp_Cons *c = XCONS (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 if (EQ (XCAR (c->cdr), property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 c->cdr = XCDR (XCDR (c->cdr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 /* Called on a malformed property list. BADPLACE should be some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 place where truncating will form a good list -- i.e. we shouldn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 result in a list with an odd length. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 if (ERRB_EQ (errb, ERROR_ME))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 if (ERRB_EQ (errb, ERROR_ME_WARN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 warn_when_safe_lispobj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (Qlist, Qwarning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 list2 (build_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ("Malformed property list -- list has been truncated"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 *plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 *badplace = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 /* Called on a circular property list. BADPLACE should be some place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 where truncating will result in an even-length list, as above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 If doesn't particularly matter where we truncate -- anywhere we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 truncate along the entire list will break the circularity, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 it will create a terminus and the list currently doesn't have one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 if (ERRB_EQ (errb, ERROR_ME))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 /* #### Eek, this will probably result in another error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 when PLIST is printed out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 return Fsignal (Qcircular_property_list, list1 (*plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 if (ERRB_EQ (errb, ERROR_ME_WARN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 warn_when_safe_lispobj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (Qlist, Qwarning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 list2 (build_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 ("Circular property list -- list has been truncated"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 *plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 *badplace = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 /* Advance the tortoise pointer by two (one iteration of a property-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 loop) and the hare pointer by four and verify that no malformations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 or circularities exist. If so, return zero and store a value into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 RETVAL that should be returned by the calling function. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 return 1. See external_plist_get().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 advance_plist_pointers (Lisp_Object *plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 Lisp_Object **tortoise, Lisp_Object **hare,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 Error_behavior errb, Lisp_Object *retval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 Lisp_Object *tortsave = *tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 /* Note that our "fixing" may be more brutal than necessary,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 but it's the user's own problem, not ours. if they went in and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 manually fucked up a plist. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 for (i = 0; i < 2; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 /* This is a standard iteration of a defensive-loop-checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 loop. We just do it twice because we want to advance past
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 both the property and its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 If the pointer indirection is confusing you, remember that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 one level of indirection on the hare and tortoise pointers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 is only due to pass-by-reference for this function. The other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 level is so that the plist can be fixed in place. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 /* When we reach the end of a well-formed plist, **HARE is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 nil. In that case, we don't do anything at all except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 advance TORTOISE by one. Otherwise, we advance HARE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 by two (making sure it's OK to do so), then advance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 TORTOISE by one (it will always be OK to do so because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 the HARE is always ahead of the TORTOISE and will have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 already verified the path), then make sure TORTOISE and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 HARE don't contain the same non-nil object -- if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 TORTOISE and the HARE ever meet, then obviously we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 in a circularity, and if we're in a circularity, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 the TORTOISE and the HARE can't cross paths without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 meeting, since the HARE only gains one step over the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 TORTOISE per iteration. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 if (!NILP (**hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 Lisp_Object *haresave = *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 if (!CONSP (**hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 *retval = bad_bad_bunny (plist, haresave, errb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 *hare = &XCDR (**hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 /* In a non-plist, we'd check here for a nil value for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 **HARE, which is OK (it just means the list has an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 odd number of elements). In a plist, it's not OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 for the list to have an odd number of elements. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 if (!CONSP (**hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 *retval = bad_bad_bunny (plist, haresave, errb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 *hare = &XCDR (**hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 *tortoise = &XCDR (**tortoise);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 if (!NILP (**hare) && EQ (**tortoise, **hare))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 *retval = bad_bad_turtle (plist, tortsave, errb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 /* Return the value of PROPERTY from PLIST, or Qunbound if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 property is not on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 PLIST is a Lisp-accessible property list, meaning that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 has to be checked for malformations and circularities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 function will never signal an error; and if ERRB is ERROR_ME_WARN,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 on finding a malformation or a circularity, it issues a warning and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 attempts to silently fix the problem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 A pointer to PLIST is passed in so that PLIST can be successfully
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 "fixed" even if the error is at the beginning of the plist. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 external_plist_get (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 int laxp, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 Lisp_Object *tortoise = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 Lisp_Object *hare = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 Lisp_Object *tortsave = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 /* We do the standard tortoise/hare march. We isolate the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 grungy stuff to do this in advance_plist_pointers(), though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 To us, all this function does is advance the tortoise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 pointer by two and the hare pointer by four and make sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 everything's OK. We first advance the pointers and then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 check if a property matched; this ensures that our
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 check for a matching property is safe. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 return retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 if (!laxp ? EQ (XCAR (*tortsave), property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 : internal_equal (XCAR (*tortsave), property, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 return XCAR (XCDR (*tortsave));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 return Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 /* Set PLIST's value for PROPERTY to VALUE, given a possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 malformed or circular plist. Analogous to external_plist_get(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 external_plist_put (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 Lisp_Object value, int laxp, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 Lisp_Object *tortoise = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 Lisp_Object *hare = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 Lisp_Object *tortsave = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 if (!laxp ? EQ (XCAR (*tortsave), property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 : internal_equal (XCAR (*tortsave), property, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 XCAR (XCDR (*tortsave)) = value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 return;
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 *plist = Fcons (property, Fcons (value, *plist));
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 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 external_remprop (Lisp_Object *plist, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 int laxp, Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 Lisp_Object *tortoise = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 Lisp_Object *hare = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 Lisp_Object *tortsave = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 if (!laxp ? EQ (XCAR (*tortsave), property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 : internal_equal (XCAR (*tortsave), property, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 /* Now you see why it's so convenient to have that level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 of indirection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 *tortsave = XCDR (XCDR (*tortsave));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 DEFUN ("plist-get", Fplist_get, Splist_get, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 Extract a value from a property list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 PLIST is a property list, which is a list of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 corresponding to the given PROP, or DEFAULT if PROP is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 one of the properties on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (plist, prop, defalt) /* Cant spel in C */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 Lisp_Object plist, prop, defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 Lisp_Object val = external_plist_get (&plist, prop, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 if (UNBOUNDP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 return defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 return val;
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 DEFUN ("plist-put", Fplist_put, Splist_put, 3, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 Change value in PLIST of PROP to VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 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
2238 PROP2 VALUE2 ...). PROP is usually a symbol and VAL is any object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 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
2240 otherwise the new PROP VAL pair is added. The new plist is returned;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 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
2242 The PLIST is modified by side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (plist, prop, val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 Lisp_Object plist, prop, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 external_plist_put (&plist, prop, val, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 return plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 DEFUN ("plist-remprop", Fplist_remprop, Splist_remprop, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 Remove from PLIST the property PROP and its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 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
2254 PROP2 VALUE2 ...). PROP is usually a symbol. The new plist is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 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
2256 the new value. The PLIST is modified by side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (plist, prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 Lisp_Object plist, prop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 external_remprop (&plist, prop, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 return 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 DEFUN ("plist-member", Fplist_member, Splist_member, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 Return t if PROP has a value specified in PLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (plist, prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 Lisp_Object plist, prop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 return UNBOUNDP (Fplist_get (plist, prop, Qunbound)) ? Qnil : Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 DEFUN ("check-valid-plist", Fcheck_valid_plist, Scheck_valid_plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 Given a plist, signal an error if there is anything wrong with it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 This means that it's a malformed or circular plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 Lisp_Object plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 Lisp_Object *tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 Lisp_Object *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 start_over:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 tortoise = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 hare = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 goto start_over;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 DEFUN ("valid-plist-p", Fvalid_plist_p, Svalid_plist_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 Given a plist, return non-nil if its format is correct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 If it returns nil, `check-valid-plist' will signal an error when given
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 the plist; that means it's a malformed or circular plist or has non-symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 as keywords.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 Lisp_Object plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 Lisp_Object *tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 Lisp_Object *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 tortoise = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 hare = &plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 while (!NILP (*tortoise))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 /* See above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 &retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 DEFUN ("canonicalize-plist", Fcanonicalize_plist, Scanonicalize_plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 Destructively remove any duplicate entries from a plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 In such cases, the first entry applies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 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
2335 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
2336 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2337 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 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
2341 `setq' the value back into where it came from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (plist, nil_means_not_present)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 Lisp_Object plist, nil_means_not_present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 Lisp_Object head = plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 Fcheck_valid_plist (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 while (!NILP (plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 Lisp_Object prop = Fcar (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 Lisp_Object next = Fcdr (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 CHECK_CONS (next); /* just make doubly sure we catch any errors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 if (EQ (head, plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 head = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 /* external_remprop returns 1 if it removed any property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 We have to loop till it didn't remove anything, in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 the property occurs many times. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 DEFUN ("lax-plist-get", Flax_plist_get, Slax_plist_get, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 Extract a value from a lax property list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 VALUE1 PROP2 VALUE2...), where comparions between properties is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 using `equal' instead of `eq'. This function returns the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 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
2380 properties on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (lax_plist, prop, defalt) /* Cant spel in C */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 Lisp_Object lax_plist, prop, defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 Lisp_Object val = external_plist_get (&lax_plist, prop, 1, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 if (UNBOUNDP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 return defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 return val;
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 DEFUN ("lax-plist-put", Flax_plist_put, Slax_plist_put, 3, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 Change value in LAX-PLIST of PROP to VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 VALUE1 PROP2 VALUE2...), where comparions between properties is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 using `equal' instead of `eq'. PROP is usually a symbol and VAL is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 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
2397 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
2398 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
2399 use the new value. The LAX-PLIST is modified by side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (lax_plist, prop, val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 Lisp_Object lax_plist, prop, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 external_plist_put (&lax_plist, prop, val, 1, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 return lax_plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 DEFUN ("lax-plist-remprop", Flax_plist_remprop, Slax_plist_remprop, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 Remove from LAX-PLIST the property PROP and its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 VALUE1 PROP2 VALUE2...), where comparions between properties is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 using `equal' instead of `eq'. PROP is usually a symbol. The new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 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
2414 sure to use the new value. The LAX-PLIST is modified by side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (lax_plist, prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 Lisp_Object lax_plist, prop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 external_remprop (&lax_plist, prop, 1, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 return lax_plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 DEFUN ("lax-plist-member", Flax_plist_member, Slax_plist_member, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 Return t if PROP has a value specified in LAX-PLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 LAX-PLIST is a lax property list, which is a list of the form \(PROP1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 VALUE1 PROP2 VALUE2...), where comparions between properties is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 using `equal' instead of `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (lax_plist, prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 Lisp_Object lax_plist, prop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 return UNBOUNDP (Flax_plist_get (lax_plist, prop, Qunbound)) ? Qnil : Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 Scanonicalize_lax_plist, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 Destructively remove any duplicate entries from a lax plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 In such cases, the first entry applies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 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
2441 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
2442 old Lisp implementations, but should not be used except for backward
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2443 compatibility.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 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
2447 `setq' the value back into where it came from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (lax_plist, nil_means_not_present)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 Lisp_Object lax_plist, nil_means_not_present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 Lisp_Object head = lax_plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 Fcheck_valid_plist (lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 while (!NILP (lax_plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 Lisp_Object prop = Fcar (lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 Lisp_Object next = Fcdr (lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 CHECK_CONS (next); /* just make doubly sure we catch any errors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 if (!NILP (nil_means_not_present) && NILP (Fcar (next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 if (EQ (head, lax_plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 head = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 lax_plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 /* external_remprop returns 1 if it removed any property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 We have to loop till it didn't remove anything, in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 the property occurs many times. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 lax_plist = Fcdr (next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 /* In C because the frame props stuff uses it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 Sdestructive_alist_to_plist, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 Convert association list ALIST into the equivalent property-list form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 The plist is returned. This converts from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 \((a . 1) (b . 2) (c . 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 \(a 1 b 2 c 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 The original alist is destroyed in the process of constructing the plist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 See also `alist-to-plist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 Lisp_Object alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 Lisp_Object head = alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 while (!NILP (alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 /* remember the alist element. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 Lisp_Object el = Fcar (alist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 Fsetcar (alist, Fcar (el));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 Fsetcar (el, Fcdr (el));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 Fsetcdr (el, Fcdr (alist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 Fsetcdr (alist, el);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 alist = Fcdr (Fcdr (alist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 return head;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 /* Symbol plists are directly accessible, so we need to protect against
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 invalid property list structure */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 symbol_getprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object defalt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 Lisp_Object val = external_plist_get (&XSYMBOL (sym)->plist, propname,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 if (UNBOUNDP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 return defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 symbol_putprop (Lisp_Object sym, Lisp_Object propname, Lisp_Object value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 external_plist_put (&XSYMBOL (sym)->plist, propname, value, 0, ERROR_ME);
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 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 symbol_remprop (Lisp_Object symbol, Lisp_Object propname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 return external_remprop (&XSYMBOL (symbol)->plist, propname, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 /* We store the string's extent info as the first element of the string's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 property list; and the string's MODIFF as the first or second element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 of the string's property list (depending on whether the extent info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 is present), but only if the string has been modified. This is ugly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 but it reduces the memory allocated for the string in the vast
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 majority of cases, where the string is never modified and has no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 extent info. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 static Lisp_Object *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 string_plist_ptr (struct Lisp_String *s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 Lisp_Object *ptr = &s->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 ptr = &XCDR (*ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ptr = &XCDR (*ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 return ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 string_getprop (struct Lisp_String *s, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 Lisp_Object defalt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 Lisp_Object val = external_plist_get (string_plist_ptr (s), property, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 if (UNBOUNDP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 return defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 string_putprop (struct Lisp_String *s, Lisp_Object property,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 Lisp_Object value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 external_plist_put (string_plist_ptr (s), property, value, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 string_remprop (struct Lisp_String *s, Lisp_Object property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 return external_remprop (string_plist_ptr (s), property, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 string_plist (struct Lisp_String *s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 return *string_plist_ptr (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 DEFUN ("get", Fget, Sget, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 Return the value of OBJECT's PROPNAME property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 This is the last VALUE stored with `(put OBJECT PROPNAME VALUE)'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 If there is no such property, return optional third arg DEFAULT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (which defaults to `nil'). OBJECT can be a symbol, face, extent,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 or string. See also `put', `remprop', and `object-plist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (object, propname, defalt) /* Cant spel in C */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 Lisp_Object object, propname, defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 /* Various places in emacs call Fget() and expect it not to quit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 so don't quit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 /* It's easiest to treat symbols specially because they may not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 be an lrecord */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 if (SYMBOLP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 val = symbol_getprop (object, propname, defalt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 else if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 val = string_getprop (XSTRING (object), propname, defalt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 else if (LRECORDP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 CONST struct lrecord_implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 *imp = XRECORD_LHEADER (object)->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 if (imp->getprop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 val = (imp->getprop) (object, propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 if (UNBOUNDP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 val = defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 goto noprops;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 noprops:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 signal_simple_error ("Object type has no properties", object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 DEFUN ("put", Fput, Sput, 3, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 Store OBJECT's PROPNAME property with value VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 It can be retrieved with `(get OBJECT PROPNAME)'. OBJECT can be a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 symbol, face, extent, or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 For a string, no properties currently have predefined meanings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 For the predefined properties for extents, see `set-extent-property'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 For the predefined properties for faces, see `set-face-property'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 See also `get', `remprop', and `object-plist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (object, propname, value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 Lisp_Object object;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 Lisp_Object propname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 Lisp_Object value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 CHECK_SYMBOL (propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 CHECK_IMPURE (object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 if (SYMBOLP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 symbol_putprop (object, propname, value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 else if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 string_putprop (XSTRING (object), propname, value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 else if (LRECORDP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 CONST struct lrecord_implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 *imp = XRECORD_LHEADER (object)->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 if (imp->putprop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 if (! (imp->putprop) (object, propname, value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 signal_simple_error ("Can't set property on object", propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 goto noprops;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 noprops:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 signal_simple_error ("Object type has no settable properties", object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 pure_put (Lisp_Object sym, Lisp_Object prop, Lisp_Object val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 Fput (sym, prop, Fpurecopy (val));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 DEFUN ("remprop", Fremprop, Sremprop, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 Remove from OBJECT's property list the property PROPNAME and its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 value. OBJECT can be a symbol, face, extent, or string. Returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 non-nil if the property list was actually changed (i.e. if PROPNAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 was present in the property list). See also `get', `put', and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 `object-plist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (object, propname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 Lisp_Object object, propname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 int retval = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 CHECK_SYMBOL (propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 CHECK_IMPURE (object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 if (SYMBOLP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 retval = symbol_remprop (object, propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 else if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 retval = string_remprop (XSTRING (object), propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 else if (LRECORDP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 CONST struct lrecord_implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 *imp = XRECORD_LHEADER (object)->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 if (imp->remprop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 retval = (imp->remprop) (object, propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 if (retval == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 signal_simple_error ("Can't remove property from object",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 propname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 goto noprops;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 noprops:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 signal_simple_error ("Object type has no removable properties", object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 return retval ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 DEFUN ("object-plist", Fobject_plist, Sobject_plist, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 Return a property list of OBJECT's props.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 For a symbol this is equivalent to `symbol-plist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 Do not modify the property list directly; this may or may not have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 the desired effects. (In particular, for a property with a special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 interpretation, this will probably have no effect at all.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 Lisp_Object object;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 if (SYMBOLP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 return Fsymbol_plist (object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 else if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 return string_plist (XSTRING (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 else if (LRECORDP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 CONST struct lrecord_implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 *imp = XRECORD_LHEADER (object)->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 if (imp->plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 return (imp->plist) (object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 signal_simple_error ("Object type has no properties", object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 signal_simple_error ("Object type has no properties", object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 internal_equal (Lisp_Object o1, Lisp_Object o2, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 if (depth > 200)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 error ("Stack overflow in equal");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 do_cdr:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 if (HACKEQ_UNSAFE (o1, o2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 return (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 /* Note that (equal 20 20.0) should be nil */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 else if (XTYPE (o1) != XTYPE (o2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 else if (CONSP (o1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 if (!internal_equal (Fcar (o1), Fcar (o2), depth + 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 o1 = Fcdr (o1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 o2 = Fcdr (o2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 goto do_cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 #ifndef LRECORD_VECTOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 else if (VECTORP (o1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 int indecks;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 int len = vector_length (XVECTOR (o1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 if (len != vector_length (XVECTOR (o2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 for (indecks = 0; indecks < len; indecks++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 Lisp_Object v1, v2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 v1 = vector_data (XVECTOR (o1)) [indecks];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 v2 = vector_data (XVECTOR (o2)) [indecks];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 if (!internal_equal (v1, v2, depth + 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 return (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 #endif /* !LRECORD_VECTOR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 else if (STRINGP (o1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
2796 Bytecount len = XSTRING_LENGTH (o1);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
2797 if (len != XSTRING_LENGTH (o2))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 return (0);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 10
diff changeset
2799 if (memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 return (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 else if (LRECORDP (o1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 CONST struct lrecord_implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 *imp1 = XRECORD_LHEADER (o1)->implementation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 *imp2 = XRECORD_LHEADER (o2)->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 if (imp1 != imp2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 else if (imp1->equal == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 /* EQ-ness of the objects was noticed above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 return ((imp1->equal) (o1, o2, depth));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 DEFUN ("equal", Fequal, Sequal, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 T if two Lisp objects have similar structure and contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 They must have the same data type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 Conses are compared by comparing the cars and the cdrs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 Vectors and strings are compared element by element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 Numbers are compared by value. Symbols must match exactly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (o1, o2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 Lisp_Object o1, o2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 return ((internal_equal (o1, o2, 0)) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 Store each element of ARRAY with ITEM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 ARRAY is a vector, bit vector, or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (array, item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 Lisp_Object array, item;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 retry:
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2842 if (STRINGP (array))
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2843 {
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2844 Charcount size;
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2845 Charcount i;
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2846 Emchar charval;
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2847 struct Lisp_String *s;
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2848 CHECK_CHAR_COERCE_INT (item);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2849 CHECK_IMPURE (array);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2850 charval = XCHAR (item);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2851 s = XSTRING (array);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2852 size = string_char_length (s);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2853 for (i = 0; i < size; i++)
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2854 set_string_char (s, i, charval);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2855 bump_string_modiff (array);
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2856 }
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2857 else if (VECTORP (array))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 Lisp_Object *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 int size;
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2861 int i;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 CHECK_IMPURE (array);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 size = vector_length (XVECTOR (array));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 p = vector_data (XVECTOR (array));
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2865 for (i = 0; i < size; i++)
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2866 p[i] = item;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 }
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2868 else if (BIT_VECTORP (array))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 struct Lisp_Bit_Vector *v;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 int size;
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2872 int i;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 CHECK_BIT (item);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 CHECK_IMPURE (array);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 v = XBIT_VECTOR (array);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 size = bit_vector_length (v);
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2877 for (i = 0; i < size; i++)
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 2
diff changeset
2878 set_bit_vector_bit (v, i, XINT (item));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 array = wrong_type_argument (Qarrayp, array);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 return array;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 nconc2 (Lisp_Object s1, Lisp_Object s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 args[0] = s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 args[1] = s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 return Fnconc (2, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 Concatenate any number of lists by altering them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 Only the last argument is not altered, and need not be a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 (nargs, args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 int argnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 Lisp_Object tail, tem, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 /* The modus operandi in Emacs is "caller gc-protects args".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 However, nconc (particularly nconc2 ()) is called many times
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 in Emacs on freshly created stuff (e.g. you see the idiom
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 callers out by protecting the args ourselves to save them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 a lot of temporary-variable grief. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 GCPRO1 (args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 gcpro1.nvars = nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 for (argnum = 0; argnum < nargs; argnum++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 tem = args[argnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 if (NILP (tem)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 if (NILP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 val = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 if (argnum + 1 == nargs) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 if (!CONSP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 tem = wrong_type_argument (Qlistp, tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 while (CONSP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 tail = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 tem = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 tem = args[argnum + 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 Fsetcdr (tail, tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 args[argnum + 1] = tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 RETURN_UNGCPRO (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 /* This is the guts of all mapping functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 Apply fn to each element of seq, one by one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 storing the results into elements of vals, a C vector of Lisp_Objects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 leni is the length of vals, which should also be the length of seq.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 If VALS is a null pointer, do not accumulate the results. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 Lisp_Object dummy = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 Lisp_Object result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 GCPRO3 (dummy, fn, seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 if (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 /* Don't let vals contain any garbage when GC happens. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 for (i = 0; i < leni; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 vals[i] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 gcpro1.var = vals;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 gcpro1.nvars = leni;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 /* We need not explicitly protect `tail' because it is used only on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 lists, and 1) lists are not relocated and 2) the list is marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 via `seq' so will not be freed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 if (VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 for (i = 0; i < leni; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 dummy = vector_data (XVECTOR (seq))[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 result = call1 (fn, dummy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 if (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 vals[i] = result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 else if (BIT_VECTORP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 struct Lisp_Bit_Vector *v = XBIT_VECTOR (seq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 for (i = 0; i < leni; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 XSETINT (dummy, bit_vector_bit (v, i));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 result = call1 (fn, dummy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 if (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 vals[i] = result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 else if (STRINGP (seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 for (i = 0; i < leni; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 result = call1 (fn, make_char (string_char (XSTRING (seq), i)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 if (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 vals[i] = result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 else /* Must be a list, since Flength did not get an error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 tail = seq;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 for (i = 0; i < leni; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 result = call1 (fn, Fcar (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 if (vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 vals[i] = result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 tail = Fcdr (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 DEFUN ("mapconcat", Fmapconcat, Smapconcat, 3, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 Apply FN to each element of SEQ, and concat the results as strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 In between each pair of results, stick in SEP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 Thus, \" \" as SEP results in spaces between the values returned by FN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (fn, seq, sep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 Lisp_Object fn, seq, sep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3035 int len = XINT (Flength (seq));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3041 nargs = len + len - 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 if (nargs < 0) return build_string ("");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 GCPRO1 (sep);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3047 mapcar1 (len, args, fn, seq);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3050 for (i = len - 1; i >= 0; i--)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 args[i + i] = args[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 for (i = 1; i < nargs; i += 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 args[i] = sep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 return Fconcat (nargs, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 The result is a list just as long as SEQUENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 SEQUENCE may be a list, a vector, a bit vector, or a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 (fn, seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 Lisp_Object fn, seq;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3067 int len = XINT (Flength (seq));
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3068 Lisp_Object *args = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3069
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3070 mapcar1 (len, args, fn, seq);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3071
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3072 return Flist (len, args);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 DEFUN ("mapc-internal", Fmapc_internal, Smapc_internal, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 Apply FUNCTION to each element of SEQUENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 SEQUENCE may be a list, a vector, a bit vector, or a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 This function is like `mapcar' but does not accumulate the results,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 which is more efficient if you do not use the results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (fn, seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 Lisp_Object fn, seq;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3084 mapcar1 (XINT (Flength (seq)), 0, fn, seq);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 /* #### this function doesn't belong in this file! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 DEFUN ("load-average", Fload_average, Sload_average, 0, 0, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 Return list of 1 minute, 5 minute and 15 minute load averages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 Each of the three load averages is multiplied by 100,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 then converted to integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 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
3098 shortened list, containing only those averages which are available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 On most systems, this won't work unless the emacs executable is installed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 as setgid kmem (assuming that /dev/kmem is in the group kmem).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 double load_ave[10]; /* hey, just in case */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 int loads = getloadavg (load_ave, 3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 Lisp_Object ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 if (loads == -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 error ("load-average not implemented for this operating system.");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 else if (loads < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 error ("could not get load-average; check permissions.");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 ret = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 while (loads > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 ret = Fcons (make_int ((int) (load_ave[--loads] * 100.0)), ret);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 return ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 Lisp_Object Vfeatures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 DEFUN ("featurep", Ffeaturep, Sfeaturep, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 Return t if FEATURE is present in this Emacs.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3126 Use this to conditionalize execution of lisp code based on the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3127 presence or absence of emacs or environment extensions.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 Use `provide' to declare that a feature is available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 This function looks at the value of the variable `features'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 (feature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 Lisp_Object feature;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 CHECK_SYMBOL (feature);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3135 return NILP (Fmemq (feature, Vfeatures)) ? Qnil : Qt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 Announce that FEATURE is a feature of the current Emacs.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3140 This function updates the value of the variable `features'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (feature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 Lisp_Object feature;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 CHECK_SYMBOL (feature);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 if (!NILP (Vautoload_queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 tem = Fmemq (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 Vfeatures = Fcons (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 LOADHIST_ATTACH (Fcons (Qprovide, feature));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 return feature;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 DEFUN ("require", Frequire, Srequire, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 If feature FEATURE is not loaded, load it from FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 If FEATURE is not a member of the list `features', then the feature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 is not loaded; so load the file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 If FILENAME is omitted, the printname of FEATURE is used as the file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 (feature, file_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 Lisp_Object feature, file_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 CHECK_SYMBOL (feature);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 tem = Fmemq (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 LOADHIST_ATTACH (Fcons (Qrequire, feature));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 if (!NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 return (feature);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 /* Value saved here is to be restored into Vautoload_queue */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 record_unwind_protect (un_autoload, Vautoload_queue);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 Vautoload_queue = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 call4 (Qload, NILP (file_name) ? Fsymbol_name (feature) : file_name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 Qnil, Qt, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 tem = Fmemq (feature, Vfeatures);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 error ("Required feature %s was not provided",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 string_data (XSYMBOL (feature)->name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 /* Once loading finishes, don't undo it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 Vautoload_queue = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 return (unbind_to (speccount, feature));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 Lisp_Object Qyes_or_no_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 syms_of_fns (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 defsymbol (&Qstring_lessp, "string-lessp");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 defsymbol (&Qidentity, "identity");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 defsymbol (&Qyes_or_no_p, "yes-or-no-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 defsubr (&Sidentity);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 defsubr (&Srandom);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 defsubr (&Slength);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 defsubr (&Ssafe_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 defsubr (&Sstring_equal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 defsubr (&Sstring_lessp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 defsubr (&Sstring_modified_tick);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 defsubr (&Sappend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 defsubr (&Sconcat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 defsubr (&Svconcat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 defsubr (&Sbvconcat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 defsubr (&Scopy_sequence);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 defsubr (&Scopy_alist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 defsubr (&Scopy_tree);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 defsubr (&Ssubstring);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 defsubr (&Ssubseq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 defsubr (&Snthcdr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 defsubr (&Snth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 defsubr (&Selt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 defsubr (&Smember);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 defsubr (&Smemq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 defsubr (&Sassoc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 defsubr (&Sassq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 defsubr (&Srassoc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 defsubr (&Srassq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 defsubr (&Sdelete);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 defsubr (&Sdelq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 defsubr (&Sremassoc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 defsubr (&Sremassq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 defsubr (&Sremrassoc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 defsubr (&Sremrassq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 defsubr (&Snreverse);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 defsubr (&Sreverse);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 defsubr (&Ssort);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 defsubr (&Splists_eq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 defsubr (&Splists_equal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 defsubr (&Slax_plists_eq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 defsubr (&Slax_plists_equal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 defsubr (&Splist_get);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 defsubr (&Splist_put);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 defsubr (&Splist_remprop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 defsubr (&Splist_member);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 defsubr (&Scheck_valid_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 defsubr (&Svalid_plist_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 defsubr (&Scanonicalize_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 defsubr (&Slax_plist_get);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 defsubr (&Slax_plist_put);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 defsubr (&Slax_plist_remprop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 defsubr (&Slax_plist_member);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 defsubr (&Scanonicalize_lax_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 defsubr (&Sdestructive_alist_to_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 defsubr (&Sget);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 defsubr (&Sput);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 defsubr (&Sremprop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 defsubr (&Sobject_plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 defsubr (&Sequal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 defsubr (&Sfillarray);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 defsubr (&Snconc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 defsubr (&Smapcar);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 defsubr (&Smapc_internal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 defsubr (&Smapconcat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 defsubr (&Sload_average);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 defsubr (&Sfeaturep);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 defsubr (&Srequire);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 defsubr (&Sprovide);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 init_provide_once (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 DEFVAR_LISP ("features", &Vfeatures /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 A list of symbols which are the features of the executing emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 Used by `featurep' and `require', and altered by `provide'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 Vfeatures = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 }