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