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