| 1 | /* Lisp parsing and input streams. |
| 2 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995, |
| 3 | 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
| 4 | 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
| 5 | |
| 6 | This file is part of GNU Emacs. |
| 7 | |
| 8 | GNU Emacs is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | GNU Emacs is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | |
| 22 | #include <config.h> |
| 23 | #include <stdio.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/file.h> |
| 27 | #include <errno.h> |
| 28 | #include <setjmp.h> |
| 29 | #include "lisp.h" |
| 30 | #include "intervals.h" |
| 31 | #include "buffer.h" |
| 32 | #include "character.h" |
| 33 | #include "charset.h" |
| 34 | #include "coding.h" |
| 35 | #include <epaths.h> |
| 36 | #include "commands.h" |
| 37 | #include "keyboard.h" |
| 38 | #include "frame.h" |
| 39 | #include "termhooks.h" |
| 40 | #include "coding.h" |
| 41 | #include "blockinput.h" |
| 42 | |
| 43 | #ifdef MSDOS |
| 44 | #include "msdos.h" |
| 45 | #endif |
| 46 | |
| 47 | #ifdef HAVE_UNISTD_H |
| 48 | #include <unistd.h> |
| 49 | #endif |
| 50 | |
| 51 | #include <math.h> |
| 52 | |
| 53 | #ifdef HAVE_SETLOCALE |
| 54 | #include <locale.h> |
| 55 | #endif /* HAVE_SETLOCALE */ |
| 56 | |
| 57 | #ifdef HAVE_FCNTL_H |
| 58 | #include <fcntl.h> |
| 59 | #endif |
| 60 | #ifndef O_RDONLY |
| 61 | #define O_RDONLY 0 |
| 62 | #endif |
| 63 | |
| 64 | #ifdef HAVE_FSEEKO |
| 65 | #define file_offset off_t |
| 66 | #define file_tell ftello |
| 67 | #else |
| 68 | #define file_offset long |
| 69 | #define file_tell ftell |
| 70 | #endif |
| 71 | |
| 72 | /* hash table read constants */ |
| 73 | Lisp_Object Qhash_table, Qdata; |
| 74 | Lisp_Object Qtest, Qsize; |
| 75 | Lisp_Object Qweakness; |
| 76 | Lisp_Object Qrehash_size; |
| 77 | Lisp_Object Qrehash_threshold; |
| 78 | extern Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness; |
| 79 | |
| 80 | Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list; |
| 81 | Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist; |
| 82 | Lisp_Object Qascii_character, Qload, Qload_file_name; |
| 83 | Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; |
| 84 | Lisp_Object Qinhibit_file_name_operation; |
| 85 | Lisp_Object Qeval_buffer_list, Veval_buffer_list; |
| 86 | Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */ |
| 87 | |
| 88 | /* Used instead of Qget_file_char while loading *.elc files compiled |
| 89 | by Emacs 21 or older. */ |
| 90 | static Lisp_Object Qget_emacs_mule_file_char; |
| 91 | |
| 92 | static Lisp_Object Qload_force_doc_strings; |
| 93 | |
| 94 | extern Lisp_Object Qevent_symbol_element_mask; |
| 95 | extern Lisp_Object Qfile_exists_p; |
| 96 | |
| 97 | /* non-zero if inside `load' */ |
| 98 | int load_in_progress; |
| 99 | static Lisp_Object Qload_in_progress; |
| 100 | |
| 101 | /* Directory in which the sources were found. */ |
| 102 | Lisp_Object Vsource_directory; |
| 103 | |
| 104 | /* Search path and suffixes for files to be loaded. */ |
| 105 | Lisp_Object Vload_path, Vload_suffixes, Vload_file_rep_suffixes; |
| 106 | |
| 107 | /* File name of user's init file. */ |
| 108 | Lisp_Object Vuser_init_file; |
| 109 | |
| 110 | /* This is the user-visible association list that maps features to |
| 111 | lists of defs in their load files. */ |
| 112 | Lisp_Object Vload_history; |
| 113 | |
| 114 | /* This is used to build the load history. */ |
| 115 | Lisp_Object Vcurrent_load_list; |
| 116 | |
| 117 | /* List of files that were preloaded. */ |
| 118 | Lisp_Object Vpreloaded_file_list; |
| 119 | |
| 120 | /* Name of file actually being read by `load'. */ |
| 121 | Lisp_Object Vload_file_name; |
| 122 | |
| 123 | /* Function to use for reading, in `load' and friends. */ |
| 124 | Lisp_Object Vload_read_function; |
| 125 | |
| 126 | /* Non-nil means read recursive structures using #n= and #n# syntax. */ |
| 127 | Lisp_Object Vread_circle; |
| 128 | |
| 129 | /* The association list of objects read with the #n=object form. |
| 130 | Each member of the list has the form (n . object), and is used to |
| 131 | look up the object for the corresponding #n# construct. |
| 132 | It must be set to nil before all top-level calls to read0. */ |
| 133 | Lisp_Object read_objects; |
| 134 | |
| 135 | /* Nonzero means load should forcibly load all dynamic doc strings. */ |
| 136 | static int load_force_doc_strings; |
| 137 | |
| 138 | /* Nonzero means read should convert strings to unibyte. */ |
| 139 | static int load_convert_to_unibyte; |
| 140 | |
| 141 | /* Nonzero means READCHAR should read bytes one by one (not character) |
| 142 | when READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char. |
| 143 | This is set to 1 by read1 temporarily while handling #@NUMBER. */ |
| 144 | static int load_each_byte; |
| 145 | |
| 146 | /* Function to use for loading an Emacs Lisp source file (not |
| 147 | compiled) instead of readevalloop. */ |
| 148 | Lisp_Object Vload_source_file_function; |
| 149 | |
| 150 | /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */ |
| 151 | Lisp_Object Vbyte_boolean_vars; |
| 152 | |
| 153 | /* Whether or not to add a `read-positions' property to symbols |
| 154 | read. */ |
| 155 | Lisp_Object Vread_with_symbol_positions; |
| 156 | |
| 157 | /* List of (SYMBOL . POSITION) accumulated so far. */ |
| 158 | Lisp_Object Vread_symbol_positions_list; |
| 159 | |
| 160 | /* List of descriptors now open for Fload. */ |
| 161 | static Lisp_Object load_descriptor_list; |
| 162 | |
| 163 | /* File for get_file_char to read from. Use by load. */ |
| 164 | static FILE *instream; |
| 165 | |
| 166 | /* When nonzero, read conses in pure space */ |
| 167 | static int read_pure; |
| 168 | |
| 169 | /* For use within read-from-string (this reader is non-reentrant!!) */ |
| 170 | static int read_from_string_index; |
| 171 | static int read_from_string_index_byte; |
| 172 | static int read_from_string_limit; |
| 173 | |
| 174 | /* Number of characters read in the current call to Fread or |
| 175 | Fread_from_string. */ |
| 176 | static int readchar_count; |
| 177 | |
| 178 | /* This contains the last string skipped with #@. */ |
| 179 | static char *saved_doc_string; |
| 180 | /* Length of buffer allocated in saved_doc_string. */ |
| 181 | static int saved_doc_string_size; |
| 182 | /* Length of actual data in saved_doc_string. */ |
| 183 | static int saved_doc_string_length; |
| 184 | /* This is the file position that string came from. */ |
| 185 | static file_offset saved_doc_string_position; |
| 186 | |
| 187 | /* This contains the previous string skipped with #@. |
| 188 | We copy it from saved_doc_string when a new string |
| 189 | is put in saved_doc_string. */ |
| 190 | static char *prev_saved_doc_string; |
| 191 | /* Length of buffer allocated in prev_saved_doc_string. */ |
| 192 | static int prev_saved_doc_string_size; |
| 193 | /* Length of actual data in prev_saved_doc_string. */ |
| 194 | static int prev_saved_doc_string_length; |
| 195 | /* This is the file position that string came from. */ |
| 196 | static file_offset prev_saved_doc_string_position; |
| 197 | |
| 198 | /* Nonzero means inside a new-style backquote |
| 199 | with no surrounding parentheses. |
| 200 | Fread initializes this to zero, so we need not specbind it |
| 201 | or worry about what happens to it when there is an error. */ |
| 202 | static int new_backquote_flag; |
| 203 | static Lisp_Object Vold_style_backquotes, Qold_style_backquotes; |
| 204 | |
| 205 | /* A list of file names for files being loaded in Fload. Used to |
| 206 | check for recursive loads. */ |
| 207 | |
| 208 | static Lisp_Object Vloads_in_progress; |
| 209 | |
| 210 | /* Non-zero means load dangerous compiled Lisp files. */ |
| 211 | |
| 212 | int load_dangerous_libraries; |
| 213 | |
| 214 | /* Non-zero means force printing messages when loading Lisp files. */ |
| 215 | |
| 216 | int force_load_messages; |
| 217 | |
| 218 | /* A regular expression used to detect files compiled with Emacs. */ |
| 219 | |
| 220 | static Lisp_Object Vbytecomp_version_regexp; |
| 221 | |
| 222 | static int read_emacs_mule_char (int, int (*) (int, Lisp_Object), |
| 223 | Lisp_Object); |
| 224 | |
| 225 | static void readevalloop (Lisp_Object, FILE*, Lisp_Object, |
| 226 | Lisp_Object (*) (), int, |
| 227 | Lisp_Object, Lisp_Object, |
| 228 | Lisp_Object, Lisp_Object); |
| 229 | static Lisp_Object load_unwind (Lisp_Object); |
| 230 | static Lisp_Object load_descriptor_unwind (Lisp_Object); |
| 231 | |
| 232 | static void invalid_syntax (const char *, int) NO_RETURN; |
| 233 | static void end_of_file_error (void) NO_RETURN; |
| 234 | |
| 235 | \f |
| 236 | /* Functions that read one byte from the current source READCHARFUN |
| 237 | or unreads one byte. If the integer argument C is -1, it returns |
| 238 | one read byte, or -1 when there's no more byte in the source. If C |
| 239 | is 0 or positive, it unreads C, and the return value is not |
| 240 | interesting. */ |
| 241 | |
| 242 | static int readbyte_for_lambda (int, Lisp_Object); |
| 243 | static int readbyte_from_file (int, Lisp_Object); |
| 244 | static int readbyte_from_string (int, Lisp_Object); |
| 245 | |
| 246 | /* Handle unreading and rereading of characters. |
| 247 | Write READCHAR to read a character, |
| 248 | UNREAD(c) to unread c to be read again. |
| 249 | |
| 250 | These macros correctly read/unread multibyte characters. */ |
| 251 | |
| 252 | #define READCHAR readchar (readcharfun, NULL) |
| 253 | #define UNREAD(c) unreadchar (readcharfun, c) |
| 254 | |
| 255 | /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */ |
| 256 | #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte) |
| 257 | |
| 258 | /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char, |
| 259 | Qlambda, or a cons, we use this to keep an unread character because |
| 260 | a file stream can't handle multibyte-char unreading. The value -1 |
| 261 | means that there's no unread character. */ |
| 262 | static int unread_char; |
| 263 | |
| 264 | static int |
| 265 | readchar (Lisp_Object readcharfun, int *multibyte) |
| 266 | { |
| 267 | Lisp_Object tem; |
| 268 | register int c; |
| 269 | int (*readbyte) (int, Lisp_Object); |
| 270 | unsigned char buf[MAX_MULTIBYTE_LENGTH]; |
| 271 | int i, len; |
| 272 | int emacs_mule_encoding = 0; |
| 273 | |
| 274 | if (multibyte) |
| 275 | *multibyte = 0; |
| 276 | |
| 277 | readchar_count++; |
| 278 | |
| 279 | if (BUFFERP (readcharfun)) |
| 280 | { |
| 281 | register struct buffer *inbuffer = XBUFFER (readcharfun); |
| 282 | |
| 283 | int pt_byte = BUF_PT_BYTE (inbuffer); |
| 284 | |
| 285 | if (pt_byte >= BUF_ZV_BYTE (inbuffer)) |
| 286 | return -1; |
| 287 | |
| 288 | if (! NILP (inbuffer->enable_multibyte_characters)) |
| 289 | { |
| 290 | /* Fetch the character code from the buffer. */ |
| 291 | unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte); |
| 292 | BUF_INC_POS (inbuffer, pt_byte); |
| 293 | c = STRING_CHAR (p); |
| 294 | if (multibyte) |
| 295 | *multibyte = 1; |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | c = BUF_FETCH_BYTE (inbuffer, pt_byte); |
| 300 | if (! ASCII_BYTE_P (c)) |
| 301 | c = BYTE8_TO_CHAR (c); |
| 302 | pt_byte++; |
| 303 | } |
| 304 | SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte); |
| 305 | |
| 306 | return c; |
| 307 | } |
| 308 | if (MARKERP (readcharfun)) |
| 309 | { |
| 310 | register struct buffer *inbuffer = XMARKER (readcharfun)->buffer; |
| 311 | |
| 312 | int bytepos = marker_byte_position (readcharfun); |
| 313 | |
| 314 | if (bytepos >= BUF_ZV_BYTE (inbuffer)) |
| 315 | return -1; |
| 316 | |
| 317 | if (! NILP (inbuffer->enable_multibyte_characters)) |
| 318 | { |
| 319 | /* Fetch the character code from the buffer. */ |
| 320 | unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos); |
| 321 | BUF_INC_POS (inbuffer, bytepos); |
| 322 | c = STRING_CHAR (p); |
| 323 | if (multibyte) |
| 324 | *multibyte = 1; |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | c = BUF_FETCH_BYTE (inbuffer, bytepos); |
| 329 | if (! ASCII_BYTE_P (c)) |
| 330 | c = BYTE8_TO_CHAR (c); |
| 331 | bytepos++; |
| 332 | } |
| 333 | |
| 334 | XMARKER (readcharfun)->bytepos = bytepos; |
| 335 | XMARKER (readcharfun)->charpos++; |
| 336 | |
| 337 | return c; |
| 338 | } |
| 339 | |
| 340 | if (EQ (readcharfun, Qlambda)) |
| 341 | { |
| 342 | readbyte = readbyte_for_lambda; |
| 343 | goto read_multibyte; |
| 344 | } |
| 345 | |
| 346 | if (EQ (readcharfun, Qget_file_char)) |
| 347 | { |
| 348 | readbyte = readbyte_from_file; |
| 349 | goto read_multibyte; |
| 350 | } |
| 351 | |
| 352 | if (STRINGP (readcharfun)) |
| 353 | { |
| 354 | if (read_from_string_index >= read_from_string_limit) |
| 355 | c = -1; |
| 356 | else if (STRING_MULTIBYTE (readcharfun)) |
| 357 | { |
| 358 | if (multibyte) |
| 359 | *multibyte = 1; |
| 360 | FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, readcharfun, |
| 361 | read_from_string_index, |
| 362 | read_from_string_index_byte); |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | c = SREF (readcharfun, read_from_string_index_byte); |
| 367 | read_from_string_index++; |
| 368 | read_from_string_index_byte++; |
| 369 | } |
| 370 | return c; |
| 371 | } |
| 372 | |
| 373 | if (CONSP (readcharfun)) |
| 374 | { |
| 375 | /* This is the case that read_vector is reading from a unibyte |
| 376 | string that contains a byte sequence previously skipped |
| 377 | because of #@NUMBER. The car part of readcharfun is that |
| 378 | string, and the cdr part is a value of readcharfun given to |
| 379 | read_vector. */ |
| 380 | readbyte = readbyte_from_string; |
| 381 | if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char)) |
| 382 | emacs_mule_encoding = 1; |
| 383 | goto read_multibyte; |
| 384 | } |
| 385 | |
| 386 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) |
| 387 | { |
| 388 | readbyte = readbyte_from_file; |
| 389 | emacs_mule_encoding = 1; |
| 390 | goto read_multibyte; |
| 391 | } |
| 392 | |
| 393 | tem = call0 (readcharfun); |
| 394 | |
| 395 | if (NILP (tem)) |
| 396 | return -1; |
| 397 | return XINT (tem); |
| 398 | |
| 399 | read_multibyte: |
| 400 | if (unread_char >= 0) |
| 401 | { |
| 402 | c = unread_char; |
| 403 | unread_char = -1; |
| 404 | return c; |
| 405 | } |
| 406 | c = (*readbyte) (-1, readcharfun); |
| 407 | if (c < 0 || load_each_byte) |
| 408 | return c; |
| 409 | if (multibyte) |
| 410 | *multibyte = 1; |
| 411 | if (ASCII_BYTE_P (c)) |
| 412 | return c; |
| 413 | if (emacs_mule_encoding) |
| 414 | return read_emacs_mule_char (c, readbyte, readcharfun); |
| 415 | i = 0; |
| 416 | buf[i++] = c; |
| 417 | len = BYTES_BY_CHAR_HEAD (c); |
| 418 | while (i < len) |
| 419 | { |
| 420 | c = (*readbyte) (-1, readcharfun); |
| 421 | if (c < 0 || ! TRAILING_CODE_P (c)) |
| 422 | { |
| 423 | while (--i > 1) |
| 424 | (*readbyte) (buf[i], readcharfun); |
| 425 | return BYTE8_TO_CHAR (buf[0]); |
| 426 | } |
| 427 | buf[i++] = c; |
| 428 | } |
| 429 | return STRING_CHAR (buf); |
| 430 | } |
| 431 | |
| 432 | /* Unread the character C in the way appropriate for the stream READCHARFUN. |
| 433 | If the stream is a user function, call it with the char as argument. */ |
| 434 | |
| 435 | static void |
| 436 | unreadchar (Lisp_Object readcharfun, int c) |
| 437 | { |
| 438 | readchar_count--; |
| 439 | if (c == -1) |
| 440 | /* Don't back up the pointer if we're unreading the end-of-input mark, |
| 441 | since readchar didn't advance it when we read it. */ |
| 442 | ; |
| 443 | else if (BUFFERP (readcharfun)) |
| 444 | { |
| 445 | struct buffer *b = XBUFFER (readcharfun); |
| 446 | int bytepos = BUF_PT_BYTE (b); |
| 447 | |
| 448 | BUF_PT (b)--; |
| 449 | if (! NILP (b->enable_multibyte_characters)) |
| 450 | BUF_DEC_POS (b, bytepos); |
| 451 | else |
| 452 | bytepos--; |
| 453 | |
| 454 | BUF_PT_BYTE (b) = bytepos; |
| 455 | } |
| 456 | else if (MARKERP (readcharfun)) |
| 457 | { |
| 458 | struct buffer *b = XMARKER (readcharfun)->buffer; |
| 459 | int bytepos = XMARKER (readcharfun)->bytepos; |
| 460 | |
| 461 | XMARKER (readcharfun)->charpos--; |
| 462 | if (! NILP (b->enable_multibyte_characters)) |
| 463 | BUF_DEC_POS (b, bytepos); |
| 464 | else |
| 465 | bytepos--; |
| 466 | |
| 467 | XMARKER (readcharfun)->bytepos = bytepos; |
| 468 | } |
| 469 | else if (STRINGP (readcharfun)) |
| 470 | { |
| 471 | read_from_string_index--; |
| 472 | read_from_string_index_byte |
| 473 | = string_char_to_byte (readcharfun, read_from_string_index); |
| 474 | } |
| 475 | else if (CONSP (readcharfun)) |
| 476 | { |
| 477 | unread_char = c; |
| 478 | } |
| 479 | else if (EQ (readcharfun, Qlambda)) |
| 480 | { |
| 481 | unread_char = c; |
| 482 | } |
| 483 | else if (EQ (readcharfun, Qget_file_char) |
| 484 | || EQ (readcharfun, Qget_emacs_mule_file_char)) |
| 485 | { |
| 486 | if (load_each_byte) |
| 487 | { |
| 488 | BLOCK_INPUT; |
| 489 | ungetc (c, instream); |
| 490 | UNBLOCK_INPUT; |
| 491 | } |
| 492 | else |
| 493 | unread_char = c; |
| 494 | } |
| 495 | else |
| 496 | call1 (readcharfun, make_number (c)); |
| 497 | } |
| 498 | |
| 499 | static int |
| 500 | readbyte_for_lambda (int c, Lisp_Object readcharfun) |
| 501 | { |
| 502 | return read_bytecode_char (c >= 0); |
| 503 | } |
| 504 | |
| 505 | |
| 506 | static int |
| 507 | readbyte_from_file (int c, Lisp_Object readcharfun) |
| 508 | { |
| 509 | if (c >= 0) |
| 510 | { |
| 511 | BLOCK_INPUT; |
| 512 | ungetc (c, instream); |
| 513 | UNBLOCK_INPUT; |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | BLOCK_INPUT; |
| 518 | c = getc (instream); |
| 519 | |
| 520 | #ifdef EINTR |
| 521 | /* Interrupted reads have been observed while reading over the network */ |
| 522 | while (c == EOF && ferror (instream) && errno == EINTR) |
| 523 | { |
| 524 | UNBLOCK_INPUT; |
| 525 | QUIT; |
| 526 | BLOCK_INPUT; |
| 527 | clearerr (instream); |
| 528 | c = getc (instream); |
| 529 | } |
| 530 | #endif |
| 531 | |
| 532 | UNBLOCK_INPUT; |
| 533 | |
| 534 | return (c == EOF ? -1 : c); |
| 535 | } |
| 536 | |
| 537 | static int |
| 538 | readbyte_from_string (int c, Lisp_Object readcharfun) |
| 539 | { |
| 540 | Lisp_Object string = XCAR (readcharfun); |
| 541 | |
| 542 | if (c >= 0) |
| 543 | { |
| 544 | read_from_string_index--; |
| 545 | read_from_string_index_byte |
| 546 | = string_char_to_byte (string, read_from_string_index); |
| 547 | } |
| 548 | |
| 549 | if (read_from_string_index >= read_from_string_limit) |
| 550 | c = -1; |
| 551 | else |
| 552 | FETCH_STRING_CHAR_ADVANCE (c, string, |
| 553 | read_from_string_index, |
| 554 | read_from_string_index_byte); |
| 555 | return c; |
| 556 | } |
| 557 | |
| 558 | |
| 559 | /* Read one non-ASCII character from INSTREAM. The character is |
| 560 | encoded in `emacs-mule' and the first byte is already read in |
| 561 | C. */ |
| 562 | |
| 563 | extern char emacs_mule_bytes[256]; |
| 564 | |
| 565 | static int |
| 566 | read_emacs_mule_char (int c, int (*readbyte) (int, Lisp_Object), Lisp_Object readcharfun) |
| 567 | { |
| 568 | /* Emacs-mule coding uses at most 4-byte for one character. */ |
| 569 | unsigned char buf[4]; |
| 570 | int len = emacs_mule_bytes[c]; |
| 571 | struct charset *charset; |
| 572 | int i; |
| 573 | unsigned code; |
| 574 | |
| 575 | if (len == 1) |
| 576 | /* C is not a valid leading-code of `emacs-mule'. */ |
| 577 | return BYTE8_TO_CHAR (c); |
| 578 | |
| 579 | i = 0; |
| 580 | buf[i++] = c; |
| 581 | while (i < len) |
| 582 | { |
| 583 | c = (*readbyte) (-1, readcharfun); |
| 584 | if (c < 0xA0) |
| 585 | { |
| 586 | while (--i > 1) |
| 587 | (*readbyte) (buf[i], readcharfun); |
| 588 | return BYTE8_TO_CHAR (buf[0]); |
| 589 | } |
| 590 | buf[i++] = c; |
| 591 | } |
| 592 | |
| 593 | if (len == 2) |
| 594 | { |
| 595 | charset = emacs_mule_charset[buf[0]]; |
| 596 | code = buf[1] & 0x7F; |
| 597 | } |
| 598 | else if (len == 3) |
| 599 | { |
| 600 | if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11 |
| 601 | || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12) |
| 602 | { |
| 603 | charset = emacs_mule_charset[buf[1]]; |
| 604 | code = buf[2] & 0x7F; |
| 605 | } |
| 606 | else |
| 607 | { |
| 608 | charset = emacs_mule_charset[buf[0]]; |
| 609 | code = ((buf[1] << 8) | buf[2]) & 0x7F7F; |
| 610 | } |
| 611 | } |
| 612 | else |
| 613 | { |
| 614 | charset = emacs_mule_charset[buf[1]]; |
| 615 | code = ((buf[2] << 8) | buf[3]) & 0x7F7F; |
| 616 | } |
| 617 | c = DECODE_CHAR (charset, code); |
| 618 | if (c < 0) |
| 619 | Fsignal (Qinvalid_read_syntax, |
| 620 | Fcons (build_string ("invalid multibyte form"), Qnil)); |
| 621 | return c; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | static Lisp_Object read_internal_start (Lisp_Object, Lisp_Object, |
| 626 | Lisp_Object); |
| 627 | static Lisp_Object read0 (Lisp_Object); |
| 628 | static Lisp_Object read1 (Lisp_Object, int *, int); |
| 629 | |
| 630 | static Lisp_Object read_list (int, Lisp_Object); |
| 631 | static Lisp_Object read_vector (Lisp_Object, int); |
| 632 | |
| 633 | static Lisp_Object substitute_object_recurse (Lisp_Object, Lisp_Object, |
| 634 | Lisp_Object); |
| 635 | static void substitute_object_in_subtree (Lisp_Object, |
| 636 | Lisp_Object); |
| 637 | static void substitute_in_interval (INTERVAL, Lisp_Object); |
| 638 | |
| 639 | \f |
| 640 | /* Get a character from the tty. */ |
| 641 | |
| 642 | /* Read input events until we get one that's acceptable for our purposes. |
| 643 | |
| 644 | If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed |
| 645 | until we get a character we like, and then stuffed into |
| 646 | unread_switch_frame. |
| 647 | |
| 648 | If ASCII_REQUIRED is non-zero, we check function key events to see |
| 649 | if the unmodified version of the symbol has a Qascii_character |
| 650 | property, and use that character, if present. |
| 651 | |
| 652 | If ERROR_NONASCII is non-zero, we signal an error if the input we |
| 653 | get isn't an ASCII character with modifiers. If it's zero but |
| 654 | ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII |
| 655 | character. |
| 656 | |
| 657 | If INPUT_METHOD is nonzero, we invoke the current input method |
| 658 | if the character warrants that. |
| 659 | |
| 660 | If SECONDS is a number, we wait that many seconds for input, and |
| 661 | return Qnil if no input arrives within that time. */ |
| 662 | |
| 663 | Lisp_Object |
| 664 | read_filtered_event (no_switch_frame, ascii_required, error_nonascii, |
| 665 | input_method, seconds) |
| 666 | int no_switch_frame, ascii_required, error_nonascii, input_method; |
| 667 | Lisp_Object seconds; |
| 668 | { |
| 669 | Lisp_Object val, delayed_switch_frame; |
| 670 | EMACS_TIME end_time; |
| 671 | |
| 672 | #ifdef HAVE_WINDOW_SYSTEM |
| 673 | if (display_hourglass_p) |
| 674 | cancel_hourglass (); |
| 675 | #endif |
| 676 | |
| 677 | delayed_switch_frame = Qnil; |
| 678 | |
| 679 | /* Compute timeout. */ |
| 680 | if (NUMBERP (seconds)) |
| 681 | { |
| 682 | EMACS_TIME wait_time; |
| 683 | int sec, usec; |
| 684 | double duration = extract_float (seconds); |
| 685 | |
| 686 | sec = (int) duration; |
| 687 | usec = (duration - sec) * 1000000; |
| 688 | EMACS_GET_TIME (end_time); |
| 689 | EMACS_SET_SECS_USECS (wait_time, sec, usec); |
| 690 | EMACS_ADD_TIME (end_time, end_time, wait_time); |
| 691 | } |
| 692 | |
| 693 | /* Read until we get an acceptable event. */ |
| 694 | retry: |
| 695 | do |
| 696 | val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0, |
| 697 | NUMBERP (seconds) ? &end_time : NULL); |
| 698 | while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */ |
| 699 | |
| 700 | if (BUFFERP (val)) |
| 701 | goto retry; |
| 702 | |
| 703 | /* switch-frame events are put off until after the next ASCII |
| 704 | character. This is better than signaling an error just because |
| 705 | the last characters were typed to a separate minibuffer frame, |
| 706 | for example. Eventually, some code which can deal with |
| 707 | switch-frame events will read it and process it. */ |
| 708 | if (no_switch_frame |
| 709 | && EVENT_HAS_PARAMETERS (val) |
| 710 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame)) |
| 711 | { |
| 712 | delayed_switch_frame = val; |
| 713 | goto retry; |
| 714 | } |
| 715 | |
| 716 | if (ascii_required && !(NUMBERP (seconds) && NILP (val))) |
| 717 | { |
| 718 | /* Convert certain symbols to their ASCII equivalents. */ |
| 719 | if (SYMBOLP (val)) |
| 720 | { |
| 721 | Lisp_Object tem, tem1; |
| 722 | tem = Fget (val, Qevent_symbol_element_mask); |
| 723 | if (!NILP (tem)) |
| 724 | { |
| 725 | tem1 = Fget (Fcar (tem), Qascii_character); |
| 726 | /* Merge this symbol's modifier bits |
| 727 | with the ASCII equivalent of its basic code. */ |
| 728 | if (!NILP (tem1)) |
| 729 | XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem)))); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /* If we don't have a character now, deal with it appropriately. */ |
| 734 | if (!INTEGERP (val)) |
| 735 | { |
| 736 | if (error_nonascii) |
| 737 | { |
| 738 | Vunread_command_events = Fcons (val, Qnil); |
| 739 | error ("Non-character input-event"); |
| 740 | } |
| 741 | else |
| 742 | goto retry; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | if (! NILP (delayed_switch_frame)) |
| 747 | unread_switch_frame = delayed_switch_frame; |
| 748 | |
| 749 | #if 0 |
| 750 | |
| 751 | #ifdef HAVE_WINDOW_SYSTEM |
| 752 | if (display_hourglass_p) |
| 753 | start_hourglass (); |
| 754 | #endif |
| 755 | |
| 756 | #endif |
| 757 | |
| 758 | return val; |
| 759 | } |
| 760 | |
| 761 | DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, |
| 762 | doc: /* Read a character from the command input (keyboard or macro). |
| 763 | It is returned as a number. |
| 764 | If the character has modifiers, they are resolved and reflected to the |
| 765 | character code if possible (e.g. C-SPC -> 0). |
| 766 | |
| 767 | If the user generates an event which is not a character (i.e. a mouse |
| 768 | click or function key event), `read-char' signals an error. As an |
| 769 | exception, switch-frame events are put off until non-character events |
| 770 | can be read. |
| 771 | If you want to read non-character events, or ignore them, call |
| 772 | `read-event' or `read-char-exclusive' instead. |
| 773 | |
| 774 | If the optional argument PROMPT is non-nil, display that as a prompt. |
| 775 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some |
| 776 | input method is turned on in the current buffer, that input method |
| 777 | is used for reading a character. |
| 778 | If the optional argument SECONDS is non-nil, it should be a number |
| 779 | specifying the maximum number of seconds to wait for input. If no |
| 780 | input arrives in that time, return nil. SECONDS may be a |
| 781 | floating-point value. */) |
| 782 | (prompt, inherit_input_method, seconds) |
| 783 | Lisp_Object prompt, inherit_input_method, seconds; |
| 784 | { |
| 785 | Lisp_Object val; |
| 786 | |
| 787 | if (! NILP (prompt)) |
| 788 | message_with_string ("%s", prompt, 0); |
| 789 | val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds); |
| 790 | |
| 791 | return (NILP (val) ? Qnil |
| 792 | : make_number (char_resolve_modifier_mask (XINT (val)))); |
| 793 | } |
| 794 | |
| 795 | DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0, |
| 796 | doc: /* Read an event object from the input stream. |
| 797 | If the optional argument PROMPT is non-nil, display that as a prompt. |
| 798 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some |
| 799 | input method is turned on in the current buffer, that input method |
| 800 | is used for reading a character. |
| 801 | If the optional argument SECONDS is non-nil, it should be a number |
| 802 | specifying the maximum number of seconds to wait for input. If no |
| 803 | input arrives in that time, return nil. SECONDS may be a |
| 804 | floating-point value. */) |
| 805 | (prompt, inherit_input_method, seconds) |
| 806 | Lisp_Object prompt, inherit_input_method, seconds; |
| 807 | { |
| 808 | if (! NILP (prompt)) |
| 809 | message_with_string ("%s", prompt, 0); |
| 810 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds); |
| 811 | } |
| 812 | |
| 813 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0, |
| 814 | doc: /* Read a character from the command input (keyboard or macro). |
| 815 | It is returned as a number. Non-character events are ignored. |
| 816 | If the character has modifiers, they are resolved and reflected to the |
| 817 | character code if possible (e.g. C-SPC -> 0). |
| 818 | |
| 819 | If the optional argument PROMPT is non-nil, display that as a prompt. |
| 820 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some |
| 821 | input method is turned on in the current buffer, that input method |
| 822 | is used for reading a character. |
| 823 | If the optional argument SECONDS is non-nil, it should be a number |
| 824 | specifying the maximum number of seconds to wait for input. If no |
| 825 | input arrives in that time, return nil. SECONDS may be a |
| 826 | floating-point value. */) |
| 827 | (prompt, inherit_input_method, seconds) |
| 828 | Lisp_Object prompt, inherit_input_method, seconds; |
| 829 | { |
| 830 | Lisp_Object val; |
| 831 | |
| 832 | if (! NILP (prompt)) |
| 833 | message_with_string ("%s", prompt, 0); |
| 834 | |
| 835 | val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds); |
| 836 | |
| 837 | return (NILP (val) ? Qnil |
| 838 | : make_number (char_resolve_modifier_mask (XINT (val)))); |
| 839 | } |
| 840 | |
| 841 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, |
| 842 | doc: /* Don't use this yourself. */) |
| 843 | () |
| 844 | { |
| 845 | register Lisp_Object val; |
| 846 | BLOCK_INPUT; |
| 847 | XSETINT (val, getc (instream)); |
| 848 | UNBLOCK_INPUT; |
| 849 | return val; |
| 850 | } |
| 851 | |
| 852 | |
| 853 | \f |
| 854 | /* Value is a version number of byte compiled code if the file |
| 855 | associated with file descriptor FD is a compiled Lisp file that's |
| 856 | safe to load. Only files compiled with Emacs are safe to load. |
| 857 | Files compiled with XEmacs can lead to a crash in Fbyte_code |
| 858 | because of an incompatible change in the byte compiler. */ |
| 859 | |
| 860 | static int |
| 861 | safe_to_load_p (int fd) |
| 862 | { |
| 863 | char buf[512]; |
| 864 | int nbytes, i; |
| 865 | int safe_p = 1; |
| 866 | int version = 1; |
| 867 | |
| 868 | /* Read the first few bytes from the file, and look for a line |
| 869 | specifying the byte compiler version used. */ |
| 870 | nbytes = emacs_read (fd, buf, sizeof buf - 1); |
| 871 | if (nbytes > 0) |
| 872 | { |
| 873 | buf[nbytes] = '\0'; |
| 874 | |
| 875 | /* Skip to the next newline, skipping over the initial `ELC' |
| 876 | with NUL bytes following it, but note the version. */ |
| 877 | for (i = 0; i < nbytes && buf[i] != '\n'; ++i) |
| 878 | if (i == 4) |
| 879 | version = buf[i]; |
| 880 | |
| 881 | if (i == nbytes |
| 882 | || fast_c_string_match_ignore_case (Vbytecomp_version_regexp, |
| 883 | buf + i) < 0) |
| 884 | safe_p = 0; |
| 885 | } |
| 886 | if (safe_p) |
| 887 | safe_p = version; |
| 888 | |
| 889 | lseek (fd, 0, SEEK_SET); |
| 890 | return safe_p; |
| 891 | } |
| 892 | |
| 893 | |
| 894 | /* Callback for record_unwind_protect. Restore the old load list OLD, |
| 895 | after loading a file successfully. */ |
| 896 | |
| 897 | static Lisp_Object |
| 898 | record_load_unwind (Lisp_Object old) |
| 899 | { |
| 900 | return Vloads_in_progress = old; |
| 901 | } |
| 902 | |
| 903 | /* This handler function is used via internal_condition_case_1. */ |
| 904 | |
| 905 | static Lisp_Object |
| 906 | load_error_handler (Lisp_Object data) |
| 907 | { |
| 908 | return Qnil; |
| 909 | } |
| 910 | |
| 911 | static Lisp_Object |
| 912 | load_warn_old_style_backquotes (Lisp_Object file) |
| 913 | { |
| 914 | if (!NILP (Vold_style_backquotes)) |
| 915 | { |
| 916 | Lisp_Object args[2]; |
| 917 | args[0] = build_string ("Loading `%s': old-style backquotes detected!"); |
| 918 | args[1] = file; |
| 919 | Fmessage (2, args); |
| 920 | } |
| 921 | return Qnil; |
| 922 | } |
| 923 | |
| 924 | DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0, |
| 925 | doc: /* Return the suffixes that `load' should try if a suffix is \ |
| 926 | required. |
| 927 | This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */) |
| 928 | () |
| 929 | { |
| 930 | Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext; |
| 931 | while (CONSP (suffixes)) |
| 932 | { |
| 933 | Lisp_Object exts = Vload_file_rep_suffixes; |
| 934 | suffix = XCAR (suffixes); |
| 935 | suffixes = XCDR (suffixes); |
| 936 | while (CONSP (exts)) |
| 937 | { |
| 938 | ext = XCAR (exts); |
| 939 | exts = XCDR (exts); |
| 940 | lst = Fcons (concat2 (suffix, ext), lst); |
| 941 | } |
| 942 | } |
| 943 | return Fnreverse (lst); |
| 944 | } |
| 945 | |
| 946 | DEFUN ("load", Fload, Sload, 1, 5, 0, |
| 947 | doc: /* Execute a file of Lisp code named FILE. |
| 948 | First try FILE with `.elc' appended, then try with `.el', |
| 949 | then try FILE unmodified (the exact suffixes in the exact order are |
| 950 | determined by `load-suffixes'). Environment variable references in |
| 951 | FILE are replaced with their values by calling `substitute-in-file-name'. |
| 952 | This function searches the directories in `load-path'. |
| 953 | |
| 954 | If optional second arg NOERROR is non-nil, |
| 955 | report no error if FILE doesn't exist. |
| 956 | Print messages at start and end of loading unless |
| 957 | optional third arg NOMESSAGE is non-nil (but `force-load-messages' |
| 958 | overrides that). |
| 959 | If optional fourth arg NOSUFFIX is non-nil, don't try adding |
| 960 | suffixes `.elc' or `.el' to the specified name FILE. |
| 961 | If optional fifth arg MUST-SUFFIX is non-nil, insist on |
| 962 | the suffix `.elc' or `.el'; don't accept just FILE unless |
| 963 | it ends in one of those suffixes or includes a directory name. |
| 964 | |
| 965 | If this function fails to find a file, it may look for different |
| 966 | representations of that file before trying another file. |
| 967 | It does so by adding the non-empty suffixes in `load-file-rep-suffixes' |
| 968 | to the file name. Emacs uses this feature mainly to find compressed |
| 969 | versions of files when Auto Compression mode is enabled. |
| 970 | |
| 971 | The exact suffixes that this function tries out, in the exact order, |
| 972 | are given by the value of the variable `load-file-rep-suffixes' if |
| 973 | NOSUFFIX is non-nil and by the return value of the function |
| 974 | `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and |
| 975 | MUST-SUFFIX are nil, this function first tries out the latter suffixes |
| 976 | and then the former. |
| 977 | |
| 978 | Loading a file records its definitions, and its `provide' and |
| 979 | `require' calls, in an element of `load-history' whose |
| 980 | car is the file name loaded. See `load-history'. |
| 981 | |
| 982 | Return t if the file exists and loads successfully. */) |
| 983 | (file, noerror, nomessage, nosuffix, must_suffix) |
| 984 | Lisp_Object file, noerror, nomessage, nosuffix, must_suffix; |
| 985 | { |
| 986 | register FILE *stream; |
| 987 | register int fd = -1; |
| 988 | int count = SPECPDL_INDEX (); |
| 989 | struct gcpro gcpro1, gcpro2, gcpro3; |
| 990 | Lisp_Object found, efound, hist_file_name; |
| 991 | /* 1 means we printed the ".el is newer" message. */ |
| 992 | int newer = 0; |
| 993 | /* 1 means we are loading a compiled file. */ |
| 994 | int compiled = 0; |
| 995 | Lisp_Object handler; |
| 996 | int safe_p = 1; |
| 997 | char *fmode = "r"; |
| 998 | Lisp_Object tmp[2]; |
| 999 | int version; |
| 1000 | |
| 1001 | #ifdef DOS_NT |
| 1002 | fmode = "rt"; |
| 1003 | #endif /* DOS_NT */ |
| 1004 | |
| 1005 | CHECK_STRING (file); |
| 1006 | |
| 1007 | /* If file name is magic, call the handler. */ |
| 1008 | /* This shouldn't be necessary any more now that `openp' handles it right. |
| 1009 | handler = Ffind_file_name_handler (file, Qload); |
| 1010 | if (!NILP (handler)) |
| 1011 | return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */ |
| 1012 | |
| 1013 | /* Do this after the handler to avoid |
| 1014 | the need to gcpro noerror, nomessage and nosuffix. |
| 1015 | (Below here, we care only whether they are nil or not.) |
| 1016 | The presence of this call is the result of a historical accident: |
| 1017 | it used to be in every file-operation and when it got removed |
| 1018 | everywhere, it accidentally stayed here. Since then, enough people |
| 1019 | supposedly have things like (load "$PROJECT/foo.el") in their .emacs |
| 1020 | that it seemed risky to remove. */ |
| 1021 | if (! NILP (noerror)) |
| 1022 | { |
| 1023 | file = internal_condition_case_1 (Fsubstitute_in_file_name, file, |
| 1024 | Qt, load_error_handler); |
| 1025 | if (NILP (file)) |
| 1026 | return Qnil; |
| 1027 | } |
| 1028 | else |
| 1029 | file = Fsubstitute_in_file_name (file); |
| 1030 | |
| 1031 | |
| 1032 | /* Avoid weird lossage with null string as arg, |
| 1033 | since it would try to load a directory as a Lisp file */ |
| 1034 | if (SCHARS (file) > 0) |
| 1035 | { |
| 1036 | int size = SBYTES (file); |
| 1037 | |
| 1038 | found = Qnil; |
| 1039 | GCPRO2 (file, found); |
| 1040 | |
| 1041 | if (! NILP (must_suffix)) |
| 1042 | { |
| 1043 | /* Don't insist on adding a suffix if FILE already ends with one. */ |
| 1044 | if (size > 3 |
| 1045 | && !strcmp (SDATA (file) + size - 3, ".el")) |
| 1046 | must_suffix = Qnil; |
| 1047 | else if (size > 4 |
| 1048 | && !strcmp (SDATA (file) + size - 4, ".elc")) |
| 1049 | must_suffix = Qnil; |
| 1050 | /* Don't insist on adding a suffix |
| 1051 | if the argument includes a directory name. */ |
| 1052 | else if (! NILP (Ffile_name_directory (file))) |
| 1053 | must_suffix = Qnil; |
| 1054 | } |
| 1055 | |
| 1056 | fd = openp (Vload_path, file, |
| 1057 | (!NILP (nosuffix) ? Qnil |
| 1058 | : !NILP (must_suffix) ? Fget_load_suffixes () |
| 1059 | : Fappend (2, (tmp[0] = Fget_load_suffixes (), |
| 1060 | tmp[1] = Vload_file_rep_suffixes, |
| 1061 | tmp))), |
| 1062 | &found, Qnil); |
| 1063 | UNGCPRO; |
| 1064 | } |
| 1065 | |
| 1066 | if (fd == -1) |
| 1067 | { |
| 1068 | if (NILP (noerror)) |
| 1069 | xsignal2 (Qfile_error, build_string ("Cannot open load file"), file); |
| 1070 | return Qnil; |
| 1071 | } |
| 1072 | |
| 1073 | /* Tell startup.el whether or not we found the user's init file. */ |
| 1074 | if (EQ (Qt, Vuser_init_file)) |
| 1075 | Vuser_init_file = found; |
| 1076 | |
| 1077 | /* If FD is -2, that means openp found a magic file. */ |
| 1078 | if (fd == -2) |
| 1079 | { |
| 1080 | if (NILP (Fequal (found, file))) |
| 1081 | /* If FOUND is a different file name from FILE, |
| 1082 | find its handler even if we have already inhibited |
| 1083 | the `load' operation on FILE. */ |
| 1084 | handler = Ffind_file_name_handler (found, Qt); |
| 1085 | else |
| 1086 | handler = Ffind_file_name_handler (found, Qload); |
| 1087 | if (! NILP (handler)) |
| 1088 | return call5 (handler, Qload, found, noerror, nomessage, Qt); |
| 1089 | } |
| 1090 | |
| 1091 | /* Check if we're stuck in a recursive load cycle. |
| 1092 | |
| 1093 | 2000-09-21: It's not possible to just check for the file loaded |
| 1094 | being a member of Vloads_in_progress. This fails because of the |
| 1095 | way the byte compiler currently works; `provide's are not |
| 1096 | evaluated, see font-lock.el/jit-lock.el as an example. This |
| 1097 | leads to a certain amount of ``normal'' recursion. |
| 1098 | |
| 1099 | Also, just loading a file recursively is not always an error in |
| 1100 | the general case; the second load may do something different. */ |
| 1101 | { |
| 1102 | int count = 0; |
| 1103 | Lisp_Object tem; |
| 1104 | for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem)) |
| 1105 | if (!NILP (Fequal (found, XCAR (tem))) && (++count > 3)) |
| 1106 | { |
| 1107 | if (fd >= 0) |
| 1108 | emacs_close (fd); |
| 1109 | signal_error ("Recursive load", Fcons (found, Vloads_in_progress)); |
| 1110 | } |
| 1111 | record_unwind_protect (record_load_unwind, Vloads_in_progress); |
| 1112 | Vloads_in_progress = Fcons (found, Vloads_in_progress); |
| 1113 | } |
| 1114 | |
| 1115 | /* Get the name for load-history. */ |
| 1116 | hist_file_name = (! NILP (Vpurify_flag) |
| 1117 | ? Fconcat (2, (tmp[0] = Ffile_name_directory (file), |
| 1118 | tmp[1] = Ffile_name_nondirectory (found), |
| 1119 | tmp)) |
| 1120 | : found) ; |
| 1121 | |
| 1122 | version = -1; |
| 1123 | |
| 1124 | /* Check for the presence of old-style quotes and warn about them. */ |
| 1125 | specbind (Qold_style_backquotes, Qnil); |
| 1126 | record_unwind_protect (load_warn_old_style_backquotes, file); |
| 1127 | |
| 1128 | if (!bcmp (SDATA (found) + SBYTES (found) - 4, |
| 1129 | ".elc", 4) |
| 1130 | || (fd >= 0 && (version = safe_to_load_p (fd)) > 0)) |
| 1131 | /* Load .elc files directly, but not when they are |
| 1132 | remote and have no handler! */ |
| 1133 | { |
| 1134 | if (fd != -2) |
| 1135 | { |
| 1136 | struct stat s1, s2; |
| 1137 | int result; |
| 1138 | |
| 1139 | GCPRO3 (file, found, hist_file_name); |
| 1140 | |
| 1141 | if (version < 0 |
| 1142 | && ! (version = safe_to_load_p (fd))) |
| 1143 | { |
| 1144 | safe_p = 0; |
| 1145 | if (!load_dangerous_libraries) |
| 1146 | { |
| 1147 | if (fd >= 0) |
| 1148 | emacs_close (fd); |
| 1149 | error ("File `%s' was not compiled in Emacs", |
| 1150 | SDATA (found)); |
| 1151 | } |
| 1152 | else if (!NILP (nomessage) && !force_load_messages) |
| 1153 | message_with_string ("File `%s' not compiled in Emacs", found, 1); |
| 1154 | } |
| 1155 | |
| 1156 | compiled = 1; |
| 1157 | |
| 1158 | efound = ENCODE_FILE (found); |
| 1159 | |
| 1160 | #ifdef DOS_NT |
| 1161 | fmode = "rb"; |
| 1162 | #endif /* DOS_NT */ |
| 1163 | stat ((char *)SDATA (efound), &s1); |
| 1164 | SSET (efound, SBYTES (efound) - 1, 0); |
| 1165 | result = stat ((char *)SDATA (efound), &s2); |
| 1166 | SSET (efound, SBYTES (efound) - 1, 'c'); |
| 1167 | |
| 1168 | if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) |
| 1169 | { |
| 1170 | /* Make the progress messages mention that source is newer. */ |
| 1171 | newer = 1; |
| 1172 | |
| 1173 | /* If we won't print another message, mention this anyway. */ |
| 1174 | if (!NILP (nomessage) && !force_load_messages) |
| 1175 | { |
| 1176 | Lisp_Object msg_file; |
| 1177 | msg_file = Fsubstring (found, make_number (0), make_number (-1)); |
| 1178 | message_with_string ("Source file `%s' newer than byte-compiled file", |
| 1179 | msg_file, 1); |
| 1180 | } |
| 1181 | } |
| 1182 | UNGCPRO; |
| 1183 | } |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| 1187 | /* We are loading a source file (*.el). */ |
| 1188 | if (!NILP (Vload_source_file_function)) |
| 1189 | { |
| 1190 | Lisp_Object val; |
| 1191 | |
| 1192 | if (fd >= 0) |
| 1193 | emacs_close (fd); |
| 1194 | val = call4 (Vload_source_file_function, found, hist_file_name, |
| 1195 | NILP (noerror) ? Qnil : Qt, |
| 1196 | (NILP (nomessage) || force_load_messages) ? Qnil : Qt); |
| 1197 | return unbind_to (count, val); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | GCPRO3 (file, found, hist_file_name); |
| 1202 | |
| 1203 | #ifdef WINDOWSNT |
| 1204 | emacs_close (fd); |
| 1205 | efound = ENCODE_FILE (found); |
| 1206 | stream = fopen ((char *) SDATA (efound), fmode); |
| 1207 | #else /* not WINDOWSNT */ |
| 1208 | stream = fdopen (fd, fmode); |
| 1209 | #endif /* not WINDOWSNT */ |
| 1210 | if (stream == 0) |
| 1211 | { |
| 1212 | emacs_close (fd); |
| 1213 | error ("Failure to create stdio stream for %s", SDATA (file)); |
| 1214 | } |
| 1215 | |
| 1216 | if (! NILP (Vpurify_flag)) |
| 1217 | Vpreloaded_file_list = Fcons (Fpurecopy(file), Vpreloaded_file_list); |
| 1218 | |
| 1219 | if (NILP (nomessage) || force_load_messages) |
| 1220 | { |
| 1221 | if (!safe_p) |
| 1222 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...", |
| 1223 | file, 1); |
| 1224 | else if (!compiled) |
| 1225 | message_with_string ("Loading %s (source)...", file, 1); |
| 1226 | else if (newer) |
| 1227 | message_with_string ("Loading %s (compiled; note, source file is newer)...", |
| 1228 | file, 1); |
| 1229 | else /* The typical case; compiled file newer than source file. */ |
| 1230 | message_with_string ("Loading %s...", file, 1); |
| 1231 | } |
| 1232 | |
| 1233 | record_unwind_protect (load_unwind, make_save_value (stream, 0)); |
| 1234 | record_unwind_protect (load_descriptor_unwind, load_descriptor_list); |
| 1235 | specbind (Qload_file_name, found); |
| 1236 | specbind (Qinhibit_file_name_operation, Qnil); |
| 1237 | load_descriptor_list |
| 1238 | = Fcons (make_number (fileno (stream)), load_descriptor_list); |
| 1239 | specbind (Qload_in_progress, Qt); |
| 1240 | if (! version || version >= 22) |
| 1241 | readevalloop (Qget_file_char, stream, hist_file_name, |
| 1242 | Feval, 0, Qnil, Qnil, Qnil, Qnil); |
| 1243 | else |
| 1244 | { |
| 1245 | /* We can't handle a file which was compiled with |
| 1246 | byte-compile-dynamic by older version of Emacs. */ |
| 1247 | specbind (Qload_force_doc_strings, Qt); |
| 1248 | readevalloop (Qget_emacs_mule_file_char, stream, hist_file_name, Feval, |
| 1249 | 0, Qnil, Qnil, Qnil, Qnil); |
| 1250 | } |
| 1251 | unbind_to (count, Qnil); |
| 1252 | |
| 1253 | /* Run any eval-after-load forms for this file */ |
| 1254 | if (!NILP (Ffboundp (Qdo_after_load_evaluation))) |
| 1255 | call1 (Qdo_after_load_evaluation, hist_file_name) ; |
| 1256 | |
| 1257 | UNGCPRO; |
| 1258 | |
| 1259 | xfree (saved_doc_string); |
| 1260 | saved_doc_string = 0; |
| 1261 | saved_doc_string_size = 0; |
| 1262 | |
| 1263 | xfree (prev_saved_doc_string); |
| 1264 | prev_saved_doc_string = 0; |
| 1265 | prev_saved_doc_string_size = 0; |
| 1266 | |
| 1267 | if (!noninteractive && (NILP (nomessage) || force_load_messages)) |
| 1268 | { |
| 1269 | if (!safe_p) |
| 1270 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done", |
| 1271 | file, 1); |
| 1272 | else if (!compiled) |
| 1273 | message_with_string ("Loading %s (source)...done", file, 1); |
| 1274 | else if (newer) |
| 1275 | message_with_string ("Loading %s (compiled; note, source file is newer)...done", |
| 1276 | file, 1); |
| 1277 | else /* The typical case; compiled file newer than source file. */ |
| 1278 | message_with_string ("Loading %s...done", file, 1); |
| 1279 | } |
| 1280 | |
| 1281 | return Qt; |
| 1282 | } |
| 1283 | |
| 1284 | static Lisp_Object |
| 1285 | load_unwind (Lisp_Object arg) /* used as unwind-protect function in load */ |
| 1286 | |
| 1287 | { |
| 1288 | FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer; |
| 1289 | if (stream != NULL) |
| 1290 | { |
| 1291 | BLOCK_INPUT; |
| 1292 | fclose (stream); |
| 1293 | UNBLOCK_INPUT; |
| 1294 | } |
| 1295 | return Qnil; |
| 1296 | } |
| 1297 | |
| 1298 | static Lisp_Object |
| 1299 | load_descriptor_unwind (Lisp_Object oldlist) |
| 1300 | { |
| 1301 | load_descriptor_list = oldlist; |
| 1302 | return Qnil; |
| 1303 | } |
| 1304 | |
| 1305 | /* Close all descriptors in use for Floads. |
| 1306 | This is used when starting a subprocess. */ |
| 1307 | |
| 1308 | void |
| 1309 | close_load_descs (void) |
| 1310 | { |
| 1311 | #ifndef WINDOWSNT |
| 1312 | Lisp_Object tail; |
| 1313 | for (tail = load_descriptor_list; CONSP (tail); tail = XCDR (tail)) |
| 1314 | emacs_close (XFASTINT (XCAR (tail))); |
| 1315 | #endif |
| 1316 | } |
| 1317 | \f |
| 1318 | static int |
| 1319 | complete_filename_p (Lisp_Object pathname) |
| 1320 | { |
| 1321 | register const unsigned char *s = SDATA (pathname); |
| 1322 | return (IS_DIRECTORY_SEP (s[0]) |
| 1323 | || (SCHARS (pathname) > 2 |
| 1324 | && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))); |
| 1325 | } |
| 1326 | |
| 1327 | DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0, |
| 1328 | doc: /* Search for FILENAME through PATH. |
| 1329 | Returns the file's name in absolute form, or nil if not found. |
| 1330 | If SUFFIXES is non-nil, it should be a list of suffixes to append to |
| 1331 | file name when searching. |
| 1332 | If non-nil, PREDICATE is used instead of `file-readable-p'. |
| 1333 | PREDICATE can also be an integer to pass to the access(2) function, |
| 1334 | in which case file-name-handlers are ignored. */) |
| 1335 | (filename, path, suffixes, predicate) |
| 1336 | Lisp_Object filename, path, suffixes, predicate; |
| 1337 | { |
| 1338 | Lisp_Object file; |
| 1339 | int fd = openp (path, filename, suffixes, &file, predicate); |
| 1340 | if (NILP (predicate) && fd > 0) |
| 1341 | close (fd); |
| 1342 | return file; |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | /* Search for a file whose name is STR, looking in directories |
| 1347 | in the Lisp list PATH, and trying suffixes from SUFFIX. |
| 1348 | On success, returns a file descriptor. On failure, returns -1. |
| 1349 | |
| 1350 | SUFFIXES is a list of strings containing possible suffixes. |
| 1351 | The empty suffix is automatically added if the list is empty. |
| 1352 | |
| 1353 | PREDICATE non-nil means don't open the files, |
| 1354 | just look for one that satisfies the predicate. In this case, |
| 1355 | returns 1 on success. The predicate can be a lisp function or |
| 1356 | an integer to pass to `access' (in which case file-name-handlers |
| 1357 | are ignored). |
| 1358 | |
| 1359 | If STOREPTR is nonzero, it points to a slot where the name of |
| 1360 | the file actually found should be stored as a Lisp string. |
| 1361 | nil is stored there on failure. |
| 1362 | |
| 1363 | If the file we find is remote, return -2 |
| 1364 | but store the found remote file name in *STOREPTR. */ |
| 1365 | |
| 1366 | int |
| 1367 | openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate) |
| 1368 | { |
| 1369 | register int fd; |
| 1370 | int fn_size = 100; |
| 1371 | char buf[100]; |
| 1372 | register char *fn = buf; |
| 1373 | int absolute = 0; |
| 1374 | int want_size; |
| 1375 | Lisp_Object filename; |
| 1376 | struct stat st; |
| 1377 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
| 1378 | Lisp_Object string, tail, encoded_fn; |
| 1379 | int max_suffix_len = 0; |
| 1380 | |
| 1381 | CHECK_STRING (str); |
| 1382 | |
| 1383 | for (tail = suffixes; CONSP (tail); tail = XCDR (tail)) |
| 1384 | { |
| 1385 | CHECK_STRING_CAR (tail); |
| 1386 | max_suffix_len = max (max_suffix_len, |
| 1387 | SBYTES (XCAR (tail))); |
| 1388 | } |
| 1389 | |
| 1390 | string = filename = encoded_fn = Qnil; |
| 1391 | GCPRO6 (str, string, filename, path, suffixes, encoded_fn); |
| 1392 | |
| 1393 | if (storeptr) |
| 1394 | *storeptr = Qnil; |
| 1395 | |
| 1396 | if (complete_filename_p (str)) |
| 1397 | absolute = 1; |
| 1398 | |
| 1399 | for (; CONSP (path); path = XCDR (path)) |
| 1400 | { |
| 1401 | filename = Fexpand_file_name (str, XCAR (path)); |
| 1402 | if (!complete_filename_p (filename)) |
| 1403 | /* If there are non-absolute elts in PATH (eg ".") */ |
| 1404 | /* Of course, this could conceivably lose if luser sets |
| 1405 | default-directory to be something non-absolute... */ |
| 1406 | { |
| 1407 | filename = Fexpand_file_name (filename, current_buffer->directory); |
| 1408 | if (!complete_filename_p (filename)) |
| 1409 | /* Give up on this path element! */ |
| 1410 | continue; |
| 1411 | } |
| 1412 | |
| 1413 | /* Calculate maximum size of any filename made from |
| 1414 | this path element/specified file name and any possible suffix. */ |
| 1415 | want_size = max_suffix_len + SBYTES (filename) + 1; |
| 1416 | if (fn_size < want_size) |
| 1417 | fn = (char *) alloca (fn_size = 100 + want_size); |
| 1418 | |
| 1419 | /* Loop over suffixes. */ |
| 1420 | for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes; |
| 1421 | CONSP (tail); tail = XCDR (tail)) |
| 1422 | { |
| 1423 | int lsuffix = SBYTES (XCAR (tail)); |
| 1424 | Lisp_Object handler; |
| 1425 | int exists; |
| 1426 | |
| 1427 | /* Concatenate path element/specified name with the suffix. |
| 1428 | If the directory starts with /:, remove that. */ |
| 1429 | if (SCHARS (filename) > 2 |
| 1430 | && SREF (filename, 0) == '/' |
| 1431 | && SREF (filename, 1) == ':') |
| 1432 | { |
| 1433 | strncpy (fn, SDATA (filename) + 2, |
| 1434 | SBYTES (filename) - 2); |
| 1435 | fn[SBYTES (filename) - 2] = 0; |
| 1436 | } |
| 1437 | else |
| 1438 | { |
| 1439 | strncpy (fn, SDATA (filename), |
| 1440 | SBYTES (filename)); |
| 1441 | fn[SBYTES (filename)] = 0; |
| 1442 | } |
| 1443 | |
| 1444 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ |
| 1445 | strncat (fn, SDATA (XCAR (tail)), lsuffix); |
| 1446 | |
| 1447 | /* Check that the file exists and is not a directory. */ |
| 1448 | /* We used to only check for handlers on non-absolute file names: |
| 1449 | if (absolute) |
| 1450 | handler = Qnil; |
| 1451 | else |
| 1452 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); |
| 1453 | It's not clear why that was the case and it breaks things like |
| 1454 | (load "/bar.el") where the file is actually "/bar.el.gz". */ |
| 1455 | string = build_string (fn); |
| 1456 | handler = Ffind_file_name_handler (string, Qfile_exists_p); |
| 1457 | if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) |
| 1458 | { |
| 1459 | if (NILP (predicate)) |
| 1460 | exists = !NILP (Ffile_readable_p (string)); |
| 1461 | else |
| 1462 | exists = !NILP (call1 (predicate, string)); |
| 1463 | if (exists && !NILP (Ffile_directory_p (string))) |
| 1464 | exists = 0; |
| 1465 | |
| 1466 | if (exists) |
| 1467 | { |
| 1468 | /* We succeeded; return this descriptor and filename. */ |
| 1469 | if (storeptr) |
| 1470 | *storeptr = string; |
| 1471 | UNGCPRO; |
| 1472 | return -2; |
| 1473 | } |
| 1474 | } |
| 1475 | else |
| 1476 | { |
| 1477 | const char *pfn; |
| 1478 | |
| 1479 | encoded_fn = ENCODE_FILE (string); |
| 1480 | pfn = SDATA (encoded_fn); |
| 1481 | exists = (stat (pfn, &st) >= 0 |
| 1482 | && (st.st_mode & S_IFMT) != S_IFDIR); |
| 1483 | if (exists) |
| 1484 | { |
| 1485 | /* Check that we can access or open it. */ |
| 1486 | if (NATNUMP (predicate)) |
| 1487 | fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1; |
| 1488 | else |
| 1489 | fd = emacs_open (pfn, O_RDONLY, 0); |
| 1490 | |
| 1491 | if (fd >= 0) |
| 1492 | { |
| 1493 | /* We succeeded; return this descriptor and filename. */ |
| 1494 | if (storeptr) |
| 1495 | *storeptr = string; |
| 1496 | UNGCPRO; |
| 1497 | return fd; |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | if (absolute) |
| 1503 | break; |
| 1504 | } |
| 1505 | |
| 1506 | UNGCPRO; |
| 1507 | return -1; |
| 1508 | } |
| 1509 | |
| 1510 | \f |
| 1511 | /* Merge the list we've accumulated of globals from the current input source |
| 1512 | into the load_history variable. The details depend on whether |
| 1513 | the source has an associated file name or not. |
| 1514 | |
| 1515 | FILENAME is the file name that we are loading from. |
| 1516 | ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */ |
| 1517 | |
| 1518 | static void |
| 1519 | build_load_history (Lisp_Object filename, int entire) |
| 1520 | { |
| 1521 | register Lisp_Object tail, prev, newelt; |
| 1522 | register Lisp_Object tem, tem2; |
| 1523 | register int foundit = 0; |
| 1524 | |
| 1525 | tail = Vload_history; |
| 1526 | prev = Qnil; |
| 1527 | |
| 1528 | while (CONSP (tail)) |
| 1529 | { |
| 1530 | tem = XCAR (tail); |
| 1531 | |
| 1532 | /* Find the feature's previous assoc list... */ |
| 1533 | if (!NILP (Fequal (filename, Fcar (tem)))) |
| 1534 | { |
| 1535 | foundit = 1; |
| 1536 | |
| 1537 | /* If we're loading the entire file, remove old data. */ |
| 1538 | if (entire) |
| 1539 | { |
| 1540 | if (NILP (prev)) |
| 1541 | Vload_history = XCDR (tail); |
| 1542 | else |
| 1543 | Fsetcdr (prev, XCDR (tail)); |
| 1544 | } |
| 1545 | |
| 1546 | /* Otherwise, cons on new symbols that are not already members. */ |
| 1547 | else |
| 1548 | { |
| 1549 | tem2 = Vcurrent_load_list; |
| 1550 | |
| 1551 | while (CONSP (tem2)) |
| 1552 | { |
| 1553 | newelt = XCAR (tem2); |
| 1554 | |
| 1555 | if (NILP (Fmember (newelt, tem))) |
| 1556 | Fsetcar (tail, Fcons (XCAR (tem), |
| 1557 | Fcons (newelt, XCDR (tem)))); |
| 1558 | |
| 1559 | tem2 = XCDR (tem2); |
| 1560 | QUIT; |
| 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | else |
| 1565 | prev = tail; |
| 1566 | tail = XCDR (tail); |
| 1567 | QUIT; |
| 1568 | } |
| 1569 | |
| 1570 | /* If we're loading an entire file, cons the new assoc onto the |
| 1571 | front of load-history, the most-recently-loaded position. Also |
| 1572 | do this if we didn't find an existing member for the file. */ |
| 1573 | if (entire || !foundit) |
| 1574 | Vload_history = Fcons (Fnreverse (Vcurrent_load_list), |
| 1575 | Vload_history); |
| 1576 | } |
| 1577 | |
| 1578 | Lisp_Object |
| 1579 | unreadpure (Lisp_Object junk) /* Used as unwind-protect function in readevalloop */ |
| 1580 | |
| 1581 | { |
| 1582 | read_pure = 0; |
| 1583 | return Qnil; |
| 1584 | } |
| 1585 | |
| 1586 | static Lisp_Object |
| 1587 | readevalloop_1 (Lisp_Object old) |
| 1588 | { |
| 1589 | load_convert_to_unibyte = ! NILP (old); |
| 1590 | return Qnil; |
| 1591 | } |
| 1592 | |
| 1593 | /* Signal an `end-of-file' error, if possible with file name |
| 1594 | information. */ |
| 1595 | |
| 1596 | static void |
| 1597 | end_of_file_error (void) |
| 1598 | { |
| 1599 | if (STRINGP (Vload_file_name)) |
| 1600 | xsignal1 (Qend_of_file, Vload_file_name); |
| 1601 | |
| 1602 | xsignal0 (Qend_of_file); |
| 1603 | } |
| 1604 | |
| 1605 | /* UNIBYTE specifies how to set load_convert_to_unibyte |
| 1606 | for this invocation. |
| 1607 | READFUN, if non-nil, is used instead of `read'. |
| 1608 | |
| 1609 | START, END specify region to read in current buffer (from eval-region). |
| 1610 | If the input is not from a buffer, they must be nil. */ |
| 1611 | |
| 1612 | static void |
| 1613 | readevalloop (readcharfun, stream, sourcename, evalfun, |
| 1614 | printflag, unibyte, readfun, start, end) |
| 1615 | Lisp_Object readcharfun; |
| 1616 | FILE *stream; |
| 1617 | Lisp_Object sourcename; |
| 1618 | Lisp_Object (*evalfun) (); |
| 1619 | int printflag; |
| 1620 | Lisp_Object unibyte, readfun; |
| 1621 | Lisp_Object start, end; |
| 1622 | { |
| 1623 | register int c; |
| 1624 | register Lisp_Object val; |
| 1625 | int count = SPECPDL_INDEX (); |
| 1626 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 1627 | struct buffer *b = 0; |
| 1628 | int continue_reading_p; |
| 1629 | /* Nonzero if reading an entire buffer. */ |
| 1630 | int whole_buffer = 0; |
| 1631 | /* 1 on the first time around. */ |
| 1632 | int first_sexp = 1; |
| 1633 | |
| 1634 | if (MARKERP (readcharfun)) |
| 1635 | { |
| 1636 | if (NILP (start)) |
| 1637 | start = readcharfun; |
| 1638 | } |
| 1639 | |
| 1640 | if (BUFFERP (readcharfun)) |
| 1641 | b = XBUFFER (readcharfun); |
| 1642 | else if (MARKERP (readcharfun)) |
| 1643 | b = XMARKER (readcharfun)->buffer; |
| 1644 | |
| 1645 | /* We assume START is nil when input is not from a buffer. */ |
| 1646 | if (! NILP (start) && !b) |
| 1647 | abort (); |
| 1648 | |
| 1649 | specbind (Qstandard_input, readcharfun); /* GCPROs readcharfun. */ |
| 1650 | specbind (Qcurrent_load_list, Qnil); |
| 1651 | record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil); |
| 1652 | load_convert_to_unibyte = !NILP (unibyte); |
| 1653 | |
| 1654 | GCPRO4 (sourcename, readfun, start, end); |
| 1655 | |
| 1656 | /* Try to ensure sourcename is a truename, except whilst preloading. */ |
| 1657 | if (NILP (Vpurify_flag) |
| 1658 | && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename)) |
| 1659 | && !NILP (Ffboundp (Qfile_truename))) |
| 1660 | sourcename = call1 (Qfile_truename, sourcename) ; |
| 1661 | |
| 1662 | LOADHIST_ATTACH (sourcename); |
| 1663 | |
| 1664 | continue_reading_p = 1; |
| 1665 | while (continue_reading_p) |
| 1666 | { |
| 1667 | int count1 = SPECPDL_INDEX (); |
| 1668 | |
| 1669 | if (b != 0 && NILP (b->name)) |
| 1670 | error ("Reading from killed buffer"); |
| 1671 | |
| 1672 | if (!NILP (start)) |
| 1673 | { |
| 1674 | /* Switch to the buffer we are reading from. */ |
| 1675 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
| 1676 | set_buffer_internal (b); |
| 1677 | |
| 1678 | /* Save point in it. */ |
| 1679 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
| 1680 | /* Save ZV in it. */ |
| 1681 | record_unwind_protect (save_restriction_restore, save_restriction_save ()); |
| 1682 | /* Those get unbound after we read one expression. */ |
| 1683 | |
| 1684 | /* Set point and ZV around stuff to be read. */ |
| 1685 | Fgoto_char (start); |
| 1686 | if (!NILP (end)) |
| 1687 | Fnarrow_to_region (make_number (BEGV), end); |
| 1688 | |
| 1689 | /* Just for cleanliness, convert END to a marker |
| 1690 | if it is an integer. */ |
| 1691 | if (INTEGERP (end)) |
| 1692 | end = Fpoint_max_marker (); |
| 1693 | } |
| 1694 | |
| 1695 | /* On the first cycle, we can easily test here |
| 1696 | whether we are reading the whole buffer. */ |
| 1697 | if (b && first_sexp) |
| 1698 | whole_buffer = (PT == BEG && ZV == Z); |
| 1699 | |
| 1700 | instream = stream; |
| 1701 | read_next: |
| 1702 | c = READCHAR; |
| 1703 | if (c == ';') |
| 1704 | { |
| 1705 | while ((c = READCHAR) != '\n' && c != -1); |
| 1706 | goto read_next; |
| 1707 | } |
| 1708 | if (c < 0) |
| 1709 | { |
| 1710 | unbind_to (count1, Qnil); |
| 1711 | break; |
| 1712 | } |
| 1713 | |
| 1714 | /* Ignore whitespace here, so we can detect eof. */ |
| 1715 | if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' |
| 1716 | || c == 0x8a0) /* NBSP */ |
| 1717 | goto read_next; |
| 1718 | |
| 1719 | if (!NILP (Vpurify_flag) && c == '(') |
| 1720 | { |
| 1721 | record_unwind_protect (unreadpure, Qnil); |
| 1722 | val = read_list (-1, readcharfun); |
| 1723 | } |
| 1724 | else |
| 1725 | { |
| 1726 | UNREAD (c); |
| 1727 | read_objects = Qnil; |
| 1728 | if (!NILP (readfun)) |
| 1729 | { |
| 1730 | val = call1 (readfun, readcharfun); |
| 1731 | |
| 1732 | /* If READCHARFUN has set point to ZV, we should |
| 1733 | stop reading, even if the form read sets point |
| 1734 | to a different value when evaluated. */ |
| 1735 | if (BUFFERP (readcharfun)) |
| 1736 | { |
| 1737 | struct buffer *b = XBUFFER (readcharfun); |
| 1738 | if (BUF_PT (b) == BUF_ZV (b)) |
| 1739 | continue_reading_p = 0; |
| 1740 | } |
| 1741 | } |
| 1742 | else if (! NILP (Vload_read_function)) |
| 1743 | val = call1 (Vload_read_function, readcharfun); |
| 1744 | else |
| 1745 | val = read_internal_start (readcharfun, Qnil, Qnil); |
| 1746 | } |
| 1747 | |
| 1748 | if (!NILP (start) && continue_reading_p) |
| 1749 | start = Fpoint_marker (); |
| 1750 | |
| 1751 | /* Restore saved point and BEGV. */ |
| 1752 | unbind_to (count1, Qnil); |
| 1753 | |
| 1754 | /* Now eval what we just read. */ |
| 1755 | val = (*evalfun) (val); |
| 1756 | |
| 1757 | if (printflag) |
| 1758 | { |
| 1759 | Vvalues = Fcons (val, Vvalues); |
| 1760 | if (EQ (Vstandard_output, Qt)) |
| 1761 | Fprin1 (val, Qnil); |
| 1762 | else |
| 1763 | Fprint (val, Qnil); |
| 1764 | } |
| 1765 | |
| 1766 | first_sexp = 0; |
| 1767 | } |
| 1768 | |
| 1769 | build_load_history (sourcename, |
| 1770 | stream || whole_buffer); |
| 1771 | |
| 1772 | UNGCPRO; |
| 1773 | |
| 1774 | unbind_to (count, Qnil); |
| 1775 | } |
| 1776 | |
| 1777 | DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "", |
| 1778 | doc: /* Execute the current buffer as Lisp code. |
| 1779 | When called from a Lisp program (i.e., not interactively), this |
| 1780 | function accepts up to five optional arguments: |
| 1781 | BUFFER is the buffer to evaluate (nil means use current buffer). |
| 1782 | PRINTFLAG controls printing of output: |
| 1783 | A value of nil means discard it; anything else is stream for print. |
| 1784 | FILENAME specifies the file name to use for `load-history'. |
| 1785 | UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this |
| 1786 | invocation. |
| 1787 | DO-ALLOW-PRINT, if non-nil, specifies that `print' and related |
| 1788 | functions should work normally even if PRINTFLAG is nil. |
| 1789 | |
| 1790 | This function preserves the position of point. */) |
| 1791 | (buffer, printflag, filename, unibyte, do_allow_print) |
| 1792 | Lisp_Object buffer, printflag, filename, unibyte, do_allow_print; |
| 1793 | { |
| 1794 | int count = SPECPDL_INDEX (); |
| 1795 | Lisp_Object tem, buf; |
| 1796 | |
| 1797 | if (NILP (buffer)) |
| 1798 | buf = Fcurrent_buffer (); |
| 1799 | else |
| 1800 | buf = Fget_buffer (buffer); |
| 1801 | if (NILP (buf)) |
| 1802 | error ("No such buffer"); |
| 1803 | |
| 1804 | if (NILP (printflag) && NILP (do_allow_print)) |
| 1805 | tem = Qsymbolp; |
| 1806 | else |
| 1807 | tem = printflag; |
| 1808 | |
| 1809 | if (NILP (filename)) |
| 1810 | filename = XBUFFER (buf)->filename; |
| 1811 | |
| 1812 | specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list)); |
| 1813 | specbind (Qstandard_output, tem); |
| 1814 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
| 1815 | BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); |
| 1816 | readevalloop (buf, 0, filename, Feval, |
| 1817 | !NILP (printflag), unibyte, Qnil, Qnil, Qnil); |
| 1818 | unbind_to (count, Qnil); |
| 1819 | |
| 1820 | return Qnil; |
| 1821 | } |
| 1822 | |
| 1823 | DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r", |
| 1824 | doc: /* Execute the region as Lisp code. |
| 1825 | When called from programs, expects two arguments, |
| 1826 | giving starting and ending indices in the current buffer |
| 1827 | of the text to be executed. |
| 1828 | Programs can pass third argument PRINTFLAG which controls output: |
| 1829 | A value of nil means discard it; anything else is stream for printing it. |
| 1830 | Also the fourth argument READ-FUNCTION, if non-nil, is used |
| 1831 | instead of `read' to read each expression. It gets one argument |
| 1832 | which is the input stream for reading characters. |
| 1833 | |
| 1834 | This function does not move point. */) |
| 1835 | (start, end, printflag, read_function) |
| 1836 | Lisp_Object start, end, printflag, read_function; |
| 1837 | { |
| 1838 | int count = SPECPDL_INDEX (); |
| 1839 | Lisp_Object tem, cbuf; |
| 1840 | |
| 1841 | cbuf = Fcurrent_buffer (); |
| 1842 | |
| 1843 | if (NILP (printflag)) |
| 1844 | tem = Qsymbolp; |
| 1845 | else |
| 1846 | tem = printflag; |
| 1847 | specbind (Qstandard_output, tem); |
| 1848 | specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list)); |
| 1849 | |
| 1850 | /* readevalloop calls functions which check the type of start and end. */ |
| 1851 | readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, |
| 1852 | !NILP (printflag), Qnil, read_function, |
| 1853 | start, end); |
| 1854 | |
| 1855 | return unbind_to (count, Qnil); |
| 1856 | } |
| 1857 | |
| 1858 | \f |
| 1859 | DEFUN ("read", Fread, Sread, 0, 1, 0, |
| 1860 | doc: /* Read one Lisp expression as text from STREAM, return as Lisp object. |
| 1861 | If STREAM is nil, use the value of `standard-input' (which see). |
| 1862 | STREAM or the value of `standard-input' may be: |
| 1863 | a buffer (read from point and advance it) |
| 1864 | a marker (read from where it points and advance it) |
| 1865 | a function (call it with no arguments for each character, |
| 1866 | call it with a char as argument to push a char back) |
| 1867 | a string (takes text from string, starting at the beginning) |
| 1868 | t (read text line using minibuffer and use it, or read from |
| 1869 | standard input in batch mode). */) |
| 1870 | (stream) |
| 1871 | Lisp_Object stream; |
| 1872 | { |
| 1873 | if (NILP (stream)) |
| 1874 | stream = Vstandard_input; |
| 1875 | if (EQ (stream, Qt)) |
| 1876 | stream = Qread_char; |
| 1877 | if (EQ (stream, Qread_char)) |
| 1878 | return Fread_minibuffer (build_string ("Lisp expression: "), Qnil); |
| 1879 | |
| 1880 | return read_internal_start (stream, Qnil, Qnil); |
| 1881 | } |
| 1882 | |
| 1883 | DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0, |
| 1884 | doc: /* Read one Lisp expression which is represented as text by STRING. |
| 1885 | Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). |
| 1886 | START and END optionally delimit a substring of STRING from which to read; |
| 1887 | they default to 0 and (length STRING) respectively. */) |
| 1888 | (string, start, end) |
| 1889 | Lisp_Object string, start, end; |
| 1890 | { |
| 1891 | Lisp_Object ret; |
| 1892 | CHECK_STRING (string); |
| 1893 | /* read_internal_start sets read_from_string_index. */ |
| 1894 | ret = read_internal_start (string, start, end); |
| 1895 | return Fcons (ret, make_number (read_from_string_index)); |
| 1896 | } |
| 1897 | |
| 1898 | /* Function to set up the global context we need in toplevel read |
| 1899 | calls. */ |
| 1900 | static Lisp_Object |
| 1901 | read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end) |
| 1902 | |
| 1903 | /* Only used when stream is a string. */ |
| 1904 | /* Only used when stream is a string. */ |
| 1905 | { |
| 1906 | Lisp_Object retval; |
| 1907 | |
| 1908 | readchar_count = 0; |
| 1909 | new_backquote_flag = 0; |
| 1910 | read_objects = Qnil; |
| 1911 | if (EQ (Vread_with_symbol_positions, Qt) |
| 1912 | || EQ (Vread_with_symbol_positions, stream)) |
| 1913 | Vread_symbol_positions_list = Qnil; |
| 1914 | |
| 1915 | if (STRINGP (stream) |
| 1916 | || ((CONSP (stream) && STRINGP (XCAR (stream))))) |
| 1917 | { |
| 1918 | int startval, endval; |
| 1919 | Lisp_Object string; |
| 1920 | |
| 1921 | if (STRINGP (stream)) |
| 1922 | string = stream; |
| 1923 | else |
| 1924 | string = XCAR (stream); |
| 1925 | |
| 1926 | if (NILP (end)) |
| 1927 | endval = SCHARS (string); |
| 1928 | else |
| 1929 | { |
| 1930 | CHECK_NUMBER (end); |
| 1931 | endval = XINT (end); |
| 1932 | if (endval < 0 || endval > SCHARS (string)) |
| 1933 | args_out_of_range (string, end); |
| 1934 | } |
| 1935 | |
| 1936 | if (NILP (start)) |
| 1937 | startval = 0; |
| 1938 | else |
| 1939 | { |
| 1940 | CHECK_NUMBER (start); |
| 1941 | startval = XINT (start); |
| 1942 | if (startval < 0 || startval > endval) |
| 1943 | args_out_of_range (string, start); |
| 1944 | } |
| 1945 | read_from_string_index = startval; |
| 1946 | read_from_string_index_byte = string_char_to_byte (string, startval); |
| 1947 | read_from_string_limit = endval; |
| 1948 | } |
| 1949 | |
| 1950 | retval = read0 (stream); |
| 1951 | if (EQ (Vread_with_symbol_positions, Qt) |
| 1952 | || EQ (Vread_with_symbol_positions, stream)) |
| 1953 | Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list); |
| 1954 | return retval; |
| 1955 | } |
| 1956 | \f |
| 1957 | |
| 1958 | /* Signal Qinvalid_read_syntax error. |
| 1959 | S is error string of length N (if > 0) */ |
| 1960 | |
| 1961 | static void |
| 1962 | invalid_syntax (const char *s, int n) |
| 1963 | { |
| 1964 | if (!n) |
| 1965 | n = strlen (s); |
| 1966 | xsignal1 (Qinvalid_read_syntax, make_string (s, n)); |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | /* Use this for recursive reads, in contexts where internal tokens |
| 1971 | are not allowed. */ |
| 1972 | |
| 1973 | static Lisp_Object |
| 1974 | read0 (Lisp_Object readcharfun) |
| 1975 | { |
| 1976 | register Lisp_Object val; |
| 1977 | int c; |
| 1978 | |
| 1979 | val = read1 (readcharfun, &c, 0); |
| 1980 | if (!c) |
| 1981 | return val; |
| 1982 | |
| 1983 | xsignal1 (Qinvalid_read_syntax, |
| 1984 | Fmake_string (make_number (1), make_number (c))); |
| 1985 | } |
| 1986 | \f |
| 1987 | static int read_buffer_size; |
| 1988 | static char *read_buffer; |
| 1989 | |
| 1990 | /* Read a \-escape sequence, assuming we already read the `\'. |
| 1991 | If the escape sequence forces unibyte, return eight-bit char. */ |
| 1992 | |
| 1993 | static int |
| 1994 | read_escape (Lisp_Object readcharfun, int stringp) |
| 1995 | { |
| 1996 | register int c = READCHAR; |
| 1997 | /* \u allows up to four hex digits, \U up to eight. Default to the |
| 1998 | behavior for \u, and change this value in the case that \U is seen. */ |
| 1999 | int unicode_hex_count = 4; |
| 2000 | |
| 2001 | switch (c) |
| 2002 | { |
| 2003 | case -1: |
| 2004 | end_of_file_error (); |
| 2005 | |
| 2006 | case 'a': |
| 2007 | return '\007'; |
| 2008 | case 'b': |
| 2009 | return '\b'; |
| 2010 | case 'd': |
| 2011 | return 0177; |
| 2012 | case 'e': |
| 2013 | return 033; |
| 2014 | case 'f': |
| 2015 | return '\f'; |
| 2016 | case 'n': |
| 2017 | return '\n'; |
| 2018 | case 'r': |
| 2019 | return '\r'; |
| 2020 | case 't': |
| 2021 | return '\t'; |
| 2022 | case 'v': |
| 2023 | return '\v'; |
| 2024 | case '\n': |
| 2025 | return -1; |
| 2026 | case ' ': |
| 2027 | if (stringp) |
| 2028 | return -1; |
| 2029 | return ' '; |
| 2030 | |
| 2031 | case 'M': |
| 2032 | c = READCHAR; |
| 2033 | if (c != '-') |
| 2034 | error ("Invalid escape character syntax"); |
| 2035 | c = READCHAR; |
| 2036 | if (c == '\\') |
| 2037 | c = read_escape (readcharfun, 0); |
| 2038 | return c | meta_modifier; |
| 2039 | |
| 2040 | case 'S': |
| 2041 | c = READCHAR; |
| 2042 | if (c != '-') |
| 2043 | error ("Invalid escape character syntax"); |
| 2044 | c = READCHAR; |
| 2045 | if (c == '\\') |
| 2046 | c = read_escape (readcharfun, 0); |
| 2047 | return c | shift_modifier; |
| 2048 | |
| 2049 | case 'H': |
| 2050 | c = READCHAR; |
| 2051 | if (c != '-') |
| 2052 | error ("Invalid escape character syntax"); |
| 2053 | c = READCHAR; |
| 2054 | if (c == '\\') |
| 2055 | c = read_escape (readcharfun, 0); |
| 2056 | return c | hyper_modifier; |
| 2057 | |
| 2058 | case 'A': |
| 2059 | c = READCHAR; |
| 2060 | if (c != '-') |
| 2061 | error ("Invalid escape character syntax"); |
| 2062 | c = READCHAR; |
| 2063 | if (c == '\\') |
| 2064 | c = read_escape (readcharfun, 0); |
| 2065 | return c | alt_modifier; |
| 2066 | |
| 2067 | case 's': |
| 2068 | c = READCHAR; |
| 2069 | if (stringp || c != '-') |
| 2070 | { |
| 2071 | UNREAD (c); |
| 2072 | return ' '; |
| 2073 | } |
| 2074 | c = READCHAR; |
| 2075 | if (c == '\\') |
| 2076 | c = read_escape (readcharfun, 0); |
| 2077 | return c | super_modifier; |
| 2078 | |
| 2079 | case 'C': |
| 2080 | c = READCHAR; |
| 2081 | if (c != '-') |
| 2082 | error ("Invalid escape character syntax"); |
| 2083 | case '^': |
| 2084 | c = READCHAR; |
| 2085 | if (c == '\\') |
| 2086 | c = read_escape (readcharfun, 0); |
| 2087 | if ((c & ~CHAR_MODIFIER_MASK) == '?') |
| 2088 | return 0177 | (c & CHAR_MODIFIER_MASK); |
| 2089 | else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) |
| 2090 | return c | ctrl_modifier; |
| 2091 | /* ASCII control chars are made from letters (both cases), |
| 2092 | as well as the non-letters within 0100...0137. */ |
| 2093 | else if ((c & 0137) >= 0101 && (c & 0137) <= 0132) |
| 2094 | return (c & (037 | ~0177)); |
| 2095 | else if ((c & 0177) >= 0100 && (c & 0177) <= 0137) |
| 2096 | return (c & (037 | ~0177)); |
| 2097 | else |
| 2098 | return c | ctrl_modifier; |
| 2099 | |
| 2100 | case '0': |
| 2101 | case '1': |
| 2102 | case '2': |
| 2103 | case '3': |
| 2104 | case '4': |
| 2105 | case '5': |
| 2106 | case '6': |
| 2107 | case '7': |
| 2108 | /* An octal escape, as in ANSI C. */ |
| 2109 | { |
| 2110 | register int i = c - '0'; |
| 2111 | register int count = 0; |
| 2112 | while (++count < 3) |
| 2113 | { |
| 2114 | if ((c = READCHAR) >= '0' && c <= '7') |
| 2115 | { |
| 2116 | i *= 8; |
| 2117 | i += c - '0'; |
| 2118 | } |
| 2119 | else |
| 2120 | { |
| 2121 | UNREAD (c); |
| 2122 | break; |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | if (i >= 0x80 && i < 0x100) |
| 2127 | i = BYTE8_TO_CHAR (i); |
| 2128 | return i; |
| 2129 | } |
| 2130 | |
| 2131 | case 'x': |
| 2132 | /* A hex escape, as in ANSI C. */ |
| 2133 | { |
| 2134 | int i = 0; |
| 2135 | int count = 0; |
| 2136 | while (1) |
| 2137 | { |
| 2138 | c = READCHAR; |
| 2139 | if (c >= '0' && c <= '9') |
| 2140 | { |
| 2141 | i *= 16; |
| 2142 | i += c - '0'; |
| 2143 | } |
| 2144 | else if ((c >= 'a' && c <= 'f') |
| 2145 | || (c >= 'A' && c <= 'F')) |
| 2146 | { |
| 2147 | i *= 16; |
| 2148 | if (c >= 'a' && c <= 'f') |
| 2149 | i += c - 'a' + 10; |
| 2150 | else |
| 2151 | i += c - 'A' + 10; |
| 2152 | } |
| 2153 | else |
| 2154 | { |
| 2155 | UNREAD (c); |
| 2156 | break; |
| 2157 | } |
| 2158 | count++; |
| 2159 | } |
| 2160 | |
| 2161 | if (count < 3 && i >= 0x80) |
| 2162 | return BYTE8_TO_CHAR (i); |
| 2163 | return i; |
| 2164 | } |
| 2165 | |
| 2166 | case 'U': |
| 2167 | /* Post-Unicode-2.0: Up to eight hex chars. */ |
| 2168 | unicode_hex_count = 8; |
| 2169 | case 'u': |
| 2170 | |
| 2171 | /* A Unicode escape. We only permit them in strings and characters, |
| 2172 | not arbitrarily in the source code, as in some other languages. */ |
| 2173 | { |
| 2174 | unsigned int i = 0; |
| 2175 | int count = 0; |
| 2176 | |
| 2177 | while (++count <= unicode_hex_count) |
| 2178 | { |
| 2179 | c = READCHAR; |
| 2180 | /* isdigit and isalpha may be locale-specific, which we don't |
| 2181 | want. */ |
| 2182 | if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
| 2183 | else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; |
| 2184 | else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; |
| 2185 | else |
| 2186 | { |
| 2187 | error ("Non-hex digit used for Unicode escape"); |
| 2188 | break; |
| 2189 | } |
| 2190 | } |
| 2191 | if (i > 0x10FFFF) |
| 2192 | error ("Non-Unicode character: 0x%x", i); |
| 2193 | return i; |
| 2194 | } |
| 2195 | |
| 2196 | default: |
| 2197 | return c; |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | /* Read an integer in radix RADIX using READCHARFUN to read |
| 2202 | characters. RADIX must be in the interval [2..36]; if it isn't, a |
| 2203 | read error is signaled . Value is the integer read. Signals an |
| 2204 | error if encountering invalid read syntax or if RADIX is out of |
| 2205 | range. */ |
| 2206 | |
| 2207 | static Lisp_Object |
| 2208 | read_integer (Lisp_Object readcharfun, int radix) |
| 2209 | { |
| 2210 | int ndigits = 0, invalid_p, c, sign = 0; |
| 2211 | /* We use a floating point number because */ |
| 2212 | double number = 0; |
| 2213 | |
| 2214 | if (radix < 2 || radix > 36) |
| 2215 | invalid_p = 1; |
| 2216 | else |
| 2217 | { |
| 2218 | number = ndigits = invalid_p = 0; |
| 2219 | sign = 1; |
| 2220 | |
| 2221 | c = READCHAR; |
| 2222 | if (c == '-') |
| 2223 | { |
| 2224 | c = READCHAR; |
| 2225 | sign = -1; |
| 2226 | } |
| 2227 | else if (c == '+') |
| 2228 | c = READCHAR; |
| 2229 | |
| 2230 | while (c >= 0) |
| 2231 | { |
| 2232 | int digit; |
| 2233 | |
| 2234 | if (c >= '0' && c <= '9') |
| 2235 | digit = c - '0'; |
| 2236 | else if (c >= 'a' && c <= 'z') |
| 2237 | digit = c - 'a' + 10; |
| 2238 | else if (c >= 'A' && c <= 'Z') |
| 2239 | digit = c - 'A' + 10; |
| 2240 | else |
| 2241 | { |
| 2242 | UNREAD (c); |
| 2243 | break; |
| 2244 | } |
| 2245 | |
| 2246 | if (digit < 0 || digit >= radix) |
| 2247 | invalid_p = 1; |
| 2248 | |
| 2249 | number = radix * number + digit; |
| 2250 | ++ndigits; |
| 2251 | c = READCHAR; |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | if (ndigits == 0 || invalid_p) |
| 2256 | { |
| 2257 | char buf[50]; |
| 2258 | sprintf (buf, "integer, radix %d", radix); |
| 2259 | invalid_syntax (buf, 0); |
| 2260 | } |
| 2261 | |
| 2262 | return make_fixnum_or_float (sign * number); |
| 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | /* If the next token is ')' or ']' or '.', we store that character |
| 2267 | in *PCH and the return value is not interesting. Else, we store |
| 2268 | zero in *PCH and we read and return one lisp object. |
| 2269 | |
| 2270 | FIRST_IN_LIST is nonzero if this is the first element of a list. */ |
| 2271 | |
| 2272 | static Lisp_Object |
| 2273 | read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) |
| 2274 | { |
| 2275 | register int c; |
| 2276 | int uninterned_symbol = 0; |
| 2277 | int multibyte; |
| 2278 | |
| 2279 | *pch = 0; |
| 2280 | load_each_byte = 0; |
| 2281 | |
| 2282 | retry: |
| 2283 | |
| 2284 | c = READCHAR_REPORT_MULTIBYTE (&multibyte); |
| 2285 | if (c < 0) |
| 2286 | end_of_file_error (); |
| 2287 | |
| 2288 | switch (c) |
| 2289 | { |
| 2290 | case '(': |
| 2291 | return read_list (0, readcharfun); |
| 2292 | |
| 2293 | case '[': |
| 2294 | return read_vector (readcharfun, 0); |
| 2295 | |
| 2296 | case ')': |
| 2297 | case ']': |
| 2298 | { |
| 2299 | *pch = c; |
| 2300 | return Qnil; |
| 2301 | } |
| 2302 | |
| 2303 | case '#': |
| 2304 | c = READCHAR; |
| 2305 | if (c == 's') |
| 2306 | { |
| 2307 | c = READCHAR; |
| 2308 | if (c == '(') |
| 2309 | { |
| 2310 | /* Accept extended format for hashtables (extensible to |
| 2311 | other types), e.g. |
| 2312 | #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ |
| 2313 | Lisp_Object tmp = read_list (0, readcharfun); |
| 2314 | Lisp_Object head = CAR_SAFE (tmp); |
| 2315 | Lisp_Object data = Qnil; |
| 2316 | Lisp_Object val = Qnil; |
| 2317 | /* The size is 2 * number of allowed keywords to |
| 2318 | make-hash-table. */ |
| 2319 | Lisp_Object params[10]; |
| 2320 | Lisp_Object ht; |
| 2321 | Lisp_Object key = Qnil; |
| 2322 | int param_count = 0; |
| 2323 | |
| 2324 | if (!EQ (head, Qhash_table)) |
| 2325 | error ("Invalid extended read marker at head of #s list " |
| 2326 | "(only hash-table allowed)"); |
| 2327 | |
| 2328 | tmp = CDR_SAFE (tmp); |
| 2329 | |
| 2330 | /* This is repetitive but fast and simple. */ |
| 2331 | params[param_count] = QCsize; |
| 2332 | params[param_count+1] = Fplist_get (tmp, Qsize); |
| 2333 | if (!NILP (params[param_count+1])) |
| 2334 | param_count+=2; |
| 2335 | |
| 2336 | params[param_count] = QCtest; |
| 2337 | params[param_count+1] = Fplist_get (tmp, Qtest); |
| 2338 | if (!NILP (params[param_count+1])) |
| 2339 | param_count+=2; |
| 2340 | |
| 2341 | params[param_count] = QCweakness; |
| 2342 | params[param_count+1] = Fplist_get (tmp, Qweakness); |
| 2343 | if (!NILP (params[param_count+1])) |
| 2344 | param_count+=2; |
| 2345 | |
| 2346 | params[param_count] = QCrehash_size; |
| 2347 | params[param_count+1] = Fplist_get (tmp, Qrehash_size); |
| 2348 | if (!NILP (params[param_count+1])) |
| 2349 | param_count+=2; |
| 2350 | |
| 2351 | params[param_count] = QCrehash_threshold; |
| 2352 | params[param_count+1] = Fplist_get (tmp, Qrehash_threshold); |
| 2353 | if (!NILP (params[param_count+1])) |
| 2354 | param_count+=2; |
| 2355 | |
| 2356 | /* This is the hashtable data. */ |
| 2357 | data = Fplist_get (tmp, Qdata); |
| 2358 | |
| 2359 | /* Now use params to make a new hashtable and fill it. */ |
| 2360 | ht = Fmake_hash_table (param_count, params); |
| 2361 | |
| 2362 | while (CONSP (data)) |
| 2363 | { |
| 2364 | key = XCAR (data); |
| 2365 | data = XCDR (data); |
| 2366 | if (!CONSP (data)) |
| 2367 | error ("Odd number of elements in hashtable data"); |
| 2368 | val = XCAR (data); |
| 2369 | data = XCDR (data); |
| 2370 | Fputhash (key, val, ht); |
| 2371 | } |
| 2372 | |
| 2373 | return ht; |
| 2374 | } |
| 2375 | } |
| 2376 | if (c == '^') |
| 2377 | { |
| 2378 | c = READCHAR; |
| 2379 | if (c == '[') |
| 2380 | { |
| 2381 | Lisp_Object tmp; |
| 2382 | tmp = read_vector (readcharfun, 0); |
| 2383 | if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS) |
| 2384 | error ("Invalid size char-table"); |
| 2385 | XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE); |
| 2386 | return tmp; |
| 2387 | } |
| 2388 | else if (c == '^') |
| 2389 | { |
| 2390 | c = READCHAR; |
| 2391 | if (c == '[') |
| 2392 | { |
| 2393 | Lisp_Object tmp; |
| 2394 | int depth, size; |
| 2395 | |
| 2396 | tmp = read_vector (readcharfun, 0); |
| 2397 | if (!INTEGERP (AREF (tmp, 0))) |
| 2398 | error ("Invalid depth in char-table"); |
| 2399 | depth = XINT (AREF (tmp, 0)); |
| 2400 | if (depth < 1 || depth > 3) |
| 2401 | error ("Invalid depth in char-table"); |
| 2402 | size = XVECTOR (tmp)->size - 2; |
| 2403 | if (chartab_size [depth] != size) |
| 2404 | error ("Invalid size char-table"); |
| 2405 | XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE); |
| 2406 | return tmp; |
| 2407 | } |
| 2408 | invalid_syntax ("#^^", 3); |
| 2409 | } |
| 2410 | invalid_syntax ("#^", 2); |
| 2411 | } |
| 2412 | if (c == '&') |
| 2413 | { |
| 2414 | Lisp_Object length; |
| 2415 | length = read1 (readcharfun, pch, first_in_list); |
| 2416 | c = READCHAR; |
| 2417 | if (c == '"') |
| 2418 | { |
| 2419 | Lisp_Object tmp, val; |
| 2420 | int size_in_chars |
| 2421 | = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1) |
| 2422 | / BOOL_VECTOR_BITS_PER_CHAR); |
| 2423 | |
| 2424 | UNREAD (c); |
| 2425 | tmp = read1 (readcharfun, pch, first_in_list); |
| 2426 | if (STRING_MULTIBYTE (tmp) |
| 2427 | || (size_in_chars != SCHARS (tmp) |
| 2428 | /* We used to print 1 char too many |
| 2429 | when the number of bits was a multiple of 8. |
| 2430 | Accept such input in case it came from an old |
| 2431 | version. */ |
| 2432 | && ! (XFASTINT (length) |
| 2433 | == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR))) |
| 2434 | invalid_syntax ("#&...", 5); |
| 2435 | |
| 2436 | val = Fmake_bool_vector (length, Qnil); |
| 2437 | bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data, |
| 2438 | size_in_chars); |
| 2439 | /* Clear the extraneous bits in the last byte. */ |
| 2440 | if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR) |
| 2441 | XBOOL_VECTOR (val)->data[size_in_chars - 1] |
| 2442 | &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; |
| 2443 | return val; |
| 2444 | } |
| 2445 | invalid_syntax ("#&...", 5); |
| 2446 | } |
| 2447 | if (c == '[') |
| 2448 | { |
| 2449 | /* Accept compiled functions at read-time so that we don't have to |
| 2450 | build them using function calls. */ |
| 2451 | Lisp_Object tmp; |
| 2452 | tmp = read_vector (readcharfun, 1); |
| 2453 | return Fmake_byte_code (XVECTOR (tmp)->size, |
| 2454 | XVECTOR (tmp)->contents); |
| 2455 | } |
| 2456 | if (c == '(') |
| 2457 | { |
| 2458 | Lisp_Object tmp; |
| 2459 | struct gcpro gcpro1; |
| 2460 | int ch; |
| 2461 | |
| 2462 | /* Read the string itself. */ |
| 2463 | tmp = read1 (readcharfun, &ch, 0); |
| 2464 | if (ch != 0 || !STRINGP (tmp)) |
| 2465 | invalid_syntax ("#", 1); |
| 2466 | GCPRO1 (tmp); |
| 2467 | /* Read the intervals and their properties. */ |
| 2468 | while (1) |
| 2469 | { |
| 2470 | Lisp_Object beg, end, plist; |
| 2471 | |
| 2472 | beg = read1 (readcharfun, &ch, 0); |
| 2473 | end = plist = Qnil; |
| 2474 | if (ch == ')') |
| 2475 | break; |
| 2476 | if (ch == 0) |
| 2477 | end = read1 (readcharfun, &ch, 0); |
| 2478 | if (ch == 0) |
| 2479 | plist = read1 (readcharfun, &ch, 0); |
| 2480 | if (ch) |
| 2481 | invalid_syntax ("Invalid string property list", 0); |
| 2482 | Fset_text_properties (beg, end, plist, tmp); |
| 2483 | } |
| 2484 | UNGCPRO; |
| 2485 | return tmp; |
| 2486 | } |
| 2487 | |
| 2488 | /* #@NUMBER is used to skip NUMBER following characters. |
| 2489 | That's used in .elc files to skip over doc strings |
| 2490 | and function definitions. */ |
| 2491 | if (c == '@') |
| 2492 | { |
| 2493 | int i, nskip = 0; |
| 2494 | |
| 2495 | load_each_byte = 1; |
| 2496 | /* Read a decimal integer. */ |
| 2497 | while ((c = READCHAR) >= 0 |
| 2498 | && c >= '0' && c <= '9') |
| 2499 | { |
| 2500 | nskip *= 10; |
| 2501 | nskip += c - '0'; |
| 2502 | } |
| 2503 | if (c >= 0) |
| 2504 | UNREAD (c); |
| 2505 | |
| 2506 | if (load_force_doc_strings |
| 2507 | && (EQ (readcharfun, Qget_file_char) |
| 2508 | || EQ (readcharfun, Qget_emacs_mule_file_char))) |
| 2509 | { |
| 2510 | /* If we are supposed to force doc strings into core right now, |
| 2511 | record the last string that we skipped, |
| 2512 | and record where in the file it comes from. */ |
| 2513 | |
| 2514 | /* But first exchange saved_doc_string |
| 2515 | with prev_saved_doc_string, so we save two strings. */ |
| 2516 | { |
| 2517 | char *temp = saved_doc_string; |
| 2518 | int temp_size = saved_doc_string_size; |
| 2519 | file_offset temp_pos = saved_doc_string_position; |
| 2520 | int temp_len = saved_doc_string_length; |
| 2521 | |
| 2522 | saved_doc_string = prev_saved_doc_string; |
| 2523 | saved_doc_string_size = prev_saved_doc_string_size; |
| 2524 | saved_doc_string_position = prev_saved_doc_string_position; |
| 2525 | saved_doc_string_length = prev_saved_doc_string_length; |
| 2526 | |
| 2527 | prev_saved_doc_string = temp; |
| 2528 | prev_saved_doc_string_size = temp_size; |
| 2529 | prev_saved_doc_string_position = temp_pos; |
| 2530 | prev_saved_doc_string_length = temp_len; |
| 2531 | } |
| 2532 | |
| 2533 | if (saved_doc_string_size == 0) |
| 2534 | { |
| 2535 | saved_doc_string_size = nskip + 100; |
| 2536 | saved_doc_string = (char *) xmalloc (saved_doc_string_size); |
| 2537 | } |
| 2538 | if (nskip > saved_doc_string_size) |
| 2539 | { |
| 2540 | saved_doc_string_size = nskip + 100; |
| 2541 | saved_doc_string = (char *) xrealloc (saved_doc_string, |
| 2542 | saved_doc_string_size); |
| 2543 | } |
| 2544 | |
| 2545 | saved_doc_string_position = file_tell (instream); |
| 2546 | |
| 2547 | /* Copy that many characters into saved_doc_string. */ |
| 2548 | for (i = 0; i < nskip && c >= 0; i++) |
| 2549 | saved_doc_string[i] = c = READCHAR; |
| 2550 | |
| 2551 | saved_doc_string_length = i; |
| 2552 | } |
| 2553 | else |
| 2554 | { |
| 2555 | /* Skip that many characters. */ |
| 2556 | for (i = 0; i < nskip && c >= 0; i++) |
| 2557 | c = READCHAR; |
| 2558 | } |
| 2559 | |
| 2560 | load_each_byte = 0; |
| 2561 | goto retry; |
| 2562 | } |
| 2563 | if (c == '!') |
| 2564 | { |
| 2565 | /* #! appears at the beginning of an executable file. |
| 2566 | Skip the first line. */ |
| 2567 | while (c != '\n' && c >= 0) |
| 2568 | c = READCHAR; |
| 2569 | goto retry; |
| 2570 | } |
| 2571 | if (c == '$') |
| 2572 | return Vload_file_name; |
| 2573 | if (c == '\'') |
| 2574 | return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil)); |
| 2575 | /* #:foo is the uninterned symbol named foo. */ |
| 2576 | if (c == ':') |
| 2577 | { |
| 2578 | uninterned_symbol = 1; |
| 2579 | c = READCHAR; |
| 2580 | goto default_label; |
| 2581 | } |
| 2582 | /* Reader forms that can reuse previously read objects. */ |
| 2583 | if (c >= '0' && c <= '9') |
| 2584 | { |
| 2585 | int n = 0; |
| 2586 | Lisp_Object tem; |
| 2587 | |
| 2588 | /* Read a non-negative integer. */ |
| 2589 | while (c >= '0' && c <= '9') |
| 2590 | { |
| 2591 | n *= 10; |
| 2592 | n += c - '0'; |
| 2593 | c = READCHAR; |
| 2594 | } |
| 2595 | /* #n=object returns object, but associates it with n for #n#. */ |
| 2596 | if (c == '=' && !NILP (Vread_circle)) |
| 2597 | { |
| 2598 | /* Make a placeholder for #n# to use temporarily */ |
| 2599 | Lisp_Object placeholder; |
| 2600 | Lisp_Object cell; |
| 2601 | |
| 2602 | placeholder = Fcons (Qnil, Qnil); |
| 2603 | cell = Fcons (make_number (n), placeholder); |
| 2604 | read_objects = Fcons (cell, read_objects); |
| 2605 | |
| 2606 | /* Read the object itself. */ |
| 2607 | tem = read0 (readcharfun); |
| 2608 | |
| 2609 | /* Now put it everywhere the placeholder was... */ |
| 2610 | substitute_object_in_subtree (tem, placeholder); |
| 2611 | |
| 2612 | /* ...and #n# will use the real value from now on. */ |
| 2613 | Fsetcdr (cell, tem); |
| 2614 | |
| 2615 | return tem; |
| 2616 | } |
| 2617 | /* #n# returns a previously read object. */ |
| 2618 | if (c == '#' && !NILP (Vread_circle)) |
| 2619 | { |
| 2620 | tem = Fassq (make_number (n), read_objects); |
| 2621 | if (CONSP (tem)) |
| 2622 | return XCDR (tem); |
| 2623 | /* Fall through to error message. */ |
| 2624 | } |
| 2625 | else if (c == 'r' || c == 'R') |
| 2626 | return read_integer (readcharfun, n); |
| 2627 | |
| 2628 | /* Fall through to error message. */ |
| 2629 | } |
| 2630 | else if (c == 'x' || c == 'X') |
| 2631 | return read_integer (readcharfun, 16); |
| 2632 | else if (c == 'o' || c == 'O') |
| 2633 | return read_integer (readcharfun, 8); |
| 2634 | else if (c == 'b' || c == 'B') |
| 2635 | return read_integer (readcharfun, 2); |
| 2636 | |
| 2637 | UNREAD (c); |
| 2638 | invalid_syntax ("#", 1); |
| 2639 | |
| 2640 | case ';': |
| 2641 | while ((c = READCHAR) >= 0 && c != '\n'); |
| 2642 | goto retry; |
| 2643 | |
| 2644 | case '\'': |
| 2645 | { |
| 2646 | return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil)); |
| 2647 | } |
| 2648 | |
| 2649 | case '`': |
| 2650 | /* Transition from old-style to new-style: |
| 2651 | If we see "(`" it used to mean old-style, which usually works |
| 2652 | fine because ` should almost never appear in such a position |
| 2653 | for new-style. But occasionally we need "(`" to mean new |
| 2654 | style, so we try to distinguish the two by the fact that we |
| 2655 | can either write "( `foo" or "(` foo", where the first |
| 2656 | intends to use new-style whereas the second intends to use |
| 2657 | old-style. For Emacs-25, we should completely remove this |
| 2658 | first_in_list exception (old-style can still be obtained via |
| 2659 | "(\`" anyway). */ |
| 2660 | if (first_in_list && (c = READCHAR, UNREAD (c), c == ' ')) |
| 2661 | { |
| 2662 | Vold_style_backquotes = Qt; |
| 2663 | goto default_label; |
| 2664 | } |
| 2665 | else |
| 2666 | { |
| 2667 | Lisp_Object value; |
| 2668 | |
| 2669 | new_backquote_flag++; |
| 2670 | value = read0 (readcharfun); |
| 2671 | new_backquote_flag--; |
| 2672 | |
| 2673 | return Fcons (Qbackquote, Fcons (value, Qnil)); |
| 2674 | } |
| 2675 | |
| 2676 | case ',': |
| 2677 | if (new_backquote_flag) |
| 2678 | { |
| 2679 | Lisp_Object comma_type = Qnil; |
| 2680 | Lisp_Object value; |
| 2681 | int ch = READCHAR; |
| 2682 | |
| 2683 | if (ch == '@') |
| 2684 | comma_type = Qcomma_at; |
| 2685 | else if (ch == '.') |
| 2686 | comma_type = Qcomma_dot; |
| 2687 | else |
| 2688 | { |
| 2689 | if (ch >= 0) UNREAD (ch); |
| 2690 | comma_type = Qcomma; |
| 2691 | } |
| 2692 | |
| 2693 | new_backquote_flag--; |
| 2694 | value = read0 (readcharfun); |
| 2695 | new_backquote_flag++; |
| 2696 | return Fcons (comma_type, Fcons (value, Qnil)); |
| 2697 | } |
| 2698 | else |
| 2699 | { |
| 2700 | Vold_style_backquotes = Qt; |
| 2701 | goto default_label; |
| 2702 | } |
| 2703 | |
| 2704 | case '?': |
| 2705 | { |
| 2706 | int modifiers; |
| 2707 | int next_char; |
| 2708 | int ok; |
| 2709 | |
| 2710 | c = READCHAR; |
| 2711 | if (c < 0) |
| 2712 | end_of_file_error (); |
| 2713 | |
| 2714 | /* Accept `single space' syntax like (list ? x) where the |
| 2715 | whitespace character is SPC or TAB. |
| 2716 | Other literal whitespace like NL, CR, and FF are not accepted, |
| 2717 | as there are well-established escape sequences for these. */ |
| 2718 | if (c == ' ' || c == '\t') |
| 2719 | return make_number (c); |
| 2720 | |
| 2721 | if (c == '\\') |
| 2722 | c = read_escape (readcharfun, 0); |
| 2723 | modifiers = c & CHAR_MODIFIER_MASK; |
| 2724 | c &= ~CHAR_MODIFIER_MASK; |
| 2725 | if (CHAR_BYTE8_P (c)) |
| 2726 | c = CHAR_TO_BYTE8 (c); |
| 2727 | c |= modifiers; |
| 2728 | |
| 2729 | next_char = READCHAR; |
| 2730 | if (next_char == '.') |
| 2731 | { |
| 2732 | /* Only a dotted-pair dot is valid after a char constant. */ |
| 2733 | int next_next_char = READCHAR; |
| 2734 | UNREAD (next_next_char); |
| 2735 | |
| 2736 | ok = (next_next_char <= 040 |
| 2737 | || (next_next_char < 0200 |
| 2738 | && (index ("\"';([#?", next_next_char) |
| 2739 | || (!first_in_list && next_next_char == '`') |
| 2740 | || (new_backquote_flag && next_next_char == ',')))); |
| 2741 | } |
| 2742 | else |
| 2743 | { |
| 2744 | ok = (next_char <= 040 |
| 2745 | || (next_char < 0200 |
| 2746 | && (index ("\"';()[]#?", next_char) |
| 2747 | || (!first_in_list && next_char == '`') |
| 2748 | || (new_backquote_flag && next_char == ',')))); |
| 2749 | } |
| 2750 | UNREAD (next_char); |
| 2751 | if (ok) |
| 2752 | return make_number (c); |
| 2753 | |
| 2754 | invalid_syntax ("?", 1); |
| 2755 | } |
| 2756 | |
| 2757 | case '"': |
| 2758 | { |
| 2759 | char *p = read_buffer; |
| 2760 | char *end = read_buffer + read_buffer_size; |
| 2761 | register int c; |
| 2762 | /* Nonzero if we saw an escape sequence specifying |
| 2763 | a multibyte character. */ |
| 2764 | int force_multibyte = 0; |
| 2765 | /* Nonzero if we saw an escape sequence specifying |
| 2766 | a single-byte character. */ |
| 2767 | int force_singlebyte = 0; |
| 2768 | int cancel = 0; |
| 2769 | int nchars = 0; |
| 2770 | |
| 2771 | while ((c = READCHAR) >= 0 |
| 2772 | && c != '\"') |
| 2773 | { |
| 2774 | if (end - p < MAX_MULTIBYTE_LENGTH) |
| 2775 | { |
| 2776 | int offset = p - read_buffer; |
| 2777 | read_buffer = (char *) xrealloc (read_buffer, |
| 2778 | read_buffer_size *= 2); |
| 2779 | p = read_buffer + offset; |
| 2780 | end = read_buffer + read_buffer_size; |
| 2781 | } |
| 2782 | |
| 2783 | if (c == '\\') |
| 2784 | { |
| 2785 | int modifiers; |
| 2786 | |
| 2787 | c = read_escape (readcharfun, 1); |
| 2788 | |
| 2789 | /* C is -1 if \ newline has just been seen */ |
| 2790 | if (c == -1) |
| 2791 | { |
| 2792 | if (p == read_buffer) |
| 2793 | cancel = 1; |
| 2794 | continue; |
| 2795 | } |
| 2796 | |
| 2797 | modifiers = c & CHAR_MODIFIER_MASK; |
| 2798 | c = c & ~CHAR_MODIFIER_MASK; |
| 2799 | |
| 2800 | if (CHAR_BYTE8_P (c)) |
| 2801 | force_singlebyte = 1; |
| 2802 | else if (! ASCII_CHAR_P (c)) |
| 2803 | force_multibyte = 1; |
| 2804 | else /* i.e. ASCII_CHAR_P (c) */ |
| 2805 | { |
| 2806 | /* Allow `\C- ' and `\C-?'. */ |
| 2807 | if (modifiers == CHAR_CTL) |
| 2808 | { |
| 2809 | if (c == ' ') |
| 2810 | c = 0, modifiers = 0; |
| 2811 | else if (c == '?') |
| 2812 | c = 127, modifiers = 0; |
| 2813 | } |
| 2814 | if (modifiers & CHAR_SHIFT) |
| 2815 | { |
| 2816 | /* Shift modifier is valid only with [A-Za-z]. */ |
| 2817 | if (c >= 'A' && c <= 'Z') |
| 2818 | modifiers &= ~CHAR_SHIFT; |
| 2819 | else if (c >= 'a' && c <= 'z') |
| 2820 | c -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT; |
| 2821 | } |
| 2822 | |
| 2823 | if (modifiers & CHAR_META) |
| 2824 | { |
| 2825 | /* Move the meta bit to the right place for a |
| 2826 | string. */ |
| 2827 | modifiers &= ~CHAR_META; |
| 2828 | c = BYTE8_TO_CHAR (c | 0x80); |
| 2829 | force_singlebyte = 1; |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | /* Any modifiers remaining are invalid. */ |
| 2834 | if (modifiers) |
| 2835 | error ("Invalid modifier in string"); |
| 2836 | p += CHAR_STRING (c, (unsigned char *) p); |
| 2837 | } |
| 2838 | else |
| 2839 | { |
| 2840 | p += CHAR_STRING (c, (unsigned char *) p); |
| 2841 | if (CHAR_BYTE8_P (c)) |
| 2842 | force_singlebyte = 1; |
| 2843 | else if (! ASCII_CHAR_P (c)) |
| 2844 | force_multibyte = 1; |
| 2845 | } |
| 2846 | nchars++; |
| 2847 | } |
| 2848 | |
| 2849 | if (c < 0) |
| 2850 | end_of_file_error (); |
| 2851 | |
| 2852 | /* If purifying, and string starts with \ newline, |
| 2853 | return zero instead. This is for doc strings |
| 2854 | that we are really going to find in etc/DOC.nn.nn */ |
| 2855 | if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel) |
| 2856 | return make_number (0); |
| 2857 | |
| 2858 | if (force_multibyte) |
| 2859 | /* READ_BUFFER already contains valid multibyte forms. */ |
| 2860 | ; |
| 2861 | else if (force_singlebyte) |
| 2862 | { |
| 2863 | nchars = str_as_unibyte (read_buffer, p - read_buffer); |
| 2864 | p = read_buffer + nchars; |
| 2865 | } |
| 2866 | else |
| 2867 | /* Otherwise, READ_BUFFER contains only ASCII. */ |
| 2868 | ; |
| 2869 | |
| 2870 | /* We want readchar_count to be the number of characters, not |
| 2871 | bytes. Hence we adjust for multibyte characters in the |
| 2872 | string. ... But it doesn't seem to be necessary, because |
| 2873 | READCHAR *does* read multibyte characters from buffers. */ |
| 2874 | /* readchar_count -= (p - read_buffer) - nchars; */ |
| 2875 | if (read_pure) |
| 2876 | return make_pure_string (read_buffer, nchars, p - read_buffer, |
| 2877 | (force_multibyte |
| 2878 | || (p - read_buffer != nchars))); |
| 2879 | return make_specified_string (read_buffer, nchars, p - read_buffer, |
| 2880 | (force_multibyte |
| 2881 | || (p - read_buffer != nchars))); |
| 2882 | } |
| 2883 | |
| 2884 | case '.': |
| 2885 | { |
| 2886 | int next_char = READCHAR; |
| 2887 | UNREAD (next_char); |
| 2888 | |
| 2889 | if (next_char <= 040 |
| 2890 | || (next_char < 0200 |
| 2891 | && (index ("\"';([#?", next_char) |
| 2892 | || (!first_in_list && next_char == '`') |
| 2893 | || (new_backquote_flag && next_char == ',')))) |
| 2894 | { |
| 2895 | *pch = c; |
| 2896 | return Qnil; |
| 2897 | } |
| 2898 | |
| 2899 | /* Otherwise, we fall through! Note that the atom-reading loop |
| 2900 | below will now loop at least once, assuring that we will not |
| 2901 | try to UNREAD two characters in a row. */ |
| 2902 | } |
| 2903 | default: |
| 2904 | default_label: |
| 2905 | if (c <= 040) goto retry; |
| 2906 | if (c == 0x8a0) /* NBSP */ |
| 2907 | goto retry; |
| 2908 | { |
| 2909 | char *p = read_buffer; |
| 2910 | int quoted = 0; |
| 2911 | |
| 2912 | { |
| 2913 | char *end = read_buffer + read_buffer_size; |
| 2914 | |
| 2915 | while (c > 040 |
| 2916 | && c != 0x8a0 /* NBSP */ |
| 2917 | && (c >= 0200 |
| 2918 | || (!index ("\"';()[]#", c) |
| 2919 | && !(!first_in_list && c == '`') |
| 2920 | && !(new_backquote_flag && c == ',')))) |
| 2921 | { |
| 2922 | if (end - p < MAX_MULTIBYTE_LENGTH) |
| 2923 | { |
| 2924 | int offset = p - read_buffer; |
| 2925 | read_buffer = (char *) xrealloc (read_buffer, |
| 2926 | read_buffer_size *= 2); |
| 2927 | p = read_buffer + offset; |
| 2928 | end = read_buffer + read_buffer_size; |
| 2929 | } |
| 2930 | |
| 2931 | if (c == '\\') |
| 2932 | { |
| 2933 | c = READCHAR; |
| 2934 | if (c == -1) |
| 2935 | end_of_file_error (); |
| 2936 | quoted = 1; |
| 2937 | } |
| 2938 | |
| 2939 | if (multibyte) |
| 2940 | p += CHAR_STRING (c, p); |
| 2941 | else |
| 2942 | *p++ = c; |
| 2943 | c = READCHAR; |
| 2944 | } |
| 2945 | |
| 2946 | if (p == end) |
| 2947 | { |
| 2948 | int offset = p - read_buffer; |
| 2949 | read_buffer = (char *) xrealloc (read_buffer, |
| 2950 | read_buffer_size *= 2); |
| 2951 | p = read_buffer + offset; |
| 2952 | end = read_buffer + read_buffer_size; |
| 2953 | } |
| 2954 | *p = 0; |
| 2955 | if (c >= 0) |
| 2956 | UNREAD (c); |
| 2957 | } |
| 2958 | |
| 2959 | if (!quoted && !uninterned_symbol) |
| 2960 | { |
| 2961 | register char *p1; |
| 2962 | p1 = read_buffer; |
| 2963 | if (*p1 == '+' || *p1 == '-') p1++; |
| 2964 | /* Is it an integer? */ |
| 2965 | if (p1 != p) |
| 2966 | { |
| 2967 | while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++; |
| 2968 | /* Integers can have trailing decimal points. */ |
| 2969 | if (p1 > read_buffer && p1 < p && *p1 == '.') p1++; |
| 2970 | if (p1 == p) |
| 2971 | /* It is an integer. */ |
| 2972 | { |
| 2973 | if (p1[-1] == '.') |
| 2974 | p1[-1] = '\0'; |
| 2975 | { |
| 2976 | /* EMACS_INT n = atol (read_buffer); */ |
| 2977 | char *endptr = NULL; |
| 2978 | EMACS_INT n = (errno = 0, |
| 2979 | strtol (read_buffer, &endptr, 10)); |
| 2980 | if (errno == ERANGE && endptr) |
| 2981 | { |
| 2982 | Lisp_Object args |
| 2983 | = Fcons (make_string (read_buffer, |
| 2984 | endptr - read_buffer), |
| 2985 | Qnil); |
| 2986 | xsignal (Qoverflow_error, args); |
| 2987 | } |
| 2988 | return make_fixnum_or_float (n); |
| 2989 | } |
| 2990 | } |
| 2991 | } |
| 2992 | if (isfloat_string (read_buffer, 0)) |
| 2993 | { |
| 2994 | /* Compute NaN and infinities using 0.0 in a variable, |
| 2995 | to cope with compilers that think they are smarter |
| 2996 | than we are. */ |
| 2997 | double zero = 0.0; |
| 2998 | |
| 2999 | double value; |
| 3000 | |
| 3001 | /* Negate the value ourselves. This treats 0, NaNs, |
| 3002 | and infinity properly on IEEE floating point hosts, |
| 3003 | and works around a common bug where atof ("-0.0") |
| 3004 | drops the sign. */ |
| 3005 | int negative = read_buffer[0] == '-'; |
| 3006 | |
| 3007 | /* The only way p[-1] can be 'F' or 'N', after isfloat_string |
| 3008 | returns 1, is if the input ends in e+INF or e+NaN. */ |
| 3009 | switch (p[-1]) |
| 3010 | { |
| 3011 | case 'F': |
| 3012 | value = 1.0 / zero; |
| 3013 | break; |
| 3014 | case 'N': |
| 3015 | value = zero / zero; |
| 3016 | |
| 3017 | /* If that made a "negative" NaN, negate it. */ |
| 3018 | |
| 3019 | { |
| 3020 | int i; |
| 3021 | union { double d; char c[sizeof (double)]; } u_data, u_minus_zero; |
| 3022 | |
| 3023 | u_data.d = value; |
| 3024 | u_minus_zero.d = - 0.0; |
| 3025 | for (i = 0; i < sizeof (double); i++) |
| 3026 | if (u_data.c[i] & u_minus_zero.c[i]) |
| 3027 | { |
| 3028 | value = - value; |
| 3029 | break; |
| 3030 | } |
| 3031 | } |
| 3032 | /* Now VALUE is a positive NaN. */ |
| 3033 | break; |
| 3034 | default: |
| 3035 | value = atof (read_buffer + negative); |
| 3036 | break; |
| 3037 | } |
| 3038 | |
| 3039 | return make_float (negative ? - value : value); |
| 3040 | } |
| 3041 | } |
| 3042 | { |
| 3043 | Lisp_Object name, result; |
| 3044 | EMACS_INT nbytes = p - read_buffer; |
| 3045 | EMACS_INT nchars |
| 3046 | = (multibyte ? multibyte_chars_in_text (read_buffer, nbytes) |
| 3047 | : nbytes); |
| 3048 | |
| 3049 | if (uninterned_symbol && ! NILP (Vpurify_flag)) |
| 3050 | name = make_pure_string (read_buffer, nchars, nbytes, multibyte); |
| 3051 | else |
| 3052 | name = make_specified_string (read_buffer, nchars, nbytes,multibyte); |
| 3053 | result = (uninterned_symbol ? Fmake_symbol (name) |
| 3054 | : Fintern (name, Qnil)); |
| 3055 | |
| 3056 | if (EQ (Vread_with_symbol_positions, Qt) |
| 3057 | || EQ (Vread_with_symbol_positions, readcharfun)) |
| 3058 | Vread_symbol_positions_list = |
| 3059 | /* Kind of a hack; this will probably fail if characters |
| 3060 | in the symbol name were escaped. Not really a big |
| 3061 | deal, though. */ |
| 3062 | Fcons (Fcons (result, |
| 3063 | make_number (readchar_count |
| 3064 | - XFASTINT (Flength (Fsymbol_name (result))))), |
| 3065 | Vread_symbol_positions_list); |
| 3066 | return result; |
| 3067 | } |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | \f |
| 3072 | |
| 3073 | /* List of nodes we've seen during substitute_object_in_subtree. */ |
| 3074 | static Lisp_Object seen_list; |
| 3075 | |
| 3076 | static void |
| 3077 | substitute_object_in_subtree (Lisp_Object object, Lisp_Object placeholder) |
| 3078 | { |
| 3079 | Lisp_Object check_object; |
| 3080 | |
| 3081 | /* We haven't seen any objects when we start. */ |
| 3082 | seen_list = Qnil; |
| 3083 | |
| 3084 | /* Make all the substitutions. */ |
| 3085 | check_object |
| 3086 | = substitute_object_recurse (object, placeholder, object); |
| 3087 | |
| 3088 | /* Clear seen_list because we're done with it. */ |
| 3089 | seen_list = Qnil; |
| 3090 | |
| 3091 | /* The returned object here is expected to always eq the |
| 3092 | original. */ |
| 3093 | if (!EQ (check_object, object)) |
| 3094 | error ("Unexpected mutation error in reader"); |
| 3095 | } |
| 3096 | |
| 3097 | /* Feval doesn't get called from here, so no gc protection is needed. */ |
| 3098 | #define SUBSTITUTE(get_val, set_val) \ |
| 3099 | do { \ |
| 3100 | Lisp_Object old_value = get_val; \ |
| 3101 | Lisp_Object true_value \ |
| 3102 | = substitute_object_recurse (object, placeholder, \ |
| 3103 | old_value); \ |
| 3104 | \ |
| 3105 | if (!EQ (old_value, true_value)) \ |
| 3106 | { \ |
| 3107 | set_val; \ |
| 3108 | } \ |
| 3109 | } while (0) |
| 3110 | |
| 3111 | static Lisp_Object |
| 3112 | substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Object subtree) |
| 3113 | { |
| 3114 | /* If we find the placeholder, return the target object. */ |
| 3115 | if (EQ (placeholder, subtree)) |
| 3116 | return object; |
| 3117 | |
| 3118 | /* If we've been to this node before, don't explore it again. */ |
| 3119 | if (!EQ (Qnil, Fmemq (subtree, seen_list))) |
| 3120 | return subtree; |
| 3121 | |
| 3122 | /* If this node can be the entry point to a cycle, remember that |
| 3123 | we've seen it. It can only be such an entry point if it was made |
| 3124 | by #n=, which means that we can find it as a value in |
| 3125 | read_objects. */ |
| 3126 | if (!EQ (Qnil, Frassq (subtree, read_objects))) |
| 3127 | seen_list = Fcons (subtree, seen_list); |
| 3128 | |
| 3129 | /* Recurse according to subtree's type. |
| 3130 | Every branch must return a Lisp_Object. */ |
| 3131 | switch (XTYPE (subtree)) |
| 3132 | { |
| 3133 | case Lisp_Vectorlike: |
| 3134 | { |
| 3135 | int i, length = 0; |
| 3136 | if (BOOL_VECTOR_P (subtree)) |
| 3137 | return subtree; /* No sub-objects anyway. */ |
| 3138 | else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree) |
| 3139 | || COMPILEDP (subtree)) |
| 3140 | length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK; |
| 3141 | else if (VECTORP (subtree)) |
| 3142 | length = ASIZE (subtree); |
| 3143 | else |
| 3144 | /* An unknown pseudovector may contain non-Lisp fields, so we |
| 3145 | can't just blindly traverse all its fields. We used to call |
| 3146 | `Flength' which signaled `sequencep', so I just preserved this |
| 3147 | behavior. */ |
| 3148 | wrong_type_argument (Qsequencep, subtree); |
| 3149 | |
| 3150 | for (i = 0; i < length; i++) |
| 3151 | SUBSTITUTE (AREF (subtree, i), |
| 3152 | ASET (subtree, i, true_value)); |
| 3153 | return subtree; |
| 3154 | } |
| 3155 | |
| 3156 | case Lisp_Cons: |
| 3157 | { |
| 3158 | SUBSTITUTE (XCAR (subtree), |
| 3159 | XSETCAR (subtree, true_value)); |
| 3160 | SUBSTITUTE (XCDR (subtree), |
| 3161 | XSETCDR (subtree, true_value)); |
| 3162 | return subtree; |
| 3163 | } |
| 3164 | |
| 3165 | case Lisp_String: |
| 3166 | { |
| 3167 | /* Check for text properties in each interval. |
| 3168 | substitute_in_interval contains part of the logic. */ |
| 3169 | |
| 3170 | INTERVAL root_interval = STRING_INTERVALS (subtree); |
| 3171 | Lisp_Object arg = Fcons (object, placeholder); |
| 3172 | |
| 3173 | traverse_intervals_noorder (root_interval, |
| 3174 | &substitute_in_interval, arg); |
| 3175 | |
| 3176 | return subtree; |
| 3177 | } |
| 3178 | |
| 3179 | /* Other types don't recurse any further. */ |
| 3180 | default: |
| 3181 | return subtree; |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | /* Helper function for substitute_object_recurse. */ |
| 3186 | static void |
| 3187 | substitute_in_interval (INTERVAL interval, Lisp_Object arg) |
| 3188 | { |
| 3189 | Lisp_Object object = Fcar (arg); |
| 3190 | Lisp_Object placeholder = Fcdr (arg); |
| 3191 | |
| 3192 | SUBSTITUTE (interval->plist, interval->plist = true_value); |
| 3193 | } |
| 3194 | |
| 3195 | \f |
| 3196 | #define LEAD_INT 1 |
| 3197 | #define DOT_CHAR 2 |
| 3198 | #define TRAIL_INT 4 |
| 3199 | #define E_CHAR 8 |
| 3200 | #define EXP_INT 16 |
| 3201 | |
| 3202 | int |
| 3203 | isfloat_string (register char *cp, int ignore_trailing) |
| 3204 | { |
| 3205 | register int state; |
| 3206 | |
| 3207 | char *start = cp; |
| 3208 | |
| 3209 | state = 0; |
| 3210 | if (*cp == '+' || *cp == '-') |
| 3211 | cp++; |
| 3212 | |
| 3213 | if (*cp >= '0' && *cp <= '9') |
| 3214 | { |
| 3215 | state |= LEAD_INT; |
| 3216 | while (*cp >= '0' && *cp <= '9') |
| 3217 | cp++; |
| 3218 | } |
| 3219 | if (*cp == '.') |
| 3220 | { |
| 3221 | state |= DOT_CHAR; |
| 3222 | cp++; |
| 3223 | } |
| 3224 | if (*cp >= '0' && *cp <= '9') |
| 3225 | { |
| 3226 | state |= TRAIL_INT; |
| 3227 | while (*cp >= '0' && *cp <= '9') |
| 3228 | cp++; |
| 3229 | } |
| 3230 | if (*cp == 'e' || *cp == 'E') |
| 3231 | { |
| 3232 | state |= E_CHAR; |
| 3233 | cp++; |
| 3234 | if (*cp == '+' || *cp == '-') |
| 3235 | cp++; |
| 3236 | } |
| 3237 | |
| 3238 | if (*cp >= '0' && *cp <= '9') |
| 3239 | { |
| 3240 | state |= EXP_INT; |
| 3241 | while (*cp >= '0' && *cp <= '9') |
| 3242 | cp++; |
| 3243 | } |
| 3244 | else if (cp == start) |
| 3245 | ; |
| 3246 | else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F') |
| 3247 | { |
| 3248 | state |= EXP_INT; |
| 3249 | cp += 3; |
| 3250 | } |
| 3251 | else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') |
| 3252 | { |
| 3253 | state |= EXP_INT; |
| 3254 | cp += 3; |
| 3255 | } |
| 3256 | |
| 3257 | return ((ignore_trailing |
| 3258 | || (*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f')) |
| 3259 | && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) |
| 3260 | || state == (DOT_CHAR|TRAIL_INT) |
| 3261 | || state == (LEAD_INT|E_CHAR|EXP_INT) |
| 3262 | || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) |
| 3263 | || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); |
| 3264 | } |
| 3265 | |
| 3266 | \f |
| 3267 | static Lisp_Object |
| 3268 | read_vector (Lisp_Object readcharfun, int bytecodeflag) |
| 3269 | { |
| 3270 | register int i; |
| 3271 | register int size; |
| 3272 | register Lisp_Object *ptr; |
| 3273 | register Lisp_Object tem, item, vector; |
| 3274 | register struct Lisp_Cons *otem; |
| 3275 | Lisp_Object len; |
| 3276 | |
| 3277 | tem = read_list (1, readcharfun); |
| 3278 | len = Flength (tem); |
| 3279 | vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil)); |
| 3280 | |
| 3281 | size = XVECTOR (vector)->size; |
| 3282 | ptr = XVECTOR (vector)->contents; |
| 3283 | for (i = 0; i < size; i++) |
| 3284 | { |
| 3285 | item = Fcar (tem); |
| 3286 | /* If `load-force-doc-strings' is t when reading a lazily-loaded |
| 3287 | bytecode object, the docstring containing the bytecode and |
| 3288 | constants values must be treated as unibyte and passed to |
| 3289 | Fread, to get the actual bytecode string and constants vector. */ |
| 3290 | if (bytecodeflag && load_force_doc_strings) |
| 3291 | { |
| 3292 | if (i == COMPILED_BYTECODE) |
| 3293 | { |
| 3294 | if (!STRINGP (item)) |
| 3295 | error ("Invalid byte code"); |
| 3296 | |
| 3297 | /* Delay handling the bytecode slot until we know whether |
| 3298 | it is lazily-loaded (we can tell by whether the |
| 3299 | constants slot is nil). */ |
| 3300 | ptr[COMPILED_CONSTANTS] = item; |
| 3301 | item = Qnil; |
| 3302 | } |
| 3303 | else if (i == COMPILED_CONSTANTS) |
| 3304 | { |
| 3305 | Lisp_Object bytestr = ptr[COMPILED_CONSTANTS]; |
| 3306 | |
| 3307 | if (NILP (item)) |
| 3308 | { |
| 3309 | /* Coerce string to unibyte (like string-as-unibyte, |
| 3310 | but without generating extra garbage and |
| 3311 | guaranteeing no change in the contents). */ |
| 3312 | STRING_SET_CHARS (bytestr, SBYTES (bytestr)); |
| 3313 | STRING_SET_UNIBYTE (bytestr); |
| 3314 | |
| 3315 | item = Fread (Fcons (bytestr, readcharfun)); |
| 3316 | if (!CONSP (item)) |
| 3317 | error ("Invalid byte code"); |
| 3318 | |
| 3319 | otem = XCONS (item); |
| 3320 | bytestr = XCAR (item); |
| 3321 | item = XCDR (item); |
| 3322 | free_cons (otem); |
| 3323 | } |
| 3324 | |
| 3325 | /* Now handle the bytecode slot. */ |
| 3326 | ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr; |
| 3327 | } |
| 3328 | else if (i == COMPILED_DOC_STRING |
| 3329 | && STRINGP (item) |
| 3330 | && ! STRING_MULTIBYTE (item)) |
| 3331 | { |
| 3332 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) |
| 3333 | item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil); |
| 3334 | else |
| 3335 | item = Fstring_as_multibyte (item); |
| 3336 | } |
| 3337 | } |
| 3338 | ptr[i] = read_pure ? Fpurecopy (item) : item; |
| 3339 | otem = XCONS (tem); |
| 3340 | tem = Fcdr (tem); |
| 3341 | free_cons (otem); |
| 3342 | } |
| 3343 | return vector; |
| 3344 | } |
| 3345 | |
| 3346 | /* FLAG = 1 means check for ] to terminate rather than ) and . |
| 3347 | FLAG = -1 means check for starting with defun |
| 3348 | and make structure pure. */ |
| 3349 | |
| 3350 | static Lisp_Object |
| 3351 | read_list (int flag, register Lisp_Object readcharfun) |
| 3352 | { |
| 3353 | /* -1 means check next element for defun, |
| 3354 | 0 means don't check, |
| 3355 | 1 means already checked and found defun. */ |
| 3356 | int defunflag = flag < 0 ? -1 : 0; |
| 3357 | Lisp_Object val, tail; |
| 3358 | register Lisp_Object elt, tem; |
| 3359 | struct gcpro gcpro1, gcpro2; |
| 3360 | /* 0 is the normal case. |
| 3361 | 1 means this list is a doc reference; replace it with the number 0. |
| 3362 | 2 means this list is a doc reference; replace it with the doc string. */ |
| 3363 | int doc_reference = 0; |
| 3364 | |
| 3365 | /* Initialize this to 1 if we are reading a list. */ |
| 3366 | int first_in_list = flag <= 0; |
| 3367 | |
| 3368 | val = Qnil; |
| 3369 | tail = Qnil; |
| 3370 | |
| 3371 | while (1) |
| 3372 | { |
| 3373 | int ch; |
| 3374 | GCPRO2 (val, tail); |
| 3375 | elt = read1 (readcharfun, &ch, first_in_list); |
| 3376 | UNGCPRO; |
| 3377 | |
| 3378 | first_in_list = 0; |
| 3379 | |
| 3380 | /* While building, if the list starts with #$, treat it specially. */ |
| 3381 | if (EQ (elt, Vload_file_name) |
| 3382 | && ! NILP (elt) |
| 3383 | && !NILP (Vpurify_flag)) |
| 3384 | { |
| 3385 | if (NILP (Vdoc_file_name)) |
| 3386 | /* We have not yet called Snarf-documentation, so assume |
| 3387 | this file is described in the DOC-MM.NN file |
| 3388 | and Snarf-documentation will fill in the right value later. |
| 3389 | For now, replace the whole list with 0. */ |
| 3390 | doc_reference = 1; |
| 3391 | else |
| 3392 | /* We have already called Snarf-documentation, so make a relative |
| 3393 | file name for this file, so it can be found properly |
| 3394 | in the installed Lisp directory. |
| 3395 | We don't use Fexpand_file_name because that would make |
| 3396 | the directory absolute now. */ |
| 3397 | elt = concat2 (build_string ("../lisp/"), |
| 3398 | Ffile_name_nondirectory (elt)); |
| 3399 | } |
| 3400 | else if (EQ (elt, Vload_file_name) |
| 3401 | && ! NILP (elt) |
| 3402 | && load_force_doc_strings) |
| 3403 | doc_reference = 2; |
| 3404 | |
| 3405 | if (ch) |
| 3406 | { |
| 3407 | if (flag > 0) |
| 3408 | { |
| 3409 | if (ch == ']') |
| 3410 | return val; |
| 3411 | invalid_syntax (") or . in a vector", 18); |
| 3412 | } |
| 3413 | if (ch == ')') |
| 3414 | return val; |
| 3415 | if (ch == '.') |
| 3416 | { |
| 3417 | GCPRO2 (val, tail); |
| 3418 | if (!NILP (tail)) |
| 3419 | XSETCDR (tail, read0 (readcharfun)); |
| 3420 | else |
| 3421 | val = read0 (readcharfun); |
| 3422 | read1 (readcharfun, &ch, 0); |
| 3423 | UNGCPRO; |
| 3424 | if (ch == ')') |
| 3425 | { |
| 3426 | if (doc_reference == 1) |
| 3427 | return make_number (0); |
| 3428 | if (doc_reference == 2) |
| 3429 | { |
| 3430 | /* Get a doc string from the file we are loading. |
| 3431 | If it's in saved_doc_string, get it from there. |
| 3432 | |
| 3433 | Here, we don't know if the string is a |
| 3434 | bytecode string or a doc string. As a |
| 3435 | bytecode string must be unibyte, we always |
| 3436 | return a unibyte string. If it is actually a |
| 3437 | doc string, caller must make it |
| 3438 | multibyte. */ |
| 3439 | |
| 3440 | int pos = XINT (XCDR (val)); |
| 3441 | /* Position is negative for user variables. */ |
| 3442 | if (pos < 0) pos = -pos; |
| 3443 | if (pos >= saved_doc_string_position |
| 3444 | && pos < (saved_doc_string_position |
| 3445 | + saved_doc_string_length)) |
| 3446 | { |
| 3447 | int start = pos - saved_doc_string_position; |
| 3448 | int from, to; |
| 3449 | |
| 3450 | /* Process quoting with ^A, |
| 3451 | and find the end of the string, |
| 3452 | which is marked with ^_ (037). */ |
| 3453 | for (from = start, to = start; |
| 3454 | saved_doc_string[from] != 037;) |
| 3455 | { |
| 3456 | int c = saved_doc_string[from++]; |
| 3457 | if (c == 1) |
| 3458 | { |
| 3459 | c = saved_doc_string[from++]; |
| 3460 | if (c == 1) |
| 3461 | saved_doc_string[to++] = c; |
| 3462 | else if (c == '0') |
| 3463 | saved_doc_string[to++] = 0; |
| 3464 | else if (c == '_') |
| 3465 | saved_doc_string[to++] = 037; |
| 3466 | } |
| 3467 | else |
| 3468 | saved_doc_string[to++] = c; |
| 3469 | } |
| 3470 | |
| 3471 | return make_unibyte_string (saved_doc_string + start, |
| 3472 | to - start); |
| 3473 | } |
| 3474 | /* Look in prev_saved_doc_string the same way. */ |
| 3475 | else if (pos >= prev_saved_doc_string_position |
| 3476 | && pos < (prev_saved_doc_string_position |
| 3477 | + prev_saved_doc_string_length)) |
| 3478 | { |
| 3479 | int start = pos - prev_saved_doc_string_position; |
| 3480 | int from, to; |
| 3481 | |
| 3482 | /* Process quoting with ^A, |
| 3483 | and find the end of the string, |
| 3484 | which is marked with ^_ (037). */ |
| 3485 | for (from = start, to = start; |
| 3486 | prev_saved_doc_string[from] != 037;) |
| 3487 | { |
| 3488 | int c = prev_saved_doc_string[from++]; |
| 3489 | if (c == 1) |
| 3490 | { |
| 3491 | c = prev_saved_doc_string[from++]; |
| 3492 | if (c == 1) |
| 3493 | prev_saved_doc_string[to++] = c; |
| 3494 | else if (c == '0') |
| 3495 | prev_saved_doc_string[to++] = 0; |
| 3496 | else if (c == '_') |
| 3497 | prev_saved_doc_string[to++] = 037; |
| 3498 | } |
| 3499 | else |
| 3500 | prev_saved_doc_string[to++] = c; |
| 3501 | } |
| 3502 | |
| 3503 | return make_unibyte_string (prev_saved_doc_string |
| 3504 | + start, |
| 3505 | to - start); |
| 3506 | } |
| 3507 | else |
| 3508 | return get_doc_string (val, 1, 0); |
| 3509 | } |
| 3510 | |
| 3511 | return val; |
| 3512 | } |
| 3513 | invalid_syntax (". in wrong context", 18); |
| 3514 | } |
| 3515 | invalid_syntax ("] in a list", 11); |
| 3516 | } |
| 3517 | tem = (read_pure && flag <= 0 |
| 3518 | ? pure_cons (elt, Qnil) |
| 3519 | : Fcons (elt, Qnil)); |
| 3520 | if (!NILP (tail)) |
| 3521 | XSETCDR (tail, tem); |
| 3522 | else |
| 3523 | val = tem; |
| 3524 | tail = tem; |
| 3525 | if (defunflag < 0) |
| 3526 | defunflag = EQ (elt, Qdefun); |
| 3527 | else if (defunflag > 0) |
| 3528 | read_pure = 1; |
| 3529 | } |
| 3530 | } |
| 3531 | \f |
| 3532 | Lisp_Object Vobarray; |
| 3533 | Lisp_Object initial_obarray; |
| 3534 | |
| 3535 | /* oblookup stores the bucket number here, for the sake of Funintern. */ |
| 3536 | |
| 3537 | int oblookup_last_bucket_number; |
| 3538 | |
| 3539 | static int hash_string (const unsigned char *ptr, int len); |
| 3540 | |
| 3541 | /* Get an error if OBARRAY is not an obarray. |
| 3542 | If it is one, return it. */ |
| 3543 | |
| 3544 | Lisp_Object |
| 3545 | check_obarray (Lisp_Object obarray) |
| 3546 | { |
| 3547 | if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) |
| 3548 | { |
| 3549 | /* If Vobarray is now invalid, force it to be valid. */ |
| 3550 | if (EQ (Vobarray, obarray)) Vobarray = initial_obarray; |
| 3551 | wrong_type_argument (Qvectorp, obarray); |
| 3552 | } |
| 3553 | return obarray; |
| 3554 | } |
| 3555 | |
| 3556 | /* Intern the C string STR: return a symbol with that name, |
| 3557 | interned in the current obarray. */ |
| 3558 | |
| 3559 | Lisp_Object |
| 3560 | intern (const char *str) |
| 3561 | { |
| 3562 | Lisp_Object tem; |
| 3563 | int len = strlen (str); |
| 3564 | Lisp_Object obarray; |
| 3565 | |
| 3566 | obarray = Vobarray; |
| 3567 | if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) |
| 3568 | obarray = check_obarray (obarray); |
| 3569 | tem = oblookup (obarray, str, len, len); |
| 3570 | if (SYMBOLP (tem)) |
| 3571 | return tem; |
| 3572 | return Fintern (make_string (str, len), obarray); |
| 3573 | } |
| 3574 | |
| 3575 | Lisp_Object |
| 3576 | intern_c_string (const char *str) |
| 3577 | { |
| 3578 | Lisp_Object tem; |
| 3579 | int len = strlen (str); |
| 3580 | Lisp_Object obarray; |
| 3581 | |
| 3582 | obarray = Vobarray; |
| 3583 | if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) |
| 3584 | obarray = check_obarray (obarray); |
| 3585 | tem = oblookup (obarray, str, len, len); |
| 3586 | if (SYMBOLP (tem)) |
| 3587 | return tem; |
| 3588 | |
| 3589 | if (NILP (Vpurify_flag)) |
| 3590 | /* Creating a non-pure string from a string literal not |
| 3591 | implemented yet. We could just use make_string here and live |
| 3592 | with the extra copy. */ |
| 3593 | abort (); |
| 3594 | |
| 3595 | return Fintern (make_pure_c_string (str), obarray); |
| 3596 | } |
| 3597 | |
| 3598 | /* Create an uninterned symbol with name STR. */ |
| 3599 | |
| 3600 | Lisp_Object |
| 3601 | make_symbol (char *str) |
| 3602 | { |
| 3603 | int len = strlen (str); |
| 3604 | |
| 3605 | return Fmake_symbol ((!NILP (Vpurify_flag) |
| 3606 | ? make_pure_string (str, len, len, 0) |
| 3607 | : make_string (str, len))); |
| 3608 | } |
| 3609 | \f |
| 3610 | DEFUN ("intern", Fintern, Sintern, 1, 2, 0, |
| 3611 | doc: /* Return the canonical symbol whose name is STRING. |
| 3612 | If there is none, one is created by this function and returned. |
| 3613 | A second optional argument specifies the obarray to use; |
| 3614 | it defaults to the value of `obarray'. */) |
| 3615 | (string, obarray) |
| 3616 | Lisp_Object string, obarray; |
| 3617 | { |
| 3618 | register Lisp_Object tem, sym, *ptr; |
| 3619 | |
| 3620 | if (NILP (obarray)) obarray = Vobarray; |
| 3621 | obarray = check_obarray (obarray); |
| 3622 | |
| 3623 | CHECK_STRING (string); |
| 3624 | |
| 3625 | tem = oblookup (obarray, SDATA (string), |
| 3626 | SCHARS (string), |
| 3627 | SBYTES (string)); |
| 3628 | if (!INTEGERP (tem)) |
| 3629 | return tem; |
| 3630 | |
| 3631 | if (!NILP (Vpurify_flag)) |
| 3632 | string = Fpurecopy (string); |
| 3633 | sym = Fmake_symbol (string); |
| 3634 | |
| 3635 | if (EQ (obarray, initial_obarray)) |
| 3636 | XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY; |
| 3637 | else |
| 3638 | XSYMBOL (sym)->interned = SYMBOL_INTERNED; |
| 3639 | |
| 3640 | if ((SREF (string, 0) == ':') |
| 3641 | && EQ (obarray, initial_obarray)) |
| 3642 | { |
| 3643 | XSYMBOL (sym)->constant = 1; |
| 3644 | XSYMBOL (sym)->redirect = SYMBOL_PLAINVAL; |
| 3645 | SET_SYMBOL_VAL (XSYMBOL (sym), sym); |
| 3646 | } |
| 3647 | |
| 3648 | ptr = &XVECTOR (obarray)->contents[XINT (tem)]; |
| 3649 | if (SYMBOLP (*ptr)) |
| 3650 | XSYMBOL (sym)->next = XSYMBOL (*ptr); |
| 3651 | else |
| 3652 | XSYMBOL (sym)->next = 0; |
| 3653 | *ptr = sym; |
| 3654 | return sym; |
| 3655 | } |
| 3656 | |
| 3657 | DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0, |
| 3658 | doc: /* Return the canonical symbol named NAME, or nil if none exists. |
| 3659 | NAME may be a string or a symbol. If it is a symbol, that exact |
| 3660 | symbol is searched for. |
| 3661 | A second optional argument specifies the obarray to use; |
| 3662 | it defaults to the value of `obarray'. */) |
| 3663 | (name, obarray) |
| 3664 | Lisp_Object name, obarray; |
| 3665 | { |
| 3666 | register Lisp_Object tem, string; |
| 3667 | |
| 3668 | if (NILP (obarray)) obarray = Vobarray; |
| 3669 | obarray = check_obarray (obarray); |
| 3670 | |
| 3671 | if (!SYMBOLP (name)) |
| 3672 | { |
| 3673 | CHECK_STRING (name); |
| 3674 | string = name; |
| 3675 | } |
| 3676 | else |
| 3677 | string = SYMBOL_NAME (name); |
| 3678 | |
| 3679 | tem = oblookup (obarray, SDATA (string), SCHARS (string), SBYTES (string)); |
| 3680 | if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem))) |
| 3681 | return Qnil; |
| 3682 | else |
| 3683 | return tem; |
| 3684 | } |
| 3685 | \f |
| 3686 | DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0, |
| 3687 | doc: /* Delete the symbol named NAME, if any, from OBARRAY. |
| 3688 | The value is t if a symbol was found and deleted, nil otherwise. |
| 3689 | NAME may be a string or a symbol. If it is a symbol, that symbol |
| 3690 | is deleted, if it belongs to OBARRAY--no other symbol is deleted. |
| 3691 | OBARRAY defaults to the value of the variable `obarray'. */) |
| 3692 | (name, obarray) |
| 3693 | Lisp_Object name, obarray; |
| 3694 | { |
| 3695 | register Lisp_Object string, tem; |
| 3696 | int hash; |
| 3697 | |
| 3698 | if (NILP (obarray)) obarray = Vobarray; |
| 3699 | obarray = check_obarray (obarray); |
| 3700 | |
| 3701 | if (SYMBOLP (name)) |
| 3702 | string = SYMBOL_NAME (name); |
| 3703 | else |
| 3704 | { |
| 3705 | CHECK_STRING (name); |
| 3706 | string = name; |
| 3707 | } |
| 3708 | |
| 3709 | tem = oblookup (obarray, SDATA (string), |
| 3710 | SCHARS (string), |
| 3711 | SBYTES (string)); |
| 3712 | if (INTEGERP (tem)) |
| 3713 | return Qnil; |
| 3714 | /* If arg was a symbol, don't delete anything but that symbol itself. */ |
| 3715 | if (SYMBOLP (name) && !EQ (name, tem)) |
| 3716 | return Qnil; |
| 3717 | |
| 3718 | /* There are plenty of other symbols which will screw up the Emacs |
| 3719 | session if we unintern them, as well as even more ways to use |
| 3720 | `setq' or `fset' or whatnot to make the Emacs session |
| 3721 | unusable. Let's not go down this silly road. --Stef */ |
| 3722 | /* if (EQ (tem, Qnil) || EQ (tem, Qt)) |
| 3723 | error ("Attempt to unintern t or nil"); */ |
| 3724 | |
| 3725 | XSYMBOL (tem)->interned = SYMBOL_UNINTERNED; |
| 3726 | |
| 3727 | hash = oblookup_last_bucket_number; |
| 3728 | |
| 3729 | if (EQ (XVECTOR (obarray)->contents[hash], tem)) |
| 3730 | { |
| 3731 | if (XSYMBOL (tem)->next) |
| 3732 | XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next); |
| 3733 | else |
| 3734 | XSETINT (XVECTOR (obarray)->contents[hash], 0); |
| 3735 | } |
| 3736 | else |
| 3737 | { |
| 3738 | Lisp_Object tail, following; |
| 3739 | |
| 3740 | for (tail = XVECTOR (obarray)->contents[hash]; |
| 3741 | XSYMBOL (tail)->next; |
| 3742 | tail = following) |
| 3743 | { |
| 3744 | XSETSYMBOL (following, XSYMBOL (tail)->next); |
| 3745 | if (EQ (following, tem)) |
| 3746 | { |
| 3747 | XSYMBOL (tail)->next = XSYMBOL (following)->next; |
| 3748 | break; |
| 3749 | } |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | return Qt; |
| 3754 | } |
| 3755 | \f |
| 3756 | /* Return the symbol in OBARRAY whose names matches the string |
| 3757 | of SIZE characters (SIZE_BYTE bytes) at PTR. |
| 3758 | If there is no such symbol in OBARRAY, return nil. |
| 3759 | |
| 3760 | Also store the bucket number in oblookup_last_bucket_number. */ |
| 3761 | |
| 3762 | Lisp_Object |
| 3763 | oblookup (Lisp_Object obarray, register const char *ptr, int size, int size_byte) |
| 3764 | { |
| 3765 | int hash; |
| 3766 | int obsize; |
| 3767 | register Lisp_Object tail; |
| 3768 | Lisp_Object bucket, tem; |
| 3769 | |
| 3770 | if (!VECTORP (obarray) |
| 3771 | || (obsize = XVECTOR (obarray)->size) == 0) |
| 3772 | { |
| 3773 | obarray = check_obarray (obarray); |
| 3774 | obsize = XVECTOR (obarray)->size; |
| 3775 | } |
| 3776 | /* This is sometimes needed in the middle of GC. */ |
| 3777 | obsize &= ~ARRAY_MARK_FLAG; |
| 3778 | hash = hash_string (ptr, size_byte) % obsize; |
| 3779 | bucket = XVECTOR (obarray)->contents[hash]; |
| 3780 | oblookup_last_bucket_number = hash; |
| 3781 | if (EQ (bucket, make_number (0))) |
| 3782 | ; |
| 3783 | else if (!SYMBOLP (bucket)) |
| 3784 | error ("Bad data in guts of obarray"); /* Like CADR error message */ |
| 3785 | else |
| 3786 | for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next)) |
| 3787 | { |
| 3788 | if (SBYTES (SYMBOL_NAME (tail)) == size_byte |
| 3789 | && SCHARS (SYMBOL_NAME (tail)) == size |
| 3790 | && !bcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte)) |
| 3791 | return tail; |
| 3792 | else if (XSYMBOL (tail)->next == 0) |
| 3793 | break; |
| 3794 | } |
| 3795 | XSETINT (tem, hash); |
| 3796 | return tem; |
| 3797 | } |
| 3798 | |
| 3799 | static int |
| 3800 | hash_string (const unsigned char *ptr, int len) |
| 3801 | { |
| 3802 | register const unsigned char *p = ptr; |
| 3803 | register const unsigned char *end = p + len; |
| 3804 | register unsigned char c; |
| 3805 | register int hash = 0; |
| 3806 | |
| 3807 | while (p != end) |
| 3808 | { |
| 3809 | c = *p++; |
| 3810 | if (c >= 0140) c -= 40; |
| 3811 | hash = ((hash<<3) + (hash>>28) + c); |
| 3812 | } |
| 3813 | return hash & 07777777777; |
| 3814 | } |
| 3815 | \f |
| 3816 | void |
| 3817 | map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg) |
| 3818 | { |
| 3819 | register int i; |
| 3820 | register Lisp_Object tail; |
| 3821 | CHECK_VECTOR (obarray); |
| 3822 | for (i = XVECTOR (obarray)->size - 1; i >= 0; i--) |
| 3823 | { |
| 3824 | tail = XVECTOR (obarray)->contents[i]; |
| 3825 | if (SYMBOLP (tail)) |
| 3826 | while (1) |
| 3827 | { |
| 3828 | (*fn) (tail, arg); |
| 3829 | if (XSYMBOL (tail)->next == 0) |
| 3830 | break; |
| 3831 | XSETSYMBOL (tail, XSYMBOL (tail)->next); |
| 3832 | } |
| 3833 | } |
| 3834 | } |
| 3835 | |
| 3836 | void |
| 3837 | mapatoms_1 (Lisp_Object sym, Lisp_Object function) |
| 3838 | { |
| 3839 | call1 (function, sym); |
| 3840 | } |
| 3841 | |
| 3842 | DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0, |
| 3843 | doc: /* Call FUNCTION on every symbol in OBARRAY. |
| 3844 | OBARRAY defaults to the value of `obarray'. */) |
| 3845 | (function, obarray) |
| 3846 | Lisp_Object function, obarray; |
| 3847 | { |
| 3848 | if (NILP (obarray)) obarray = Vobarray; |
| 3849 | obarray = check_obarray (obarray); |
| 3850 | |
| 3851 | map_obarray (obarray, mapatoms_1, function); |
| 3852 | return Qnil; |
| 3853 | } |
| 3854 | |
| 3855 | #define OBARRAY_SIZE 1511 |
| 3856 | |
| 3857 | void |
| 3858 | init_obarray (void) |
| 3859 | { |
| 3860 | Lisp_Object oblength; |
| 3861 | |
| 3862 | XSETFASTINT (oblength, OBARRAY_SIZE); |
| 3863 | |
| 3864 | Vobarray = Fmake_vector (oblength, make_number (0)); |
| 3865 | initial_obarray = Vobarray; |
| 3866 | staticpro (&initial_obarray); |
| 3867 | |
| 3868 | Qunbound = Fmake_symbol (make_pure_c_string ("unbound")); |
| 3869 | /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the |
| 3870 | NILP (Vpurify_flag) check in intern_c_string. */ |
| 3871 | Qnil = make_number (-1); Vpurify_flag = make_number (1); |
| 3872 | Qnil = intern_c_string ("nil"); |
| 3873 | |
| 3874 | /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil, |
| 3875 | so those two need to be fixed manally. */ |
| 3876 | SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound); |
| 3877 | XSYMBOL (Qunbound)->function = Qunbound; |
| 3878 | XSYMBOL (Qunbound)->plist = Qnil; |
| 3879 | /* XSYMBOL (Qnil)->function = Qunbound; */ |
| 3880 | SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil); |
| 3881 | XSYMBOL (Qnil)->constant = 1; |
| 3882 | XSYMBOL (Qnil)->plist = Qnil; |
| 3883 | |
| 3884 | Qt = intern_c_string ("t"); |
| 3885 | SET_SYMBOL_VAL (XSYMBOL (Qt), Qt); |
| 3886 | XSYMBOL (Qt)->constant = 1; |
| 3887 | |
| 3888 | /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */ |
| 3889 | Vpurify_flag = Qt; |
| 3890 | |
| 3891 | Qvariable_documentation = intern_c_string ("variable-documentation"); |
| 3892 | staticpro (&Qvariable_documentation); |
| 3893 | |
| 3894 | read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH; |
| 3895 | read_buffer = (char *) xmalloc (read_buffer_size); |
| 3896 | } |
| 3897 | \f |
| 3898 | void |
| 3899 | defsubr (struct Lisp_Subr *sname) |
| 3900 | { |
| 3901 | Lisp_Object sym; |
| 3902 | sym = intern_c_string (sname->symbol_name); |
| 3903 | XSETPVECTYPE (sname, PVEC_SUBR); |
| 3904 | XSETSUBR (XSYMBOL (sym)->function, sname); |
| 3905 | } |
| 3906 | |
| 3907 | #ifdef NOTDEF /* use fset in subr.el now */ |
| 3908 | void |
| 3909 | defalias (sname, string) |
| 3910 | struct Lisp_Subr *sname; |
| 3911 | char *string; |
| 3912 | { |
| 3913 | Lisp_Object sym; |
| 3914 | sym = intern (string); |
| 3915 | XSETSUBR (XSYMBOL (sym)->function, sname); |
| 3916 | } |
| 3917 | #endif /* NOTDEF */ |
| 3918 | |
| 3919 | /* Define an "integer variable"; a symbol whose value is forwarded |
| 3920 | to a C variable of type int. Sample call: |
| 3921 | DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */ |
| 3922 | void |
| 3923 | defvar_int (struct Lisp_Intfwd *i_fwd, |
| 3924 | const char *namestring, EMACS_INT *address) |
| 3925 | { |
| 3926 | Lisp_Object sym; |
| 3927 | sym = intern_c_string (namestring); |
| 3928 | i_fwd->type = Lisp_Fwd_Int; |
| 3929 | i_fwd->intvar = address; |
| 3930 | XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; |
| 3931 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)i_fwd); |
| 3932 | } |
| 3933 | |
| 3934 | /* Similar but define a variable whose value is t if address contains 1, |
| 3935 | nil if address contains 0. */ |
| 3936 | void |
| 3937 | defvar_bool (struct Lisp_Boolfwd *b_fwd, |
| 3938 | const char *namestring, int *address) |
| 3939 | { |
| 3940 | Lisp_Object sym; |
| 3941 | sym = intern_c_string (namestring); |
| 3942 | b_fwd->type = Lisp_Fwd_Bool; |
| 3943 | b_fwd->boolvar = address; |
| 3944 | XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; |
| 3945 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)b_fwd); |
| 3946 | Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars); |
| 3947 | } |
| 3948 | |
| 3949 | /* Similar but define a variable whose value is the Lisp Object stored |
| 3950 | at address. Two versions: with and without gc-marking of the C |
| 3951 | variable. The nopro version is used when that variable will be |
| 3952 | gc-marked for some other reason, since marking the same slot twice |
| 3953 | can cause trouble with strings. */ |
| 3954 | void |
| 3955 | defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd, |
| 3956 | const char *namestring, Lisp_Object *address) |
| 3957 | { |
| 3958 | Lisp_Object sym; |
| 3959 | sym = intern_c_string (namestring); |
| 3960 | o_fwd->type = Lisp_Fwd_Obj; |
| 3961 | o_fwd->objvar = address; |
| 3962 | XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; |
| 3963 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)o_fwd); |
| 3964 | } |
| 3965 | |
| 3966 | void |
| 3967 | defvar_lisp (struct Lisp_Objfwd *o_fwd, |
| 3968 | const char *namestring, Lisp_Object *address) |
| 3969 | { |
| 3970 | defvar_lisp_nopro (o_fwd, namestring, address); |
| 3971 | staticpro (address); |
| 3972 | } |
| 3973 | |
| 3974 | /* Similar but define a variable whose value is the Lisp Object stored |
| 3975 | at a particular offset in the current kboard object. */ |
| 3976 | |
| 3977 | void |
| 3978 | defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd, |
| 3979 | const char *namestring, int offset) |
| 3980 | { |
| 3981 | Lisp_Object sym; |
| 3982 | sym = intern_c_string (namestring); |
| 3983 | ko_fwd->type = Lisp_Fwd_Kboard_Obj; |
| 3984 | ko_fwd->offset = offset; |
| 3985 | XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; |
| 3986 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd); |
| 3987 | } |
| 3988 | \f |
| 3989 | /* Record the value of load-path used at the start of dumping |
| 3990 | so we can see if the site changed it later during dumping. */ |
| 3991 | static Lisp_Object dump_path; |
| 3992 | |
| 3993 | void |
| 3994 | init_lread (void) |
| 3995 | { |
| 3996 | char *normal; |
| 3997 | int turn_off_warning = 0; |
| 3998 | |
| 3999 | /* Compute the default load-path. */ |
| 4000 | #ifdef CANNOT_DUMP |
| 4001 | normal = PATH_LOADSEARCH; |
| 4002 | Vload_path = decode_env_path (0, normal); |
| 4003 | #else |
| 4004 | if (NILP (Vpurify_flag)) |
| 4005 | normal = PATH_LOADSEARCH; |
| 4006 | else |
| 4007 | normal = PATH_DUMPLOADSEARCH; |
| 4008 | |
| 4009 | /* In a dumped Emacs, we normally have to reset the value of |
| 4010 | Vload_path from PATH_LOADSEARCH, since the value that was dumped |
| 4011 | uses ../lisp, instead of the path of the installed elisp |
| 4012 | libraries. However, if it appears that Vload_path was changed |
| 4013 | from the default before dumping, don't override that value. */ |
| 4014 | if (initialized) |
| 4015 | { |
| 4016 | if (! NILP (Fequal (dump_path, Vload_path))) |
| 4017 | { |
| 4018 | Vload_path = decode_env_path (0, normal); |
| 4019 | if (!NILP (Vinstallation_directory)) |
| 4020 | { |
| 4021 | Lisp_Object tem, tem1, sitelisp; |
| 4022 | |
| 4023 | /* Remove site-lisp dirs from path temporarily and store |
| 4024 | them in sitelisp, then conc them on at the end so |
| 4025 | they're always first in path. */ |
| 4026 | sitelisp = Qnil; |
| 4027 | while (1) |
| 4028 | { |
| 4029 | tem = Fcar (Vload_path); |
| 4030 | tem1 = Fstring_match (build_string ("site-lisp"), |
| 4031 | tem, Qnil); |
| 4032 | if (!NILP (tem1)) |
| 4033 | { |
| 4034 | Vload_path = Fcdr (Vload_path); |
| 4035 | sitelisp = Fcons (tem, sitelisp); |
| 4036 | } |
| 4037 | else |
| 4038 | break; |
| 4039 | } |
| 4040 | |
| 4041 | /* Add to the path the lisp subdir of the |
| 4042 | installation dir, if it exists. */ |
| 4043 | tem = Fexpand_file_name (build_string ("lisp"), |
| 4044 | Vinstallation_directory); |
| 4045 | tem1 = Ffile_exists_p (tem); |
| 4046 | if (!NILP (tem1)) |
| 4047 | { |
| 4048 | if (NILP (Fmember (tem, Vload_path))) |
| 4049 | { |
| 4050 | turn_off_warning = 1; |
| 4051 | Vload_path = Fcons (tem, Vload_path); |
| 4052 | } |
| 4053 | } |
| 4054 | else |
| 4055 | /* That dir doesn't exist, so add the build-time |
| 4056 | Lisp dirs instead. */ |
| 4057 | Vload_path = nconc2 (Vload_path, dump_path); |
| 4058 | |
| 4059 | /* Add leim under the installation dir, if it exists. */ |
| 4060 | tem = Fexpand_file_name (build_string ("leim"), |
| 4061 | Vinstallation_directory); |
| 4062 | tem1 = Ffile_exists_p (tem); |
| 4063 | if (!NILP (tem1)) |
| 4064 | { |
| 4065 | if (NILP (Fmember (tem, Vload_path))) |
| 4066 | Vload_path = Fcons (tem, Vload_path); |
| 4067 | } |
| 4068 | |
| 4069 | /* Add site-lisp under the installation dir, if it exists. */ |
| 4070 | tem = Fexpand_file_name (build_string ("site-lisp"), |
| 4071 | Vinstallation_directory); |
| 4072 | tem1 = Ffile_exists_p (tem); |
| 4073 | if (!NILP (tem1)) |
| 4074 | { |
| 4075 | if (NILP (Fmember (tem, Vload_path))) |
| 4076 | Vload_path = Fcons (tem, Vload_path); |
| 4077 | } |
| 4078 | |
| 4079 | /* If Emacs was not built in the source directory, |
| 4080 | and it is run from where it was built, add to load-path |
| 4081 | the lisp, leim and site-lisp dirs under that directory. */ |
| 4082 | |
| 4083 | if (NILP (Fequal (Vinstallation_directory, Vsource_directory))) |
| 4084 | { |
| 4085 | Lisp_Object tem2; |
| 4086 | |
| 4087 | tem = Fexpand_file_name (build_string ("src/Makefile"), |
| 4088 | Vinstallation_directory); |
| 4089 | tem1 = Ffile_exists_p (tem); |
| 4090 | |
| 4091 | /* Don't be fooled if they moved the entire source tree |
| 4092 | AFTER dumping Emacs. If the build directory is indeed |
| 4093 | different from the source dir, src/Makefile.in and |
| 4094 | src/Makefile will not be found together. */ |
| 4095 | tem = Fexpand_file_name (build_string ("src/Makefile.in"), |
| 4096 | Vinstallation_directory); |
| 4097 | tem2 = Ffile_exists_p (tem); |
| 4098 | if (!NILP (tem1) && NILP (tem2)) |
| 4099 | { |
| 4100 | tem = Fexpand_file_name (build_string ("lisp"), |
| 4101 | Vsource_directory); |
| 4102 | |
| 4103 | if (NILP (Fmember (tem, Vload_path))) |
| 4104 | Vload_path = Fcons (tem, Vload_path); |
| 4105 | |
| 4106 | tem = Fexpand_file_name (build_string ("leim"), |
| 4107 | Vsource_directory); |
| 4108 | |
| 4109 | if (NILP (Fmember (tem, Vload_path))) |
| 4110 | Vload_path = Fcons (tem, Vload_path); |
| 4111 | |
| 4112 | tem = Fexpand_file_name (build_string ("site-lisp"), |
| 4113 | Vsource_directory); |
| 4114 | |
| 4115 | if (NILP (Fmember (tem, Vload_path))) |
| 4116 | Vload_path = Fcons (tem, Vload_path); |
| 4117 | } |
| 4118 | } |
| 4119 | if (!NILP (sitelisp)) |
| 4120 | Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path); |
| 4121 | } |
| 4122 | } |
| 4123 | } |
| 4124 | else |
| 4125 | { |
| 4126 | /* NORMAL refers to the lisp dir in the source directory. */ |
| 4127 | /* We used to add ../lisp at the front here, but |
| 4128 | that caused trouble because it was copied from dump_path |
| 4129 | into Vload_path, above, when Vinstallation_directory was non-nil. |
| 4130 | It should be unnecessary. */ |
| 4131 | Vload_path = decode_env_path (0, normal); |
| 4132 | dump_path = Vload_path; |
| 4133 | } |
| 4134 | #endif |
| 4135 | |
| 4136 | #if (!(defined (WINDOWSNT) || (defined (HAVE_NS)))) |
| 4137 | /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is |
| 4138 | almost never correct, thereby causing a warning to be printed out that |
| 4139 | confuses users. Since PATH_LOADSEARCH is always overridden by the |
| 4140 | EMACSLOADPATH environment variable below, disable the warning on NT. */ |
| 4141 | |
| 4142 | /* Warn if dirs in the *standard* path don't exist. */ |
| 4143 | if (!turn_off_warning) |
| 4144 | { |
| 4145 | Lisp_Object path_tail; |
| 4146 | |
| 4147 | for (path_tail = Vload_path; |
| 4148 | !NILP (path_tail); |
| 4149 | path_tail = XCDR (path_tail)) |
| 4150 | { |
| 4151 | Lisp_Object dirfile; |
| 4152 | dirfile = Fcar (path_tail); |
| 4153 | if (STRINGP (dirfile)) |
| 4154 | { |
| 4155 | dirfile = Fdirectory_file_name (dirfile); |
| 4156 | if (access (SDATA (dirfile), 0) < 0) |
| 4157 | dir_warning ("Warning: Lisp directory `%s' does not exist.\n", |
| 4158 | XCAR (path_tail)); |
| 4159 | } |
| 4160 | } |
| 4161 | } |
| 4162 | #endif /* !(WINDOWSNT || HAVE_NS) */ |
| 4163 | |
| 4164 | /* If the EMACSLOADPATH environment variable is set, use its value. |
| 4165 | This doesn't apply if we're dumping. */ |
| 4166 | #ifndef CANNOT_DUMP |
| 4167 | if (NILP (Vpurify_flag) |
| 4168 | && egetenv ("EMACSLOADPATH")) |
| 4169 | #endif |
| 4170 | Vload_path = decode_env_path ("EMACSLOADPATH", normal); |
| 4171 | |
| 4172 | Vvalues = Qnil; |
| 4173 | |
| 4174 | load_in_progress = 0; |
| 4175 | Vload_file_name = Qnil; |
| 4176 | |
| 4177 | load_descriptor_list = Qnil; |
| 4178 | |
| 4179 | Vstandard_input = Qt; |
| 4180 | Vloads_in_progress = Qnil; |
| 4181 | } |
| 4182 | |
| 4183 | /* Print a warning, using format string FORMAT, that directory DIRNAME |
| 4184 | does not exist. Print it on stderr and put it in *Messages*. */ |
| 4185 | |
| 4186 | void |
| 4187 | dir_warning (char *format, Lisp_Object dirname) |
| 4188 | { |
| 4189 | char *buffer |
| 4190 | = (char *) alloca (SCHARS (dirname) + strlen (format) + 5); |
| 4191 | |
| 4192 | fprintf (stderr, format, SDATA (dirname)); |
| 4193 | sprintf (buffer, format, SDATA (dirname)); |
| 4194 | /* Don't log the warning before we've initialized!! */ |
| 4195 | if (initialized) |
| 4196 | message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname)); |
| 4197 | } |
| 4198 | |
| 4199 | void |
| 4200 | syms_of_lread (void) |
| 4201 | { |
| 4202 | defsubr (&Sread); |
| 4203 | defsubr (&Sread_from_string); |
| 4204 | defsubr (&Sintern); |
| 4205 | defsubr (&Sintern_soft); |
| 4206 | defsubr (&Sunintern); |
| 4207 | defsubr (&Sget_load_suffixes); |
| 4208 | defsubr (&Sload); |
| 4209 | defsubr (&Seval_buffer); |
| 4210 | defsubr (&Seval_region); |
| 4211 | defsubr (&Sread_char); |
| 4212 | defsubr (&Sread_char_exclusive); |
| 4213 | defsubr (&Sread_event); |
| 4214 | defsubr (&Sget_file_char); |
| 4215 | defsubr (&Smapatoms); |
| 4216 | defsubr (&Slocate_file_internal); |
| 4217 | |
| 4218 | DEFVAR_LISP ("obarray", &Vobarray, |
| 4219 | doc: /* Symbol table for use by `intern' and `read'. |
| 4220 | It is a vector whose length ought to be prime for best results. |
| 4221 | The vector's contents don't make sense if examined from Lisp programs; |
| 4222 | to find all the symbols in an obarray, use `mapatoms'. */); |
| 4223 | |
| 4224 | DEFVAR_LISP ("values", &Vvalues, |
| 4225 | doc: /* List of values of all expressions which were read, evaluated and printed. |
| 4226 | Order is reverse chronological. */); |
| 4227 | |
| 4228 | DEFVAR_LISP ("standard-input", &Vstandard_input, |
| 4229 | doc: /* Stream for read to get input from. |
| 4230 | See documentation of `read' for possible values. */); |
| 4231 | Vstandard_input = Qt; |
| 4232 | |
| 4233 | DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions, |
| 4234 | doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'. |
| 4235 | |
| 4236 | If this variable is a buffer, then only forms read from that buffer |
| 4237 | will be added to `read-symbol-positions-list'. |
| 4238 | If this variable is t, then all read forms will be added. |
| 4239 | The effect of all other values other than nil are not currently |
| 4240 | defined, although they may be in the future. |
| 4241 | |
| 4242 | The positions are relative to the last call to `read' or |
| 4243 | `read-from-string'. It is probably a bad idea to set this variable at |
| 4244 | the toplevel; bind it instead. */); |
| 4245 | Vread_with_symbol_positions = Qnil; |
| 4246 | |
| 4247 | DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list, |
| 4248 | doc: /* A list mapping read symbols to their positions. |
| 4249 | This variable is modified during calls to `read' or |
| 4250 | `read-from-string', but only when `read-with-symbol-positions' is |
| 4251 | non-nil. |
| 4252 | |
| 4253 | Each element of the list looks like (SYMBOL . CHAR-POSITION), where |
| 4254 | CHAR-POSITION is an integer giving the offset of that occurrence of the |
| 4255 | symbol from the position where `read' or `read-from-string' started. |
| 4256 | |
| 4257 | Note that a symbol will appear multiple times in this list, if it was |
| 4258 | read multiple times. The list is in the same order as the symbols |
| 4259 | were read in. */); |
| 4260 | Vread_symbol_positions_list = Qnil; |
| 4261 | |
| 4262 | DEFVAR_LISP ("read-circle", &Vread_circle, |
| 4263 | doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */); |
| 4264 | Vread_circle = Qt; |
| 4265 | |
| 4266 | DEFVAR_LISP ("load-path", &Vload_path, |
| 4267 | doc: /* *List of directories to search for files to load. |
| 4268 | Each element is a string (directory name) or nil (try default directory). |
| 4269 | Initialized based on EMACSLOADPATH environment variable, if any, |
| 4270 | otherwise to default specified by file `epaths.h' when Emacs was built. */); |
| 4271 | |
| 4272 | DEFVAR_LISP ("load-suffixes", &Vload_suffixes, |
| 4273 | doc: /* List of suffixes for (compiled or source) Emacs Lisp files. |
| 4274 | This list should not include the empty string. |
| 4275 | `load' and related functions try to append these suffixes, in order, |
| 4276 | to the specified file name if a Lisp suffix is allowed or required. */); |
| 4277 | Vload_suffixes = Fcons (make_pure_c_string (".elc"), |
| 4278 | Fcons (make_pure_c_string (".el"), Qnil)); |
| 4279 | DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes, |
| 4280 | doc: /* List of suffixes that indicate representations of \ |
| 4281 | the same file. |
| 4282 | This list should normally start with the empty string. |
| 4283 | |
| 4284 | Enabling Auto Compression mode appends the suffixes in |
| 4285 | `jka-compr-load-suffixes' to this list and disabling Auto Compression |
| 4286 | mode removes them again. `load' and related functions use this list to |
| 4287 | determine whether they should look for compressed versions of a file |
| 4288 | and, if so, which suffixes they should try to append to the file name |
| 4289 | in order to do so. However, if you want to customize which suffixes |
| 4290 | the loading functions recognize as compression suffixes, you should |
| 4291 | customize `jka-compr-load-suffixes' rather than the present variable. */); |
| 4292 | Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil); |
| 4293 | |
| 4294 | DEFVAR_BOOL ("load-in-progress", &load_in_progress, |
| 4295 | doc: /* Non-nil if inside of `load'. */); |
| 4296 | Qload_in_progress = intern_c_string ("load-in-progress"); |
| 4297 | staticpro (&Qload_in_progress); |
| 4298 | |
| 4299 | DEFVAR_LISP ("after-load-alist", &Vafter_load_alist, |
| 4300 | doc: /* An alist of expressions to be evalled when particular files are loaded. |
| 4301 | Each element looks like (REGEXP-OR-FEATURE FORMS...). |
| 4302 | |
| 4303 | REGEXP-OR-FEATURE is either a regular expression to match file names, or |
| 4304 | a symbol \(a feature name). |
| 4305 | |
| 4306 | When `load' is run and the file-name argument matches an element's |
| 4307 | REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol |
| 4308 | REGEXP-OR-FEATURE, the FORMS in the element are executed. |
| 4309 | |
| 4310 | An error in FORMS does not undo the load, but does prevent execution of |
| 4311 | the rest of the FORMS. */); |
| 4312 | Vafter_load_alist = Qnil; |
| 4313 | |
| 4314 | DEFVAR_LISP ("load-history", &Vload_history, |
| 4315 | doc: /* Alist mapping loaded file names to symbols and features. |
| 4316 | Each alist element should be a list (FILE-NAME ENTRIES...), where |
| 4317 | FILE-NAME is the name of a file that has been loaded into Emacs. |
| 4318 | The file name is absolute and true (i.e. it doesn't contain symlinks). |
| 4319 | As an exception, one of the alist elements may have FILE-NAME nil, |
| 4320 | for symbols and features not associated with any file. |
| 4321 | |
| 4322 | The remaining ENTRIES in the alist element describe the functions and |
| 4323 | variables defined in that file, the features provided, and the |
| 4324 | features required. Each entry has the form `(provide . FEATURE)', |
| 4325 | `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)', |
| 4326 | `(defface . SYMBOL)', or `(t . SYMBOL)'. In addition, an entry `(t |
| 4327 | . SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that |
| 4328 | SYMBOL was an autoload before this file redefined it as a function. |
| 4329 | |
| 4330 | During preloading, the file name recorded is relative to the main Lisp |
| 4331 | directory. These file names are converted to absolute at startup. */); |
| 4332 | Vload_history = Qnil; |
| 4333 | |
| 4334 | DEFVAR_LISP ("load-file-name", &Vload_file_name, |
| 4335 | doc: /* Full name of file being loaded by `load'. */); |
| 4336 | Vload_file_name = Qnil; |
| 4337 | |
| 4338 | DEFVAR_LISP ("user-init-file", &Vuser_init_file, |
| 4339 | doc: /* File name, including directory, of user's initialization file. |
| 4340 | If the file loaded had extension `.elc', and the corresponding source file |
| 4341 | exists, this variable contains the name of source file, suitable for use |
| 4342 | by functions like `custom-save-all' which edit the init file. |
| 4343 | While Emacs loads and evaluates the init file, value is the real name |
| 4344 | of the file, regardless of whether or not it has the `.elc' extension. */); |
| 4345 | Vuser_init_file = Qnil; |
| 4346 | |
| 4347 | DEFVAR_LISP ("current-load-list", &Vcurrent_load_list, |
| 4348 | doc: /* Used for internal purposes by `load'. */); |
| 4349 | Vcurrent_load_list = Qnil; |
| 4350 | |
| 4351 | DEFVAR_LISP ("load-read-function", &Vload_read_function, |
| 4352 | doc: /* Function used by `load' and `eval-region' for reading expressions. |
| 4353 | The default is nil, which means use the function `read'. */); |
| 4354 | Vload_read_function = Qnil; |
| 4355 | |
| 4356 | DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function, |
| 4357 | doc: /* Function called in `load' for loading an Emacs Lisp source file. |
| 4358 | This function is for doing code conversion before reading the source file. |
| 4359 | If nil, loading is done without any code conversion. |
| 4360 | Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where |
| 4361 | FULLNAME is the full name of FILE. |
| 4362 | See `load' for the meaning of the remaining arguments. */); |
| 4363 | Vload_source_file_function = Qnil; |
| 4364 | |
| 4365 | DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings, |
| 4366 | doc: /* Non-nil means `load' should force-load all dynamic doc strings. |
| 4367 | This is useful when the file being loaded is a temporary copy. */); |
| 4368 | load_force_doc_strings = 0; |
| 4369 | |
| 4370 | DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte, |
| 4371 | doc: /* Non-nil means `read' converts strings to unibyte whenever possible. |
| 4372 | This is normally bound by `load' and `eval-buffer' to control `read', |
| 4373 | and is not meant for users to change. */); |
| 4374 | load_convert_to_unibyte = 0; |
| 4375 | |
| 4376 | DEFVAR_LISP ("source-directory", &Vsource_directory, |
| 4377 | doc: /* Directory in which Emacs sources were found when Emacs was built. |
| 4378 | You cannot count on them to still be there! */); |
| 4379 | Vsource_directory |
| 4380 | = Fexpand_file_name (build_string ("../"), |
| 4381 | Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH))); |
| 4382 | |
| 4383 | DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list, |
| 4384 | doc: /* List of files that were preloaded (when dumping Emacs). */); |
| 4385 | Vpreloaded_file_list = Qnil; |
| 4386 | |
| 4387 | DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars, |
| 4388 | doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */); |
| 4389 | Vbyte_boolean_vars = Qnil; |
| 4390 | |
| 4391 | DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries, |
| 4392 | doc: /* Non-nil means load dangerous compiled Lisp files. |
| 4393 | Some versions of XEmacs use different byte codes than Emacs. These |
| 4394 | incompatible byte codes can make Emacs crash when it tries to execute |
| 4395 | them. */); |
| 4396 | load_dangerous_libraries = 0; |
| 4397 | |
| 4398 | DEFVAR_BOOL ("force-load-messages", &force_load_messages, |
| 4399 | doc: /* Non-nil means force printing messages when loading Lisp files. |
| 4400 | This overrides the value of the NOMESSAGE argument to `load'. */); |
| 4401 | force_load_messages = 0; |
| 4402 | |
| 4403 | DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp, |
| 4404 | doc: /* Regular expression matching safe to load compiled Lisp files. |
| 4405 | When Emacs loads a compiled Lisp file, it reads the first 512 bytes |
| 4406 | from the file, and matches them against this regular expression. |
| 4407 | When the regular expression matches, the file is considered to be safe |
| 4408 | to load. See also `load-dangerous-libraries'. */); |
| 4409 | Vbytecomp_version_regexp |
| 4410 | = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)"); |
| 4411 | |
| 4412 | DEFVAR_LISP ("eval-buffer-list", &Veval_buffer_list, |
| 4413 | doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */); |
| 4414 | Veval_buffer_list = Qnil; |
| 4415 | |
| 4416 | DEFVAR_LISP ("old-style-backquotes", &Vold_style_backquotes, |
| 4417 | doc: /* Set to non-nil when `read' encounters an old-style backquote. */); |
| 4418 | Vold_style_backquotes = Qnil; |
| 4419 | Qold_style_backquotes = intern_c_string ("old-style-backquotes"); |
| 4420 | staticpro (&Qold_style_backquotes); |
| 4421 | |
| 4422 | /* Vsource_directory was initialized in init_lread. */ |
| 4423 | |
| 4424 | load_descriptor_list = Qnil; |
| 4425 | staticpro (&load_descriptor_list); |
| 4426 | |
| 4427 | Qcurrent_load_list = intern_c_string ("current-load-list"); |
| 4428 | staticpro (&Qcurrent_load_list); |
| 4429 | |
| 4430 | Qstandard_input = intern_c_string ("standard-input"); |
| 4431 | staticpro (&Qstandard_input); |
| 4432 | |
| 4433 | Qread_char = intern_c_string ("read-char"); |
| 4434 | staticpro (&Qread_char); |
| 4435 | |
| 4436 | Qget_file_char = intern_c_string ("get-file-char"); |
| 4437 | staticpro (&Qget_file_char); |
| 4438 | |
| 4439 | Qget_emacs_mule_file_char = intern_c_string ("get-emacs-mule-file-char"); |
| 4440 | staticpro (&Qget_emacs_mule_file_char); |
| 4441 | |
| 4442 | Qload_force_doc_strings = intern_c_string ("load-force-doc-strings"); |
| 4443 | staticpro (&Qload_force_doc_strings); |
| 4444 | |
| 4445 | Qbackquote = intern_c_string ("`"); |
| 4446 | staticpro (&Qbackquote); |
| 4447 | Qcomma = intern_c_string (","); |
| 4448 | staticpro (&Qcomma); |
| 4449 | Qcomma_at = intern_c_string (",@"); |
| 4450 | staticpro (&Qcomma_at); |
| 4451 | Qcomma_dot = intern_c_string (",."); |
| 4452 | staticpro (&Qcomma_dot); |
| 4453 | |
| 4454 | Qinhibit_file_name_operation = intern_c_string ("inhibit-file-name-operation"); |
| 4455 | staticpro (&Qinhibit_file_name_operation); |
| 4456 | |
| 4457 | Qascii_character = intern_c_string ("ascii-character"); |
| 4458 | staticpro (&Qascii_character); |
| 4459 | |
| 4460 | Qfunction = intern_c_string ("function"); |
| 4461 | staticpro (&Qfunction); |
| 4462 | |
| 4463 | Qload = intern_c_string ("load"); |
| 4464 | staticpro (&Qload); |
| 4465 | |
| 4466 | Qload_file_name = intern_c_string ("load-file-name"); |
| 4467 | staticpro (&Qload_file_name); |
| 4468 | |
| 4469 | Qeval_buffer_list = intern_c_string ("eval-buffer-list"); |
| 4470 | staticpro (&Qeval_buffer_list); |
| 4471 | |
| 4472 | Qfile_truename = intern_c_string ("file-truename"); |
| 4473 | staticpro (&Qfile_truename) ; |
| 4474 | |
| 4475 | Qdo_after_load_evaluation = intern_c_string ("do-after-load-evaluation"); |
| 4476 | staticpro (&Qdo_after_load_evaluation) ; |
| 4477 | |
| 4478 | staticpro (&dump_path); |
| 4479 | |
| 4480 | staticpro (&read_objects); |
| 4481 | read_objects = Qnil; |
| 4482 | staticpro (&seen_list); |
| 4483 | seen_list = Qnil; |
| 4484 | |
| 4485 | Vloads_in_progress = Qnil; |
| 4486 | staticpro (&Vloads_in_progress); |
| 4487 | |
| 4488 | Qhash_table = intern_c_string ("hash-table"); |
| 4489 | staticpro (&Qhash_table); |
| 4490 | Qdata = intern_c_string ("data"); |
| 4491 | staticpro (&Qdata); |
| 4492 | Qtest = intern_c_string ("test"); |
| 4493 | staticpro (&Qtest); |
| 4494 | Qsize = intern_c_string ("size"); |
| 4495 | staticpro (&Qsize); |
| 4496 | Qweakness = intern_c_string ("weakness"); |
| 4497 | staticpro (&Qweakness); |
| 4498 | Qrehash_size = intern_c_string ("rehash-size"); |
| 4499 | staticpro (&Qrehash_size); |
| 4500 | Qrehash_threshold = intern_c_string ("rehash-threshold"); |
| 4501 | staticpro (&Qrehash_threshold); |
| 4502 | } |
| 4503 | |
| 4504 | /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d |
| 4505 | (do not change this comment) */ |