Merge from trunk.
[emacs.git] / src / lread.c
blobb29971a5f880fec20dea0923d06a4038c0ed3eb4
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.
6 This file is part of GNU Emacs.
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.
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.
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/>. */
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"
43 #ifdef MSDOS
44 #include "msdos.h"
45 #endif
47 #ifdef HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
51 #include <math.h>
53 #ifdef HAVE_SETLOCALE
54 #include <locale.h>
55 #endif /* HAVE_SETLOCALE */
57 #ifdef HAVE_FCNTL_H
58 #include <fcntl.h>
59 #endif
60 #ifndef O_RDONLY
61 #define O_RDONLY 0
62 #endif
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
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;
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 */
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;
92 static Lisp_Object Qload_force_doc_strings;
94 extern Lisp_Object Qevent_symbol_element_mask;
95 extern Lisp_Object Qfile_exists_p;
97 /* non-zero if inside `load' */
98 int load_in_progress;
99 static Lisp_Object Qload_in_progress;
101 /* Directory in which the sources were found. */
102 Lisp_Object Vsource_directory;
104 /* Search path and suffixes for files to be loaded. */
105 Lisp_Object Vload_path, Vload_suffixes, Vload_file_rep_suffixes;
107 /* File name of user's init file. */
108 Lisp_Object Vuser_init_file;
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;
114 /* This is used to build the load history. */
115 Lisp_Object Vcurrent_load_list;
117 /* List of files that were preloaded. */
118 Lisp_Object Vpreloaded_file_list;
120 /* Name of file actually being read by `load'. */
121 Lisp_Object Vload_file_name;
123 /* Function to use for reading, in `load' and friends. */
124 Lisp_Object Vload_read_function;
126 /* Non-nil means read recursive structures using #n= and #n# syntax. */
127 Lisp_Object Vread_circle;
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;
135 /* Nonzero means load should forcibly load all dynamic doc strings. */
136 static int load_force_doc_strings;
138 /* Nonzero means read should convert strings to unibyte. */
139 static int load_convert_to_unibyte;
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;
146 /* Function to use for loading an Emacs Lisp source file (not
147 compiled) instead of readevalloop. */
148 Lisp_Object Vload_source_file_function;
150 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
151 Lisp_Object Vbyte_boolean_vars;
153 /* Whether or not to add a `read-positions' property to symbols
154 read. */
155 Lisp_Object Vread_with_symbol_positions;
157 /* List of (SYMBOL . POSITION) accumulated so far. */
158 Lisp_Object Vread_symbol_positions_list;
160 /* List of descriptors now open for Fload. */
161 static Lisp_Object load_descriptor_list;
163 /* File for get_file_char to read from. Use by load. */
164 static FILE *instream;
166 /* When nonzero, read conses in pure space */
167 static int read_pure;
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;
174 /* Number of characters read in the current call to Fread or
175 Fread_from_string. */
176 static int readchar_count;
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;
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;
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;
205 /* A list of file names for files being loaded in Fload. Used to
206 check for recursive loads. */
208 static Lisp_Object Vloads_in_progress;
210 /* Non-zero means load dangerous compiled Lisp files. */
212 int load_dangerous_libraries;
214 /* Non-zero means force printing messages when loading Lisp files. */
216 int force_load_messages;
218 /* A regular expression used to detect files compiled with Emacs. */
220 static Lisp_Object Vbytecomp_version_regexp;
222 static int read_emacs_mule_char (int, int (*) (int, Lisp_Object),
223 Lisp_Object);
225 static void readevalloop (Lisp_Object, FILE*, Lisp_Object,
226 Lisp_Object (*) (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);
232 static void invalid_syntax (const char *, int) NO_RETURN;
233 static void end_of_file_error (void) NO_RETURN;
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. */
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);
246 /* Handle unreading and rereading of characters.
247 Write READCHAR to read a character,
248 UNREAD(c) to unread c to be read again.
250 These macros correctly read/unread multibyte characters. */
252 #define READCHAR readchar (readcharfun, NULL)
253 #define UNREAD(c) unreadchar (readcharfun, c)
255 /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
256 #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
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;
264 static int
265 readchar (Lisp_Object readcharfun, int *multibyte)
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;
274 if (multibyte)
275 *multibyte = 0;
277 readchar_count++;
279 if (BUFFERP (readcharfun))
281 register struct buffer *inbuffer = XBUFFER (readcharfun);
283 int pt_byte = BUF_PT_BYTE (inbuffer);
285 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
286 return -1;
288 if (! NILP (inbuffer->enable_multibyte_characters))
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;
297 else
299 c = BUF_FETCH_BYTE (inbuffer, pt_byte);
300 if (! ASCII_BYTE_P (c))
301 c = BYTE8_TO_CHAR (c);
302 pt_byte++;
304 SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
306 return c;
308 if (MARKERP (readcharfun))
310 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
312 int bytepos = marker_byte_position (readcharfun);
314 if (bytepos >= BUF_ZV_BYTE (inbuffer))
315 return -1;
317 if (! NILP (inbuffer->enable_multibyte_characters))
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;
326 else
328 c = BUF_FETCH_BYTE (inbuffer, bytepos);
329 if (! ASCII_BYTE_P (c))
330 c = BYTE8_TO_CHAR (c);
331 bytepos++;
334 XMARKER (readcharfun)->bytepos = bytepos;
335 XMARKER (readcharfun)->charpos++;
337 return c;
340 if (EQ (readcharfun, Qlambda))
342 readbyte = readbyte_for_lambda;
343 goto read_multibyte;
346 if (EQ (readcharfun, Qget_file_char))
348 readbyte = readbyte_from_file;
349 goto read_multibyte;
352 if (STRINGP (readcharfun))
354 if (read_from_string_index >= read_from_string_limit)
355 c = -1;
356 else if (STRING_MULTIBYTE (readcharfun))
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);
364 else
366 c = SREF (readcharfun, read_from_string_index_byte);
367 read_from_string_index++;
368 read_from_string_index_byte++;
370 return c;
373 if (CONSP (readcharfun))
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;
386 if (EQ (readcharfun, Qget_emacs_mule_file_char))
388 readbyte = readbyte_from_file;
389 emacs_mule_encoding = 1;
390 goto read_multibyte;
393 tem = call0 (readcharfun);
395 if (NILP (tem))
396 return -1;
397 return XINT (tem);
399 read_multibyte:
400 if (unread_char >= 0)
402 c = unread_char;
403 unread_char = -1;
404 return c;
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)
420 c = (*readbyte) (-1, readcharfun);
421 if (c < 0 || ! TRAILING_CODE_P (c))
423 while (--i > 1)
424 (*readbyte) (buf[i], readcharfun);
425 return BYTE8_TO_CHAR (buf[0]);
427 buf[i++] = c;
429 return STRING_CHAR (buf);
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. */
435 static void
436 unreadchar (Lisp_Object readcharfun, int c)
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. */
443 else if (BUFFERP (readcharfun))
445 struct buffer *b = XBUFFER (readcharfun);
446 int bytepos = BUF_PT_BYTE (b);
448 BUF_PT (b)--;
449 if (! NILP (b->enable_multibyte_characters))
450 BUF_DEC_POS (b, bytepos);
451 else
452 bytepos--;
454 BUF_PT_BYTE (b) = bytepos;
456 else if (MARKERP (readcharfun))
458 struct buffer *b = XMARKER (readcharfun)->buffer;
459 int bytepos = XMARKER (readcharfun)->bytepos;
461 XMARKER (readcharfun)->charpos--;
462 if (! NILP (b->enable_multibyte_characters))
463 BUF_DEC_POS (b, bytepos);
464 else
465 bytepos--;
467 XMARKER (readcharfun)->bytepos = bytepos;
469 else if (STRINGP (readcharfun))
471 read_from_string_index--;
472 read_from_string_index_byte
473 = string_char_to_byte (readcharfun, read_from_string_index);
475 else if (CONSP (readcharfun))
477 unread_char = c;
479 else if (EQ (readcharfun, Qlambda))
481 unread_char = c;
483 else if (EQ (readcharfun, Qget_file_char)
484 || EQ (readcharfun, Qget_emacs_mule_file_char))
486 if (load_each_byte)
488 BLOCK_INPUT;
489 ungetc (c, instream);
490 UNBLOCK_INPUT;
492 else
493 unread_char = c;
495 else
496 call1 (readcharfun, make_number (c));
499 static int
500 readbyte_for_lambda (int c, Lisp_Object readcharfun)
502 return read_bytecode_char (c >= 0);
506 static int
507 readbyte_from_file (int c, Lisp_Object readcharfun)
509 if (c >= 0)
511 BLOCK_INPUT;
512 ungetc (c, instream);
513 UNBLOCK_INPUT;
514 return 0;
517 BLOCK_INPUT;
518 c = getc (instream);
520 #ifdef EINTR
521 /* Interrupted reads have been observed while reading over the network */
522 while (c == EOF && ferror (instream) && errno == EINTR)
524 UNBLOCK_INPUT;
525 QUIT;
526 BLOCK_INPUT;
527 clearerr (instream);
528 c = getc (instream);
530 #endif
532 UNBLOCK_INPUT;
534 return (c == EOF ? -1 : c);
537 static int
538 readbyte_from_string (int c, Lisp_Object readcharfun)
540 Lisp_Object string = XCAR (readcharfun);
542 if (c >= 0)
544 read_from_string_index--;
545 read_from_string_index_byte
546 = string_char_to_byte (string, read_from_string_index);
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;
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. */
563 extern char emacs_mule_bytes[256];
565 static int
566 read_emacs_mule_char (int c, int (*readbyte) (int, Lisp_Object), Lisp_Object readcharfun)
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;
575 if (len == 1)
576 /* C is not a valid leading-code of `emacs-mule'. */
577 return BYTE8_TO_CHAR (c);
579 i = 0;
580 buf[i++] = c;
581 while (i < len)
583 c = (*readbyte) (-1, readcharfun);
584 if (c < 0xA0)
586 while (--i > 1)
587 (*readbyte) (buf[i], readcharfun);
588 return BYTE8_TO_CHAR (buf[0]);
590 buf[i++] = c;
593 if (len == 2)
595 charset = emacs_mule_charset[buf[0]];
596 code = buf[1] & 0x7F;
598 else if (len == 3)
600 if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11
601 || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12)
603 charset = emacs_mule_charset[buf[1]];
604 code = buf[2] & 0x7F;
606 else
608 charset = emacs_mule_charset[buf[0]];
609 code = ((buf[1] << 8) | buf[2]) & 0x7F7F;
612 else
614 charset = emacs_mule_charset[buf[1]];
615 code = ((buf[2] << 8) | buf[3]) & 0x7F7F;
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;
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);
630 static Lisp_Object read_list (int, Lisp_Object);
631 static Lisp_Object read_vector (Lisp_Object, int);
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);
640 /* Get a character from the tty. */
642 /* Read input events until we get one that's acceptable for our purposes.
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.
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.
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.
657 If INPUT_METHOD is nonzero, we invoke the current input method
658 if the character warrants that.
660 If SECONDS is a number, we wait that many seconds for input, and
661 return Qnil if no input arrives within that time. */
663 Lisp_Object
664 read_filtered_event (int no_switch_frame, int ascii_required,
665 int error_nonascii, int input_method, Lisp_Object seconds)
667 Lisp_Object val, delayed_switch_frame;
668 EMACS_TIME end_time;
670 #ifdef HAVE_WINDOW_SYSTEM
671 if (display_hourglass_p)
672 cancel_hourglass ();
673 #endif
675 delayed_switch_frame = Qnil;
677 /* Compute timeout. */
678 if (NUMBERP (seconds))
680 EMACS_TIME wait_time;
681 int sec, usec;
682 double duration = extract_float (seconds);
684 sec = (int) duration;
685 usec = (duration - sec) * 1000000;
686 EMACS_GET_TIME (end_time);
687 EMACS_SET_SECS_USECS (wait_time, sec, usec);
688 EMACS_ADD_TIME (end_time, end_time, wait_time);
691 /* Read until we get an acceptable event. */
692 retry:
694 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0,
695 NUMBERP (seconds) ? &end_time : NULL);
696 while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */
698 if (BUFFERP (val))
699 goto retry;
701 /* switch-frame events are put off until after the next ASCII
702 character. This is better than signaling an error just because
703 the last characters were typed to a separate minibuffer frame,
704 for example. Eventually, some code which can deal with
705 switch-frame events will read it and process it. */
706 if (no_switch_frame
707 && EVENT_HAS_PARAMETERS (val)
708 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame))
710 delayed_switch_frame = val;
711 goto retry;
714 if (ascii_required && !(NUMBERP (seconds) && NILP (val)))
716 /* Convert certain symbols to their ASCII equivalents. */
717 if (SYMBOLP (val))
719 Lisp_Object tem, tem1;
720 tem = Fget (val, Qevent_symbol_element_mask);
721 if (!NILP (tem))
723 tem1 = Fget (Fcar (tem), Qascii_character);
724 /* Merge this symbol's modifier bits
725 with the ASCII equivalent of its basic code. */
726 if (!NILP (tem1))
727 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
731 /* If we don't have a character now, deal with it appropriately. */
732 if (!INTEGERP (val))
734 if (error_nonascii)
736 Vunread_command_events = Fcons (val, Qnil);
737 error ("Non-character input-event");
739 else
740 goto retry;
744 if (! NILP (delayed_switch_frame))
745 unread_switch_frame = delayed_switch_frame;
747 #if 0
749 #ifdef HAVE_WINDOW_SYSTEM
750 if (display_hourglass_p)
751 start_hourglass ();
752 #endif
754 #endif
756 return val;
759 DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
760 doc: /* Read a character from the command input (keyboard or macro).
761 It is returned as a number.
762 If the character has modifiers, they are resolved and reflected to the
763 character code if possible (e.g. C-SPC -> 0).
765 If the user generates an event which is not a character (i.e. a mouse
766 click or function key event), `read-char' signals an error. As an
767 exception, switch-frame events are put off until non-character events
768 can be read.
769 If you want to read non-character events, or ignore them, call
770 `read-event' or `read-char-exclusive' instead.
772 If the optional argument PROMPT is non-nil, display that as a prompt.
773 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
774 input method is turned on in the current buffer, that input method
775 is used for reading a character.
776 If the optional argument SECONDS is non-nil, it should be a number
777 specifying the maximum number of seconds to wait for input. If no
778 input arrives in that time, return nil. SECONDS may be a
779 floating-point value. */)
780 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
782 Lisp_Object val;
784 if (! NILP (prompt))
785 message_with_string ("%s", prompt, 0);
786 val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
788 return (NILP (val) ? Qnil
789 : make_number (char_resolve_modifier_mask (XINT (val))));
792 DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
793 doc: /* Read an event object from the input stream.
794 If the optional argument PROMPT is non-nil, display that as a prompt.
795 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
796 input method is turned on in the current buffer, that input method
797 is used for reading a character.
798 If the optional argument SECONDS is non-nil, it should be a number
799 specifying the maximum number of seconds to wait for input. If no
800 input arrives in that time, return nil. SECONDS may be a
801 floating-point value. */)
802 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
804 if (! NILP (prompt))
805 message_with_string ("%s", prompt, 0);
806 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds);
809 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0,
810 doc: /* Read a character from the command input (keyboard or macro).
811 It is returned as a number. Non-character events are ignored.
812 If the character has modifiers, they are resolved and reflected to the
813 character code if possible (e.g. C-SPC -> 0).
815 If the optional argument PROMPT is non-nil, display that as a prompt.
816 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
817 input method is turned on in the current buffer, that input method
818 is used for reading a character.
819 If the optional argument SECONDS is non-nil, it should be a number
820 specifying the maximum number of seconds to wait for input. If no
821 input arrives in that time, return nil. SECONDS may be a
822 floating-point value. */)
823 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
825 Lisp_Object val;
827 if (! NILP (prompt))
828 message_with_string ("%s", prompt, 0);
830 val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds);
832 return (NILP (val) ? Qnil
833 : make_number (char_resolve_modifier_mask (XINT (val))));
836 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
837 doc: /* Don't use this yourself. */)
838 (void)
840 register Lisp_Object val;
841 BLOCK_INPUT;
842 XSETINT (val, getc (instream));
843 UNBLOCK_INPUT;
844 return val;
849 /* Value is a version number of byte compiled code if the file
850 associated with file descriptor FD is a compiled Lisp file that's
851 safe to load. Only files compiled with Emacs are safe to load.
852 Files compiled with XEmacs can lead to a crash in Fbyte_code
853 because of an incompatible change in the byte compiler. */
855 static int
856 safe_to_load_p (int fd)
858 char buf[512];
859 int nbytes, i;
860 int safe_p = 1;
861 int version = 1;
863 /* Read the first few bytes from the file, and look for a line
864 specifying the byte compiler version used. */
865 nbytes = emacs_read (fd, buf, sizeof buf - 1);
866 if (nbytes > 0)
868 buf[nbytes] = '\0';
870 /* Skip to the next newline, skipping over the initial `ELC'
871 with NUL bytes following it, but note the version. */
872 for (i = 0; i < nbytes && buf[i] != '\n'; ++i)
873 if (i == 4)
874 version = buf[i];
876 if (i == nbytes
877 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
878 buf + i) < 0)
879 safe_p = 0;
881 if (safe_p)
882 safe_p = version;
884 lseek (fd, 0, SEEK_SET);
885 return safe_p;
889 /* Callback for record_unwind_protect. Restore the old load list OLD,
890 after loading a file successfully. */
892 static Lisp_Object
893 record_load_unwind (Lisp_Object old)
895 return Vloads_in_progress = old;
898 /* This handler function is used via internal_condition_case_1. */
900 static Lisp_Object
901 load_error_handler (Lisp_Object data)
903 return Qnil;
906 static Lisp_Object
907 load_warn_old_style_backquotes (Lisp_Object file)
909 if (!NILP (Vold_style_backquotes))
911 Lisp_Object args[2];
912 args[0] = build_string ("Loading `%s': old-style backquotes detected!");
913 args[1] = file;
914 Fmessage (2, args);
916 return Qnil;
919 DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
920 doc: /* Return the suffixes that `load' should try if a suffix is \
921 required.
922 This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
923 (void)
925 Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext;
926 while (CONSP (suffixes))
928 Lisp_Object exts = Vload_file_rep_suffixes;
929 suffix = XCAR (suffixes);
930 suffixes = XCDR (suffixes);
931 while (CONSP (exts))
933 ext = XCAR (exts);
934 exts = XCDR (exts);
935 lst = Fcons (concat2 (suffix, ext), lst);
938 return Fnreverse (lst);
941 DEFUN ("load", Fload, Sload, 1, 5, 0,
942 doc: /* Execute a file of Lisp code named FILE.
943 First try FILE with `.elc' appended, then try with `.el',
944 then try FILE unmodified (the exact suffixes in the exact order are
945 determined by `load-suffixes'). Environment variable references in
946 FILE are replaced with their values by calling `substitute-in-file-name'.
947 This function searches the directories in `load-path'.
949 If optional second arg NOERROR is non-nil,
950 report no error if FILE doesn't exist.
951 Print messages at start and end of loading unless
952 optional third arg NOMESSAGE is non-nil (but `force-load-messages'
953 overrides that).
954 If optional fourth arg NOSUFFIX is non-nil, don't try adding
955 suffixes `.elc' or `.el' to the specified name FILE.
956 If optional fifth arg MUST-SUFFIX is non-nil, insist on
957 the suffix `.elc' or `.el'; don't accept just FILE unless
958 it ends in one of those suffixes or includes a directory name.
960 If this function fails to find a file, it may look for different
961 representations of that file before trying another file.
962 It does so by adding the non-empty suffixes in `load-file-rep-suffixes'
963 to the file name. Emacs uses this feature mainly to find compressed
964 versions of files when Auto Compression mode is enabled.
966 The exact suffixes that this function tries out, in the exact order,
967 are given by the value of the variable `load-file-rep-suffixes' if
968 NOSUFFIX is non-nil and by the return value of the function
969 `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and
970 MUST-SUFFIX are nil, this function first tries out the latter suffixes
971 and then the former.
973 Loading a file records its definitions, and its `provide' and
974 `require' calls, in an element of `load-history' whose
975 car is the file name loaded. See `load-history'.
977 Return t if the file exists and loads successfully. */)
978 (Lisp_Object file, Lisp_Object noerror, Lisp_Object nomessage, Lisp_Object nosuffix, Lisp_Object must_suffix)
980 register FILE *stream;
981 register int fd = -1;
982 int count = SPECPDL_INDEX ();
983 struct gcpro gcpro1, gcpro2, gcpro3;
984 Lisp_Object found, efound, hist_file_name;
985 /* 1 means we printed the ".el is newer" message. */
986 int newer = 0;
987 /* 1 means we are loading a compiled file. */
988 int compiled = 0;
989 Lisp_Object handler;
990 int safe_p = 1;
991 char *fmode = "r";
992 Lisp_Object tmp[2];
993 int version;
995 #ifdef DOS_NT
996 fmode = "rt";
997 #endif /* DOS_NT */
999 CHECK_STRING (file);
1001 /* If file name is magic, call the handler. */
1002 /* This shouldn't be necessary any more now that `openp' handles it right.
1003 handler = Ffind_file_name_handler (file, Qload);
1004 if (!NILP (handler))
1005 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
1007 /* Do this after the handler to avoid
1008 the need to gcpro noerror, nomessage and nosuffix.
1009 (Below here, we care only whether they are nil or not.)
1010 The presence of this call is the result of a historical accident:
1011 it used to be in every file-operation and when it got removed
1012 everywhere, it accidentally stayed here. Since then, enough people
1013 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
1014 that it seemed risky to remove. */
1015 if (! NILP (noerror))
1017 file = internal_condition_case_1 (Fsubstitute_in_file_name, file,
1018 Qt, load_error_handler);
1019 if (NILP (file))
1020 return Qnil;
1022 else
1023 file = Fsubstitute_in_file_name (file);
1026 /* Avoid weird lossage with null string as arg,
1027 since it would try to load a directory as a Lisp file */
1028 if (SCHARS (file) > 0)
1030 int size = SBYTES (file);
1032 found = Qnil;
1033 GCPRO2 (file, found);
1035 if (! NILP (must_suffix))
1037 /* Don't insist on adding a suffix if FILE already ends with one. */
1038 if (size > 3
1039 && !strcmp (SDATA (file) + size - 3, ".el"))
1040 must_suffix = Qnil;
1041 else if (size > 4
1042 && !strcmp (SDATA (file) + size - 4, ".elc"))
1043 must_suffix = Qnil;
1044 /* Don't insist on adding a suffix
1045 if the argument includes a directory name. */
1046 else if (! NILP (Ffile_name_directory (file)))
1047 must_suffix = Qnil;
1050 fd = openp (Vload_path, file,
1051 (!NILP (nosuffix) ? Qnil
1052 : !NILP (must_suffix) ? Fget_load_suffixes ()
1053 : Fappend (2, (tmp[0] = Fget_load_suffixes (),
1054 tmp[1] = Vload_file_rep_suffixes,
1055 tmp))),
1056 &found, Qnil);
1057 UNGCPRO;
1060 if (fd == -1)
1062 if (NILP (noerror))
1063 xsignal2 (Qfile_error, build_string ("Cannot open load file"), file);
1064 return Qnil;
1067 /* Tell startup.el whether or not we found the user's init file. */
1068 if (EQ (Qt, Vuser_init_file))
1069 Vuser_init_file = found;
1071 /* If FD is -2, that means openp found a magic file. */
1072 if (fd == -2)
1074 if (NILP (Fequal (found, file)))
1075 /* If FOUND is a different file name from FILE,
1076 find its handler even if we have already inhibited
1077 the `load' operation on FILE. */
1078 handler = Ffind_file_name_handler (found, Qt);
1079 else
1080 handler = Ffind_file_name_handler (found, Qload);
1081 if (! NILP (handler))
1082 return call5 (handler, Qload, found, noerror, nomessage, Qt);
1085 /* Check if we're stuck in a recursive load cycle.
1087 2000-09-21: It's not possible to just check for the file loaded
1088 being a member of Vloads_in_progress. This fails because of the
1089 way the byte compiler currently works; `provide's are not
1090 evaluated, see font-lock.el/jit-lock.el as an example. This
1091 leads to a certain amount of ``normal'' recursion.
1093 Also, just loading a file recursively is not always an error in
1094 the general case; the second load may do something different. */
1096 int count = 0;
1097 Lisp_Object tem;
1098 for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
1099 if (!NILP (Fequal (found, XCAR (tem))) && (++count > 3))
1101 if (fd >= 0)
1102 emacs_close (fd);
1103 signal_error ("Recursive load", Fcons (found, Vloads_in_progress));
1105 record_unwind_protect (record_load_unwind, Vloads_in_progress);
1106 Vloads_in_progress = Fcons (found, Vloads_in_progress);
1109 /* Get the name for load-history. */
1110 hist_file_name = (! NILP (Vpurify_flag)
1111 ? Fconcat (2, (tmp[0] = Ffile_name_directory (file),
1112 tmp[1] = Ffile_name_nondirectory (found),
1113 tmp))
1114 : found) ;
1116 version = -1;
1118 /* Check for the presence of old-style quotes and warn about them. */
1119 specbind (Qold_style_backquotes, Qnil);
1120 record_unwind_protect (load_warn_old_style_backquotes, file);
1122 if (!memcmp (SDATA (found) + SBYTES (found) - 4, ".elc", 4)
1123 || (fd >= 0 && (version = safe_to_load_p (fd)) > 0))
1124 /* Load .elc files directly, but not when they are
1125 remote and have no handler! */
1127 if (fd != -2)
1129 struct stat s1, s2;
1130 int result;
1132 GCPRO3 (file, found, hist_file_name);
1134 if (version < 0
1135 && ! (version = safe_to_load_p (fd)))
1137 safe_p = 0;
1138 if (!load_dangerous_libraries)
1140 if (fd >= 0)
1141 emacs_close (fd);
1142 error ("File `%s' was not compiled in Emacs",
1143 SDATA (found));
1145 else if (!NILP (nomessage) && !force_load_messages)
1146 message_with_string ("File `%s' not compiled in Emacs", found, 1);
1149 compiled = 1;
1151 efound = ENCODE_FILE (found);
1153 #ifdef DOS_NT
1154 fmode = "rb";
1155 #endif /* DOS_NT */
1156 stat ((char *)SDATA (efound), &s1);
1157 SSET (efound, SBYTES (efound) - 1, 0);
1158 result = stat ((char *)SDATA (efound), &s2);
1159 SSET (efound, SBYTES (efound) - 1, 'c');
1161 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
1163 /* Make the progress messages mention that source is newer. */
1164 newer = 1;
1166 /* If we won't print another message, mention this anyway. */
1167 if (!NILP (nomessage) && !force_load_messages)
1169 Lisp_Object msg_file;
1170 msg_file = Fsubstring (found, make_number (0), make_number (-1));
1171 message_with_string ("Source file `%s' newer than byte-compiled file",
1172 msg_file, 1);
1175 UNGCPRO;
1178 else
1180 /* We are loading a source file (*.el). */
1181 if (!NILP (Vload_source_file_function))
1183 Lisp_Object val;
1185 if (fd >= 0)
1186 emacs_close (fd);
1187 val = call4 (Vload_source_file_function, found, hist_file_name,
1188 NILP (noerror) ? Qnil : Qt,
1189 (NILP (nomessage) || force_load_messages) ? Qnil : Qt);
1190 return unbind_to (count, val);
1194 GCPRO3 (file, found, hist_file_name);
1196 #ifdef WINDOWSNT
1197 emacs_close (fd);
1198 efound = ENCODE_FILE (found);
1199 stream = fopen ((char *) SDATA (efound), fmode);
1200 #else /* not WINDOWSNT */
1201 stream = fdopen (fd, fmode);
1202 #endif /* not WINDOWSNT */
1203 if (stream == 0)
1205 emacs_close (fd);
1206 error ("Failure to create stdio stream for %s", SDATA (file));
1209 if (! NILP (Vpurify_flag))
1210 Vpreloaded_file_list = Fcons (Fpurecopy(file), Vpreloaded_file_list);
1212 if (NILP (nomessage) || force_load_messages)
1214 if (!safe_p)
1215 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
1216 file, 1);
1217 else if (!compiled)
1218 message_with_string ("Loading %s (source)...", file, 1);
1219 else if (newer)
1220 message_with_string ("Loading %s (compiled; note, source file is newer)...",
1221 file, 1);
1222 else /* The typical case; compiled file newer than source file. */
1223 message_with_string ("Loading %s...", file, 1);
1226 record_unwind_protect (load_unwind, make_save_value (stream, 0));
1227 record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
1228 specbind (Qload_file_name, found);
1229 specbind (Qinhibit_file_name_operation, Qnil);
1230 load_descriptor_list
1231 = Fcons (make_number (fileno (stream)), load_descriptor_list);
1232 specbind (Qload_in_progress, Qt);
1233 if (! version || version >= 22)
1234 readevalloop (Qget_file_char, stream, hist_file_name,
1235 Feval, 0, Qnil, Qnil, Qnil, Qnil);
1236 else
1238 /* We can't handle a file which was compiled with
1239 byte-compile-dynamic by older version of Emacs. */
1240 specbind (Qload_force_doc_strings, Qt);
1241 readevalloop (Qget_emacs_mule_file_char, stream, hist_file_name, Feval,
1242 0, Qnil, Qnil, Qnil, Qnil);
1244 unbind_to (count, Qnil);
1246 /* Run any eval-after-load forms for this file */
1247 if (!NILP (Ffboundp (Qdo_after_load_evaluation)))
1248 call1 (Qdo_after_load_evaluation, hist_file_name) ;
1250 UNGCPRO;
1252 xfree (saved_doc_string);
1253 saved_doc_string = 0;
1254 saved_doc_string_size = 0;
1256 xfree (prev_saved_doc_string);
1257 prev_saved_doc_string = 0;
1258 prev_saved_doc_string_size = 0;
1260 if (!noninteractive && (NILP (nomessage) || force_load_messages))
1262 if (!safe_p)
1263 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
1264 file, 1);
1265 else if (!compiled)
1266 message_with_string ("Loading %s (source)...done", file, 1);
1267 else if (newer)
1268 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
1269 file, 1);
1270 else /* The typical case; compiled file newer than source file. */
1271 message_with_string ("Loading %s...done", file, 1);
1274 return Qt;
1277 static Lisp_Object
1278 load_unwind (Lisp_Object arg) /* used as unwind-protect function in load */
1280 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
1281 if (stream != NULL)
1283 BLOCK_INPUT;
1284 fclose (stream);
1285 UNBLOCK_INPUT;
1287 return Qnil;
1290 static Lisp_Object
1291 load_descriptor_unwind (Lisp_Object oldlist)
1293 load_descriptor_list = oldlist;
1294 return Qnil;
1297 /* Close all descriptors in use for Floads.
1298 This is used when starting a subprocess. */
1300 void
1301 close_load_descs (void)
1303 #ifndef WINDOWSNT
1304 Lisp_Object tail;
1305 for (tail = load_descriptor_list; CONSP (tail); tail = XCDR (tail))
1306 emacs_close (XFASTINT (XCAR (tail)));
1307 #endif
1310 static int
1311 complete_filename_p (Lisp_Object pathname)
1313 register const unsigned char *s = SDATA (pathname);
1314 return (IS_DIRECTORY_SEP (s[0])
1315 || (SCHARS (pathname) > 2
1316 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])));
1319 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
1320 doc: /* Search for FILENAME through PATH.
1321 Returns the file's name in absolute form, or nil if not found.
1322 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1323 file name when searching.
1324 If non-nil, PREDICATE is used instead of `file-readable-p'.
1325 PREDICATE can also be an integer to pass to the access(2) function,
1326 in which case file-name-handlers are ignored. */)
1327 (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate)
1329 Lisp_Object file;
1330 int fd = openp (path, filename, suffixes, &file, predicate);
1331 if (NILP (predicate) && fd > 0)
1332 close (fd);
1333 return file;
1337 /* Search for a file whose name is STR, looking in directories
1338 in the Lisp list PATH, and trying suffixes from SUFFIX.
1339 On success, returns a file descriptor. On failure, returns -1.
1341 SUFFIXES is a list of strings containing possible suffixes.
1342 The empty suffix is automatically added if the list is empty.
1344 PREDICATE non-nil means don't open the files,
1345 just look for one that satisfies the predicate. In this case,
1346 returns 1 on success. The predicate can be a lisp function or
1347 an integer to pass to `access' (in which case file-name-handlers
1348 are ignored).
1350 If STOREPTR is nonzero, it points to a slot where the name of
1351 the file actually found should be stored as a Lisp string.
1352 nil is stored there on failure.
1354 If the file we find is remote, return -2
1355 but store the found remote file name in *STOREPTR. */
1358 openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate)
1360 register int fd;
1361 int fn_size = 100;
1362 char buf[100];
1363 register char *fn = buf;
1364 int absolute = 0;
1365 int want_size;
1366 Lisp_Object filename;
1367 struct stat st;
1368 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1369 Lisp_Object string, tail, encoded_fn;
1370 int max_suffix_len = 0;
1372 CHECK_STRING (str);
1374 for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
1376 CHECK_STRING_CAR (tail);
1377 max_suffix_len = max (max_suffix_len,
1378 SBYTES (XCAR (tail)));
1381 string = filename = encoded_fn = Qnil;
1382 GCPRO6 (str, string, filename, path, suffixes, encoded_fn);
1384 if (storeptr)
1385 *storeptr = Qnil;
1387 if (complete_filename_p (str))
1388 absolute = 1;
1390 for (; CONSP (path); path = XCDR (path))
1392 filename = Fexpand_file_name (str, XCAR (path));
1393 if (!complete_filename_p (filename))
1394 /* If there are non-absolute elts in PATH (eg ".") */
1395 /* Of course, this could conceivably lose if luser sets
1396 default-directory to be something non-absolute... */
1398 filename = Fexpand_file_name (filename, current_buffer->directory);
1399 if (!complete_filename_p (filename))
1400 /* Give up on this path element! */
1401 continue;
1404 /* Calculate maximum size of any filename made from
1405 this path element/specified file name and any possible suffix. */
1406 want_size = max_suffix_len + SBYTES (filename) + 1;
1407 if (fn_size < want_size)
1408 fn = (char *) alloca (fn_size = 100 + want_size);
1410 /* Loop over suffixes. */
1411 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1412 CONSP (tail); tail = XCDR (tail))
1414 int lsuffix = SBYTES (XCAR (tail));
1415 Lisp_Object handler;
1416 int exists;
1418 /* Concatenate path element/specified name with the suffix.
1419 If the directory starts with /:, remove that. */
1420 if (SCHARS (filename) > 2
1421 && SREF (filename, 0) == '/'
1422 && SREF (filename, 1) == ':')
1424 strncpy (fn, SDATA (filename) + 2,
1425 SBYTES (filename) - 2);
1426 fn[SBYTES (filename) - 2] = 0;
1428 else
1430 strncpy (fn, SDATA (filename),
1431 SBYTES (filename));
1432 fn[SBYTES (filename)] = 0;
1435 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1436 strncat (fn, SDATA (XCAR (tail)), lsuffix);
1438 /* Check that the file exists and is not a directory. */
1439 /* We used to only check for handlers on non-absolute file names:
1440 if (absolute)
1441 handler = Qnil;
1442 else
1443 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1444 It's not clear why that was the case and it breaks things like
1445 (load "/bar.el") where the file is actually "/bar.el.gz". */
1446 string = build_string (fn);
1447 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1448 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1450 if (NILP (predicate))
1451 exists = !NILP (Ffile_readable_p (string));
1452 else
1453 exists = !NILP (call1 (predicate, string));
1454 if (exists && !NILP (Ffile_directory_p (string)))
1455 exists = 0;
1457 if (exists)
1459 /* We succeeded; return this descriptor and filename. */
1460 if (storeptr)
1461 *storeptr = string;
1462 UNGCPRO;
1463 return -2;
1466 else
1468 const char *pfn;
1470 encoded_fn = ENCODE_FILE (string);
1471 pfn = SDATA (encoded_fn);
1472 exists = (stat (pfn, &st) >= 0
1473 && (st.st_mode & S_IFMT) != S_IFDIR);
1474 if (exists)
1476 /* Check that we can access or open it. */
1477 if (NATNUMP (predicate))
1478 fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1;
1479 else
1480 fd = emacs_open (pfn, O_RDONLY, 0);
1482 if (fd >= 0)
1484 /* We succeeded; return this descriptor and filename. */
1485 if (storeptr)
1486 *storeptr = string;
1487 UNGCPRO;
1488 return fd;
1493 if (absolute)
1494 break;
1497 UNGCPRO;
1498 return -1;
1502 /* Merge the list we've accumulated of globals from the current input source
1503 into the load_history variable. The details depend on whether
1504 the source has an associated file name or not.
1506 FILENAME is the file name that we are loading from.
1507 ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */
1509 static void
1510 build_load_history (Lisp_Object filename, int entire)
1512 register Lisp_Object tail, prev, newelt;
1513 register Lisp_Object tem, tem2;
1514 register int foundit = 0;
1516 tail = Vload_history;
1517 prev = Qnil;
1519 while (CONSP (tail))
1521 tem = XCAR (tail);
1523 /* Find the feature's previous assoc list... */
1524 if (!NILP (Fequal (filename, Fcar (tem))))
1526 foundit = 1;
1528 /* If we're loading the entire file, remove old data. */
1529 if (entire)
1531 if (NILP (prev))
1532 Vload_history = XCDR (tail);
1533 else
1534 Fsetcdr (prev, XCDR (tail));
1537 /* Otherwise, cons on new symbols that are not already members. */
1538 else
1540 tem2 = Vcurrent_load_list;
1542 while (CONSP (tem2))
1544 newelt = XCAR (tem2);
1546 if (NILP (Fmember (newelt, tem)))
1547 Fsetcar (tail, Fcons (XCAR (tem),
1548 Fcons (newelt, XCDR (tem))));
1550 tem2 = XCDR (tem2);
1551 QUIT;
1555 else
1556 prev = tail;
1557 tail = XCDR (tail);
1558 QUIT;
1561 /* If we're loading an entire file, cons the new assoc onto the
1562 front of load-history, the most-recently-loaded position. Also
1563 do this if we didn't find an existing member for the file. */
1564 if (entire || !foundit)
1565 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1566 Vload_history);
1569 static Lisp_Object
1570 unreadpure (Lisp_Object junk) /* Used as unwind-protect function in readevalloop */
1572 read_pure = 0;
1573 return Qnil;
1576 static Lisp_Object
1577 readevalloop_1 (Lisp_Object old)
1579 load_convert_to_unibyte = ! NILP (old);
1580 return Qnil;
1583 /* Signal an `end-of-file' error, if possible with file name
1584 information. */
1586 static void
1587 end_of_file_error (void)
1589 if (STRINGP (Vload_file_name))
1590 xsignal1 (Qend_of_file, Vload_file_name);
1592 xsignal0 (Qend_of_file);
1595 /* UNIBYTE specifies how to set load_convert_to_unibyte
1596 for this invocation.
1597 READFUN, if non-nil, is used instead of `read'.
1599 START, END specify region to read in current buffer (from eval-region).
1600 If the input is not from a buffer, they must be nil. */
1602 static void
1603 readevalloop (Lisp_Object readcharfun,
1604 FILE *stream,
1605 Lisp_Object sourcename,
1606 Lisp_Object (*evalfun) (Lisp_Object),
1607 int printflag,
1608 Lisp_Object unibyte, Lisp_Object readfun,
1609 Lisp_Object start, Lisp_Object end)
1611 register int c;
1612 register Lisp_Object val;
1613 int count = SPECPDL_INDEX ();
1614 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1615 struct buffer *b = 0;
1616 int continue_reading_p;
1617 /* Nonzero if reading an entire buffer. */
1618 int whole_buffer = 0;
1619 /* 1 on the first time around. */
1620 int first_sexp = 1;
1622 if (MARKERP (readcharfun))
1624 if (NILP (start))
1625 start = readcharfun;
1628 if (BUFFERP (readcharfun))
1629 b = XBUFFER (readcharfun);
1630 else if (MARKERP (readcharfun))
1631 b = XMARKER (readcharfun)->buffer;
1633 /* We assume START is nil when input is not from a buffer. */
1634 if (! NILP (start) && !b)
1635 abort ();
1637 specbind (Qstandard_input, readcharfun); /* GCPROs readcharfun. */
1638 specbind (Qcurrent_load_list, Qnil);
1639 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
1640 load_convert_to_unibyte = !NILP (unibyte);
1642 GCPRO4 (sourcename, readfun, start, end);
1644 /* Try to ensure sourcename is a truename, except whilst preloading. */
1645 if (NILP (Vpurify_flag)
1646 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename))
1647 && !NILP (Ffboundp (Qfile_truename)))
1648 sourcename = call1 (Qfile_truename, sourcename) ;
1650 LOADHIST_ATTACH (sourcename);
1652 continue_reading_p = 1;
1653 while (continue_reading_p)
1655 int count1 = SPECPDL_INDEX ();
1657 if (b != 0 && NILP (b->name))
1658 error ("Reading from killed buffer");
1660 if (!NILP (start))
1662 /* Switch to the buffer we are reading from. */
1663 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1664 set_buffer_internal (b);
1666 /* Save point in it. */
1667 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1668 /* Save ZV in it. */
1669 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1670 /* Those get unbound after we read one expression. */
1672 /* Set point and ZV around stuff to be read. */
1673 Fgoto_char (start);
1674 if (!NILP (end))
1675 Fnarrow_to_region (make_number (BEGV), end);
1677 /* Just for cleanliness, convert END to a marker
1678 if it is an integer. */
1679 if (INTEGERP (end))
1680 end = Fpoint_max_marker ();
1683 /* On the first cycle, we can easily test here
1684 whether we are reading the whole buffer. */
1685 if (b && first_sexp)
1686 whole_buffer = (PT == BEG && ZV == Z);
1688 instream = stream;
1689 read_next:
1690 c = READCHAR;
1691 if (c == ';')
1693 while ((c = READCHAR) != '\n' && c != -1);
1694 goto read_next;
1696 if (c < 0)
1698 unbind_to (count1, Qnil);
1699 break;
1702 /* Ignore whitespace here, so we can detect eof. */
1703 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'
1704 || c == 0x8a0) /* NBSP */
1705 goto read_next;
1707 if (!NILP (Vpurify_flag) && c == '(')
1709 record_unwind_protect (unreadpure, Qnil);
1710 val = read_list (-1, readcharfun);
1712 else
1714 UNREAD (c);
1715 read_objects = Qnil;
1716 if (!NILP (readfun))
1718 val = call1 (readfun, readcharfun);
1720 /* If READCHARFUN has set point to ZV, we should
1721 stop reading, even if the form read sets point
1722 to a different value when evaluated. */
1723 if (BUFFERP (readcharfun))
1725 struct buffer *b = XBUFFER (readcharfun);
1726 if (BUF_PT (b) == BUF_ZV (b))
1727 continue_reading_p = 0;
1730 else if (! NILP (Vload_read_function))
1731 val = call1 (Vload_read_function, readcharfun);
1732 else
1733 val = read_internal_start (readcharfun, Qnil, Qnil);
1736 if (!NILP (start) && continue_reading_p)
1737 start = Fpoint_marker ();
1739 /* Restore saved point and BEGV. */
1740 unbind_to (count1, Qnil);
1742 /* Now eval what we just read. */
1743 val = (*evalfun) (val);
1745 if (printflag)
1747 Vvalues = Fcons (val, Vvalues);
1748 if (EQ (Vstandard_output, Qt))
1749 Fprin1 (val, Qnil);
1750 else
1751 Fprint (val, Qnil);
1754 first_sexp = 0;
1757 build_load_history (sourcename,
1758 stream || whole_buffer);
1760 UNGCPRO;
1762 unbind_to (count, Qnil);
1765 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
1766 doc: /* Execute the current buffer as Lisp code.
1767 When called from a Lisp program (i.e., not interactively), this
1768 function accepts up to five optional arguments:
1769 BUFFER is the buffer to evaluate (nil means use current buffer).
1770 PRINTFLAG controls printing of output:
1771 A value of nil means discard it; anything else is stream for print.
1772 FILENAME specifies the file name to use for `load-history'.
1773 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
1774 invocation.
1775 DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1776 functions should work normally even if PRINTFLAG is nil.
1778 This function preserves the position of point. */)
1779 (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print)
1781 int count = SPECPDL_INDEX ();
1782 Lisp_Object tem, buf;
1784 if (NILP (buffer))
1785 buf = Fcurrent_buffer ();
1786 else
1787 buf = Fget_buffer (buffer);
1788 if (NILP (buf))
1789 error ("No such buffer");
1791 if (NILP (printflag) && NILP (do_allow_print))
1792 tem = Qsymbolp;
1793 else
1794 tem = printflag;
1796 if (NILP (filename))
1797 filename = XBUFFER (buf)->filename;
1799 specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
1800 specbind (Qstandard_output, tem);
1801 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1802 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
1803 readevalloop (buf, 0, filename, Feval,
1804 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
1805 unbind_to (count, Qnil);
1807 return Qnil;
1810 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
1811 doc: /* Execute the region as Lisp code.
1812 When called from programs, expects two arguments,
1813 giving starting and ending indices in the current buffer
1814 of the text to be executed.
1815 Programs can pass third argument PRINTFLAG which controls output:
1816 A value of nil means discard it; anything else is stream for printing it.
1817 Also the fourth argument READ-FUNCTION, if non-nil, is used
1818 instead of `read' to read each expression. It gets one argument
1819 which is the input stream for reading characters.
1821 This function does not move point. */)
1822 (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function)
1824 int count = SPECPDL_INDEX ();
1825 Lisp_Object tem, cbuf;
1827 cbuf = Fcurrent_buffer ();
1829 if (NILP (printflag))
1830 tem = Qsymbolp;
1831 else
1832 tem = printflag;
1833 specbind (Qstandard_output, tem);
1834 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list));
1836 /* readevalloop calls functions which check the type of start and end. */
1837 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
1838 !NILP (printflag), Qnil, read_function,
1839 start, end);
1841 return unbind_to (count, Qnil);
1845 DEFUN ("read", Fread, Sread, 0, 1, 0,
1846 doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1847 If STREAM is nil, use the value of `standard-input' (which see).
1848 STREAM or the value of `standard-input' may be:
1849 a buffer (read from point and advance it)
1850 a marker (read from where it points and advance it)
1851 a function (call it with no arguments for each character,
1852 call it with a char as argument to push a char back)
1853 a string (takes text from string, starting at the beginning)
1854 t (read text line using minibuffer and use it, or read from
1855 standard input in batch mode). */)
1856 (Lisp_Object stream)
1858 if (NILP (stream))
1859 stream = Vstandard_input;
1860 if (EQ (stream, Qt))
1861 stream = Qread_char;
1862 if (EQ (stream, Qread_char))
1863 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
1865 return read_internal_start (stream, Qnil, Qnil);
1868 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
1869 doc: /* Read one Lisp expression which is represented as text by STRING.
1870 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1871 START and END optionally delimit a substring of STRING from which to read;
1872 they default to 0 and (length STRING) respectively. */)
1873 (Lisp_Object string, Lisp_Object start, Lisp_Object end)
1875 Lisp_Object ret;
1876 CHECK_STRING (string);
1877 /* read_internal_start sets read_from_string_index. */
1878 ret = read_internal_start (string, start, end);
1879 return Fcons (ret, make_number (read_from_string_index));
1882 /* Function to set up the global context we need in toplevel read
1883 calls. */
1884 static Lisp_Object
1885 read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
1886 /* start, end only used when stream is a string. */
1888 Lisp_Object retval;
1890 readchar_count = 0;
1891 new_backquote_flag = 0;
1892 read_objects = Qnil;
1893 if (EQ (Vread_with_symbol_positions, Qt)
1894 || EQ (Vread_with_symbol_positions, stream))
1895 Vread_symbol_positions_list = Qnil;
1897 if (STRINGP (stream)
1898 || ((CONSP (stream) && STRINGP (XCAR (stream)))))
1900 int startval, endval;
1901 Lisp_Object string;
1903 if (STRINGP (stream))
1904 string = stream;
1905 else
1906 string = XCAR (stream);
1908 if (NILP (end))
1909 endval = SCHARS (string);
1910 else
1912 CHECK_NUMBER (end);
1913 endval = XINT (end);
1914 if (endval < 0 || endval > SCHARS (string))
1915 args_out_of_range (string, end);
1918 if (NILP (start))
1919 startval = 0;
1920 else
1922 CHECK_NUMBER (start);
1923 startval = XINT (start);
1924 if (startval < 0 || startval > endval)
1925 args_out_of_range (string, start);
1927 read_from_string_index = startval;
1928 read_from_string_index_byte = string_char_to_byte (string, startval);
1929 read_from_string_limit = endval;
1932 retval = read0 (stream);
1933 if (EQ (Vread_with_symbol_positions, Qt)
1934 || EQ (Vread_with_symbol_positions, stream))
1935 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list);
1936 return retval;
1940 /* Signal Qinvalid_read_syntax error.
1941 S is error string of length N (if > 0) */
1943 static void
1944 invalid_syntax (const char *s, int n)
1946 if (!n)
1947 n = strlen (s);
1948 xsignal1 (Qinvalid_read_syntax, make_string (s, n));
1952 /* Use this for recursive reads, in contexts where internal tokens
1953 are not allowed. */
1955 static Lisp_Object
1956 read0 (Lisp_Object readcharfun)
1958 register Lisp_Object val;
1959 int c;
1961 val = read1 (readcharfun, &c, 0);
1962 if (!c)
1963 return val;
1965 xsignal1 (Qinvalid_read_syntax,
1966 Fmake_string (make_number (1), make_number (c)));
1969 static int read_buffer_size;
1970 static char *read_buffer;
1972 /* Read a \-escape sequence, assuming we already read the `\'.
1973 If the escape sequence forces unibyte, return eight-bit char. */
1975 static int
1976 read_escape (Lisp_Object readcharfun, int stringp)
1978 register int c = READCHAR;
1979 /* \u allows up to four hex digits, \U up to eight. Default to the
1980 behavior for \u, and change this value in the case that \U is seen. */
1981 int unicode_hex_count = 4;
1983 switch (c)
1985 case -1:
1986 end_of_file_error ();
1988 case 'a':
1989 return '\007';
1990 case 'b':
1991 return '\b';
1992 case 'd':
1993 return 0177;
1994 case 'e':
1995 return 033;
1996 case 'f':
1997 return '\f';
1998 case 'n':
1999 return '\n';
2000 case 'r':
2001 return '\r';
2002 case 't':
2003 return '\t';
2004 case 'v':
2005 return '\v';
2006 case '\n':
2007 return -1;
2008 case ' ':
2009 if (stringp)
2010 return -1;
2011 return ' ';
2013 case 'M':
2014 c = READCHAR;
2015 if (c != '-')
2016 error ("Invalid escape character syntax");
2017 c = READCHAR;
2018 if (c == '\\')
2019 c = read_escape (readcharfun, 0);
2020 return c | meta_modifier;
2022 case 'S':
2023 c = READCHAR;
2024 if (c != '-')
2025 error ("Invalid escape character syntax");
2026 c = READCHAR;
2027 if (c == '\\')
2028 c = read_escape (readcharfun, 0);
2029 return c | shift_modifier;
2031 case 'H':
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 | hyper_modifier;
2040 case 'A':
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 | alt_modifier;
2049 case 's':
2050 c = READCHAR;
2051 if (stringp || c != '-')
2053 UNREAD (c);
2054 return ' ';
2056 c = READCHAR;
2057 if (c == '\\')
2058 c = read_escape (readcharfun, 0);
2059 return c | super_modifier;
2061 case 'C':
2062 c = READCHAR;
2063 if (c != '-')
2064 error ("Invalid escape character syntax");
2065 case '^':
2066 c = READCHAR;
2067 if (c == '\\')
2068 c = read_escape (readcharfun, 0);
2069 if ((c & ~CHAR_MODIFIER_MASK) == '?')
2070 return 0177 | (c & CHAR_MODIFIER_MASK);
2071 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
2072 return c | ctrl_modifier;
2073 /* ASCII control chars are made from letters (both cases),
2074 as well as the non-letters within 0100...0137. */
2075 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
2076 return (c & (037 | ~0177));
2077 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
2078 return (c & (037 | ~0177));
2079 else
2080 return c | ctrl_modifier;
2082 case '0':
2083 case '1':
2084 case '2':
2085 case '3':
2086 case '4':
2087 case '5':
2088 case '6':
2089 case '7':
2090 /* An octal escape, as in ANSI C. */
2092 register int i = c - '0';
2093 register int count = 0;
2094 while (++count < 3)
2096 if ((c = READCHAR) >= '0' && c <= '7')
2098 i *= 8;
2099 i += c - '0';
2101 else
2103 UNREAD (c);
2104 break;
2108 if (i >= 0x80 && i < 0x100)
2109 i = BYTE8_TO_CHAR (i);
2110 return i;
2113 case 'x':
2114 /* A hex escape, as in ANSI C. */
2116 int i = 0;
2117 int count = 0;
2118 while (1)
2120 c = READCHAR;
2121 if (c >= '0' && c <= '9')
2123 i *= 16;
2124 i += c - '0';
2126 else if ((c >= 'a' && c <= 'f')
2127 || (c >= 'A' && c <= 'F'))
2129 i *= 16;
2130 if (c >= 'a' && c <= 'f')
2131 i += c - 'a' + 10;
2132 else
2133 i += c - 'A' + 10;
2135 else
2137 UNREAD (c);
2138 break;
2140 count++;
2143 if (count < 3 && i >= 0x80)
2144 return BYTE8_TO_CHAR (i);
2145 return i;
2148 case 'U':
2149 /* Post-Unicode-2.0: Up to eight hex chars. */
2150 unicode_hex_count = 8;
2151 case 'u':
2153 /* A Unicode escape. We only permit them in strings and characters,
2154 not arbitrarily in the source code, as in some other languages. */
2156 unsigned int i = 0;
2157 int count = 0;
2159 while (++count <= unicode_hex_count)
2161 c = READCHAR;
2162 /* isdigit and isalpha may be locale-specific, which we don't
2163 want. */
2164 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
2165 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
2166 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
2167 else
2169 error ("Non-hex digit used for Unicode escape");
2170 break;
2173 if (i > 0x10FFFF)
2174 error ("Non-Unicode character: 0x%x", i);
2175 return i;
2178 default:
2179 return c;
2183 /* Read an integer in radix RADIX using READCHARFUN to read
2184 characters. RADIX must be in the interval [2..36]; if it isn't, a
2185 read error is signaled . Value is the integer read. Signals an
2186 error if encountering invalid read syntax or if RADIX is out of
2187 range. */
2189 static Lisp_Object
2190 read_integer (Lisp_Object readcharfun, int radix)
2192 int ndigits = 0, invalid_p, c, sign = 0;
2193 /* We use a floating point number because */
2194 double number = 0;
2196 if (radix < 2 || radix > 36)
2197 invalid_p = 1;
2198 else
2200 number = ndigits = invalid_p = 0;
2201 sign = 1;
2203 c = READCHAR;
2204 if (c == '-')
2206 c = READCHAR;
2207 sign = -1;
2209 else if (c == '+')
2210 c = READCHAR;
2212 while (c >= 0)
2214 int digit;
2216 if (c >= '0' && c <= '9')
2217 digit = c - '0';
2218 else if (c >= 'a' && c <= 'z')
2219 digit = c - 'a' + 10;
2220 else if (c >= 'A' && c <= 'Z')
2221 digit = c - 'A' + 10;
2222 else
2224 UNREAD (c);
2225 break;
2228 if (digit < 0 || digit >= radix)
2229 invalid_p = 1;
2231 number = radix * number + digit;
2232 ++ndigits;
2233 c = READCHAR;
2237 if (ndigits == 0 || invalid_p)
2239 char buf[50];
2240 sprintf (buf, "integer, radix %d", radix);
2241 invalid_syntax (buf, 0);
2244 return make_fixnum_or_float (sign * number);
2248 /* If the next token is ')' or ']' or '.', we store that character
2249 in *PCH and the return value is not interesting. Else, we store
2250 zero in *PCH and we read and return one lisp object.
2252 FIRST_IN_LIST is nonzero if this is the first element of a list. */
2254 static Lisp_Object
2255 read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2257 register int c;
2258 int uninterned_symbol = 0;
2259 int multibyte;
2261 *pch = 0;
2262 load_each_byte = 0;
2264 retry:
2266 c = READCHAR_REPORT_MULTIBYTE (&multibyte);
2267 if (c < 0)
2268 end_of_file_error ();
2270 switch (c)
2272 case '(':
2273 return read_list (0, readcharfun);
2275 case '[':
2276 return read_vector (readcharfun, 0);
2278 case ')':
2279 case ']':
2281 *pch = c;
2282 return Qnil;
2285 case '#':
2286 c = READCHAR;
2287 if (c == 's')
2289 c = READCHAR;
2290 if (c == '(')
2292 /* Accept extended format for hashtables (extensible to
2293 other types), e.g.
2294 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2295 Lisp_Object tmp = read_list (0, readcharfun);
2296 Lisp_Object head = CAR_SAFE (tmp);
2297 Lisp_Object data = Qnil;
2298 Lisp_Object val = Qnil;
2299 /* The size is 2 * number of allowed keywords to
2300 make-hash-table. */
2301 Lisp_Object params[10];
2302 Lisp_Object ht;
2303 Lisp_Object key = Qnil;
2304 int param_count = 0;
2306 if (!EQ (head, Qhash_table))
2307 error ("Invalid extended read marker at head of #s list "
2308 "(only hash-table allowed)");
2310 tmp = CDR_SAFE (tmp);
2312 /* This is repetitive but fast and simple. */
2313 params[param_count] = QCsize;
2314 params[param_count+1] = Fplist_get (tmp, Qsize);
2315 if (!NILP (params[param_count + 1]))
2316 param_count += 2;
2318 params[param_count] = QCtest;
2319 params[param_count+1] = Fplist_get (tmp, Qtest);
2320 if (!NILP (params[param_count + 1]))
2321 param_count += 2;
2323 params[param_count] = QCweakness;
2324 params[param_count+1] = Fplist_get (tmp, Qweakness);
2325 if (!NILP (params[param_count + 1]))
2326 param_count += 2;
2328 params[param_count] = QCrehash_size;
2329 params[param_count+1] = Fplist_get (tmp, Qrehash_size);
2330 if (!NILP (params[param_count + 1]))
2331 param_count += 2;
2333 params[param_count] = QCrehash_threshold;
2334 params[param_count+1] = Fplist_get (tmp, Qrehash_threshold);
2335 if (!NILP (params[param_count + 1]))
2336 param_count += 2;
2338 /* This is the hashtable data. */
2339 data = Fplist_get (tmp, Qdata);
2341 /* Now use params to make a new hashtable and fill it. */
2342 ht = Fmake_hash_table (param_count, params);
2344 while (CONSP (data))
2346 key = XCAR (data);
2347 data = XCDR (data);
2348 if (!CONSP (data))
2349 error ("Odd number of elements in hashtable data");
2350 val = XCAR (data);
2351 data = XCDR (data);
2352 Fputhash (key, val, ht);
2355 return ht;
2357 UNREAD (c);
2358 invalid_syntax ("#", 1);
2360 if (c == '^')
2362 c = READCHAR;
2363 if (c == '[')
2365 Lisp_Object tmp;
2366 tmp = read_vector (readcharfun, 0);
2367 if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS)
2368 error ("Invalid size char-table");
2369 XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE);
2370 return tmp;
2372 else if (c == '^')
2374 c = READCHAR;
2375 if (c == '[')
2377 Lisp_Object tmp;
2378 int depth, size;
2380 tmp = read_vector (readcharfun, 0);
2381 if (!INTEGERP (AREF (tmp, 0)))
2382 error ("Invalid depth in char-table");
2383 depth = XINT (AREF (tmp, 0));
2384 if (depth < 1 || depth > 3)
2385 error ("Invalid depth in char-table");
2386 size = XVECTOR (tmp)->size - 2;
2387 if (chartab_size [depth] != size)
2388 error ("Invalid size char-table");
2389 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
2390 return tmp;
2392 invalid_syntax ("#^^", 3);
2394 invalid_syntax ("#^", 2);
2396 if (c == '&')
2398 Lisp_Object length;
2399 length = read1 (readcharfun, pch, first_in_list);
2400 c = READCHAR;
2401 if (c == '"')
2403 Lisp_Object tmp, val;
2404 int size_in_chars
2405 = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2406 / BOOL_VECTOR_BITS_PER_CHAR);
2408 UNREAD (c);
2409 tmp = read1 (readcharfun, pch, first_in_list);
2410 if (STRING_MULTIBYTE (tmp)
2411 || (size_in_chars != SCHARS (tmp)
2412 /* We used to print 1 char too many
2413 when the number of bits was a multiple of 8.
2414 Accept such input in case it came from an old
2415 version. */
2416 && ! (XFASTINT (length)
2417 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
2418 invalid_syntax ("#&...", 5);
2420 val = Fmake_bool_vector (length, Qnil);
2421 memcpy (XBOOL_VECTOR (val)->data, SDATA (tmp), size_in_chars);
2422 /* Clear the extraneous bits in the last byte. */
2423 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
2424 XBOOL_VECTOR (val)->data[size_in_chars - 1]
2425 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2426 return val;
2428 invalid_syntax ("#&...", 5);
2430 if (c == '[')
2432 /* Accept compiled functions at read-time so that we don't have to
2433 build them using function calls. */
2434 Lisp_Object tmp;
2435 tmp = read_vector (readcharfun, 1);
2436 return Fmake_byte_code (XVECTOR (tmp)->size,
2437 XVECTOR (tmp)->contents);
2439 if (c == '(')
2441 Lisp_Object tmp;
2442 struct gcpro gcpro1;
2443 int ch;
2445 /* Read the string itself. */
2446 tmp = read1 (readcharfun, &ch, 0);
2447 if (ch != 0 || !STRINGP (tmp))
2448 invalid_syntax ("#", 1);
2449 GCPRO1 (tmp);
2450 /* Read the intervals and their properties. */
2451 while (1)
2453 Lisp_Object beg, end, plist;
2455 beg = read1 (readcharfun, &ch, 0);
2456 end = plist = Qnil;
2457 if (ch == ')')
2458 break;
2459 if (ch == 0)
2460 end = read1 (readcharfun, &ch, 0);
2461 if (ch == 0)
2462 plist = read1 (readcharfun, &ch, 0);
2463 if (ch)
2464 invalid_syntax ("Invalid string property list", 0);
2465 Fset_text_properties (beg, end, plist, tmp);
2467 UNGCPRO;
2468 return tmp;
2471 /* #@NUMBER is used to skip NUMBER following characters.
2472 That's used in .elc files to skip over doc strings
2473 and function definitions. */
2474 if (c == '@')
2476 int i, nskip = 0;
2478 load_each_byte = 1;
2479 /* Read a decimal integer. */
2480 while ((c = READCHAR) >= 0
2481 && c >= '0' && c <= '9')
2483 nskip *= 10;
2484 nskip += c - '0';
2486 if (c >= 0)
2487 UNREAD (c);
2489 if (load_force_doc_strings
2490 && (EQ (readcharfun, Qget_file_char)
2491 || EQ (readcharfun, Qget_emacs_mule_file_char)))
2493 /* If we are supposed to force doc strings into core right now,
2494 record the last string that we skipped,
2495 and record where in the file it comes from. */
2497 /* But first exchange saved_doc_string
2498 with prev_saved_doc_string, so we save two strings. */
2500 char *temp = saved_doc_string;
2501 int temp_size = saved_doc_string_size;
2502 file_offset temp_pos = saved_doc_string_position;
2503 int temp_len = saved_doc_string_length;
2505 saved_doc_string = prev_saved_doc_string;
2506 saved_doc_string_size = prev_saved_doc_string_size;
2507 saved_doc_string_position = prev_saved_doc_string_position;
2508 saved_doc_string_length = prev_saved_doc_string_length;
2510 prev_saved_doc_string = temp;
2511 prev_saved_doc_string_size = temp_size;
2512 prev_saved_doc_string_position = temp_pos;
2513 prev_saved_doc_string_length = temp_len;
2516 if (saved_doc_string_size == 0)
2518 saved_doc_string_size = nskip + 100;
2519 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
2521 if (nskip > saved_doc_string_size)
2523 saved_doc_string_size = nskip + 100;
2524 saved_doc_string = (char *) xrealloc (saved_doc_string,
2525 saved_doc_string_size);
2528 saved_doc_string_position = file_tell (instream);
2530 /* Copy that many characters into saved_doc_string. */
2531 for (i = 0; i < nskip && c >= 0; i++)
2532 saved_doc_string[i] = c = READCHAR;
2534 saved_doc_string_length = i;
2536 else
2538 /* Skip that many characters. */
2539 for (i = 0; i < nskip && c >= 0; i++)
2540 c = READCHAR;
2543 load_each_byte = 0;
2544 goto retry;
2546 if (c == '!')
2548 /* #! appears at the beginning of an executable file.
2549 Skip the first line. */
2550 while (c != '\n' && c >= 0)
2551 c = READCHAR;
2552 goto retry;
2554 if (c == '$')
2555 return Vload_file_name;
2556 if (c == '\'')
2557 return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
2558 /* #:foo is the uninterned symbol named foo. */
2559 if (c == ':')
2561 uninterned_symbol = 1;
2562 c = READCHAR;
2563 goto default_label;
2565 /* Reader forms that can reuse previously read objects. */
2566 if (c >= '0' && c <= '9')
2568 int n = 0;
2569 Lisp_Object tem;
2571 /* Read a non-negative integer. */
2572 while (c >= '0' && c <= '9')
2574 n *= 10;
2575 n += c - '0';
2576 c = READCHAR;
2578 /* #n=object returns object, but associates it with n for #n#. */
2579 if (c == '=' && !NILP (Vread_circle))
2581 /* Make a placeholder for #n# to use temporarily */
2582 Lisp_Object placeholder;
2583 Lisp_Object cell;
2585 placeholder = Fcons (Qnil, Qnil);
2586 cell = Fcons (make_number (n), placeholder);
2587 read_objects = Fcons (cell, read_objects);
2589 /* Read the object itself. */
2590 tem = read0 (readcharfun);
2592 /* Now put it everywhere the placeholder was... */
2593 substitute_object_in_subtree (tem, placeholder);
2595 /* ...and #n# will use the real value from now on. */
2596 Fsetcdr (cell, tem);
2598 return tem;
2600 /* #n# returns a previously read object. */
2601 if (c == '#' && !NILP (Vread_circle))
2603 tem = Fassq (make_number (n), read_objects);
2604 if (CONSP (tem))
2605 return XCDR (tem);
2606 /* Fall through to error message. */
2608 else if (c == 'r' || c == 'R')
2609 return read_integer (readcharfun, n);
2611 /* Fall through to error message. */
2613 else if (c == 'x' || c == 'X')
2614 return read_integer (readcharfun, 16);
2615 else if (c == 'o' || c == 'O')
2616 return read_integer (readcharfun, 8);
2617 else if (c == 'b' || c == 'B')
2618 return read_integer (readcharfun, 2);
2620 UNREAD (c);
2621 invalid_syntax ("#", 1);
2623 case ';':
2624 while ((c = READCHAR) >= 0 && c != '\n');
2625 goto retry;
2627 case '\'':
2629 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
2632 case '`':
2634 int next_char = READCHAR;
2635 UNREAD (next_char);
2636 /* Transition from old-style to new-style:
2637 If we see "(`" it used to mean old-style, which usually works
2638 fine because ` should almost never appear in such a position
2639 for new-style. But occasionally we need "(`" to mean new
2640 style, so we try to distinguish the two by the fact that we
2641 can either write "( `foo" or "(` foo", where the first
2642 intends to use new-style whereas the second intends to use
2643 old-style. For Emacs-25, we should completely remove this
2644 first_in_list exception (old-style can still be obtained via
2645 "(\`" anyway). */
2646 if (first_in_list && next_char == ' ')
2648 Vold_style_backquotes = Qt;
2649 goto default_label;
2651 else
2653 Lisp_Object value;
2655 new_backquote_flag++;
2656 value = read0 (readcharfun);
2657 new_backquote_flag--;
2659 return Fcons (Qbackquote, Fcons (value, Qnil));
2662 case ',':
2663 if (new_backquote_flag)
2665 Lisp_Object comma_type = Qnil;
2666 Lisp_Object value;
2667 int ch = READCHAR;
2669 if (ch == '@')
2670 comma_type = Qcomma_at;
2671 else if (ch == '.')
2672 comma_type = Qcomma_dot;
2673 else
2675 if (ch >= 0) UNREAD (ch);
2676 comma_type = Qcomma;
2679 new_backquote_flag--;
2680 value = read0 (readcharfun);
2681 new_backquote_flag++;
2682 return Fcons (comma_type, Fcons (value, Qnil));
2684 else
2686 Vold_style_backquotes = Qt;
2687 goto default_label;
2690 case '?':
2692 int modifiers;
2693 int next_char;
2694 int ok;
2696 c = READCHAR;
2697 if (c < 0)
2698 end_of_file_error ();
2700 /* Accept `single space' syntax like (list ? x) where the
2701 whitespace character is SPC or TAB.
2702 Other literal whitespace like NL, CR, and FF are not accepted,
2703 as there are well-established escape sequences for these. */
2704 if (c == ' ' || c == '\t')
2705 return make_number (c);
2707 if (c == '\\')
2708 c = read_escape (readcharfun, 0);
2709 modifiers = c & CHAR_MODIFIER_MASK;
2710 c &= ~CHAR_MODIFIER_MASK;
2711 if (CHAR_BYTE8_P (c))
2712 c = CHAR_TO_BYTE8 (c);
2713 c |= modifiers;
2715 next_char = READCHAR;
2716 if (next_char == '.')
2718 /* Only a dotted-pair dot is valid after a char constant. */
2719 int next_next_char = READCHAR;
2720 UNREAD (next_next_char);
2722 ok = (next_next_char <= 040
2723 || (next_next_char < 0200
2724 && (strchr ("\"';([#?", next_next_char)
2725 || (!first_in_list && next_next_char == '`')
2726 || (new_backquote_flag && next_next_char == ','))));
2728 else
2730 ok = (next_char <= 040
2731 || (next_char < 0200
2732 && (strchr ("\"';()[]#?", next_char)
2733 || (!first_in_list && next_char == '`')
2734 || (new_backquote_flag && next_char == ','))));
2736 UNREAD (next_char);
2737 if (ok)
2738 return make_number (c);
2740 invalid_syntax ("?", 1);
2743 case '"':
2745 char *p = read_buffer;
2746 char *end = read_buffer + read_buffer_size;
2747 register int c;
2748 /* Nonzero if we saw an escape sequence specifying
2749 a multibyte character. */
2750 int force_multibyte = 0;
2751 /* Nonzero if we saw an escape sequence specifying
2752 a single-byte character. */
2753 int force_singlebyte = 0;
2754 int cancel = 0;
2755 int nchars = 0;
2757 while ((c = READCHAR) >= 0
2758 && c != '\"')
2760 if (end - p < MAX_MULTIBYTE_LENGTH)
2762 int offset = p - read_buffer;
2763 read_buffer = (char *) xrealloc (read_buffer,
2764 read_buffer_size *= 2);
2765 p = read_buffer + offset;
2766 end = read_buffer + read_buffer_size;
2769 if (c == '\\')
2771 int modifiers;
2773 c = read_escape (readcharfun, 1);
2775 /* C is -1 if \ newline has just been seen */
2776 if (c == -1)
2778 if (p == read_buffer)
2779 cancel = 1;
2780 continue;
2783 modifiers = c & CHAR_MODIFIER_MASK;
2784 c = c & ~CHAR_MODIFIER_MASK;
2786 if (CHAR_BYTE8_P (c))
2787 force_singlebyte = 1;
2788 else if (! ASCII_CHAR_P (c))
2789 force_multibyte = 1;
2790 else /* i.e. ASCII_CHAR_P (c) */
2792 /* Allow `\C- ' and `\C-?'. */
2793 if (modifiers == CHAR_CTL)
2795 if (c == ' ')
2796 c = 0, modifiers = 0;
2797 else if (c == '?')
2798 c = 127, modifiers = 0;
2800 if (modifiers & CHAR_SHIFT)
2802 /* Shift modifier is valid only with [A-Za-z]. */
2803 if (c >= 'A' && c <= 'Z')
2804 modifiers &= ~CHAR_SHIFT;
2805 else if (c >= 'a' && c <= 'z')
2806 c -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
2809 if (modifiers & CHAR_META)
2811 /* Move the meta bit to the right place for a
2812 string. */
2813 modifiers &= ~CHAR_META;
2814 c = BYTE8_TO_CHAR (c | 0x80);
2815 force_singlebyte = 1;
2819 /* Any modifiers remaining are invalid. */
2820 if (modifiers)
2821 error ("Invalid modifier in string");
2822 p += CHAR_STRING (c, (unsigned char *) p);
2824 else
2826 p += CHAR_STRING (c, (unsigned char *) p);
2827 if (CHAR_BYTE8_P (c))
2828 force_singlebyte = 1;
2829 else if (! ASCII_CHAR_P (c))
2830 force_multibyte = 1;
2832 nchars++;
2835 if (c < 0)
2836 end_of_file_error ();
2838 /* If purifying, and string starts with \ newline,
2839 return zero instead. This is for doc strings
2840 that we are really going to find in etc/DOC.nn.nn */
2841 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
2842 return make_number (0);
2844 if (force_multibyte)
2845 /* READ_BUFFER already contains valid multibyte forms. */
2847 else if (force_singlebyte)
2849 nchars = str_as_unibyte (read_buffer, p - read_buffer);
2850 p = read_buffer + nchars;
2852 else
2853 /* Otherwise, READ_BUFFER contains only ASCII. */
2856 /* We want readchar_count to be the number of characters, not
2857 bytes. Hence we adjust for multibyte characters in the
2858 string. ... But it doesn't seem to be necessary, because
2859 READCHAR *does* read multibyte characters from buffers. */
2860 /* readchar_count -= (p - read_buffer) - nchars; */
2861 if (read_pure)
2862 return make_pure_string (read_buffer, nchars, p - read_buffer,
2863 (force_multibyte
2864 || (p - read_buffer != nchars)));
2865 return make_specified_string (read_buffer, nchars, p - read_buffer,
2866 (force_multibyte
2867 || (p - read_buffer != nchars)));
2870 case '.':
2872 int next_char = READCHAR;
2873 UNREAD (next_char);
2875 if (next_char <= 040
2876 || (next_char < 0200
2877 && (strchr ("\"';([#?", next_char)
2878 || (!first_in_list && next_char == '`')
2879 || (new_backquote_flag && next_char == ','))))
2881 *pch = c;
2882 return Qnil;
2885 /* Otherwise, we fall through! Note that the atom-reading loop
2886 below will now loop at least once, assuring that we will not
2887 try to UNREAD two characters in a row. */
2889 default:
2890 default_label:
2891 if (c <= 040) goto retry;
2892 if (c == 0x8a0) /* NBSP */
2893 goto retry;
2895 char *p = read_buffer;
2896 int quoted = 0;
2899 char *end = read_buffer + read_buffer_size;
2901 while (c > 040
2902 && c != 0x8a0 /* NBSP */
2903 && (c >= 0200
2904 || (!strchr ("\"';()[]#", c)
2905 && !(!first_in_list && c == '`')
2906 && !(new_backquote_flag && c == ','))))
2908 if (end - p < MAX_MULTIBYTE_LENGTH)
2910 int offset = p - read_buffer;
2911 read_buffer = (char *) xrealloc (read_buffer,
2912 read_buffer_size *= 2);
2913 p = read_buffer + offset;
2914 end = read_buffer + read_buffer_size;
2917 if (c == '\\')
2919 c = READCHAR;
2920 if (c == -1)
2921 end_of_file_error ();
2922 quoted = 1;
2925 if (multibyte)
2926 p += CHAR_STRING (c, p);
2927 else
2928 *p++ = c;
2929 c = READCHAR;
2932 if (p == end)
2934 int offset = p - read_buffer;
2935 read_buffer = (char *) xrealloc (read_buffer,
2936 read_buffer_size *= 2);
2937 p = read_buffer + offset;
2938 end = read_buffer + read_buffer_size;
2940 *p = 0;
2941 if (c >= 0)
2942 UNREAD (c);
2945 if (!quoted && !uninterned_symbol)
2947 register char *p1;
2948 p1 = read_buffer;
2949 if (*p1 == '+' || *p1 == '-') p1++;
2950 /* Is it an integer? */
2951 if (p1 != p)
2953 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
2954 /* Integers can have trailing decimal points. */
2955 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
2956 if (p1 == p)
2957 /* It is an integer. */
2959 if (p1[-1] == '.')
2960 p1[-1] = '\0';
2962 /* EMACS_INT n = atol (read_buffer); */
2963 char *endptr = NULL;
2964 EMACS_INT n = (errno = 0,
2965 strtol (read_buffer, &endptr, 10));
2966 if (errno == ERANGE && endptr)
2968 Lisp_Object args
2969 = Fcons (make_string (read_buffer,
2970 endptr - read_buffer),
2971 Qnil);
2972 xsignal (Qoverflow_error, args);
2974 return make_fixnum_or_float (n);
2978 if (isfloat_string (read_buffer, 0))
2980 /* Compute NaN and infinities using 0.0 in a variable,
2981 to cope with compilers that think they are smarter
2982 than we are. */
2983 double zero = 0.0;
2985 double value;
2987 /* Negate the value ourselves. This treats 0, NaNs,
2988 and infinity properly on IEEE floating point hosts,
2989 and works around a common bug where atof ("-0.0")
2990 drops the sign. */
2991 int negative = read_buffer[0] == '-';
2993 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2994 returns 1, is if the input ends in e+INF or e+NaN. */
2995 switch (p[-1])
2997 case 'F':
2998 value = 1.0 / zero;
2999 break;
3000 case 'N':
3001 value = zero / zero;
3003 /* If that made a "negative" NaN, negate it. */
3006 int i;
3007 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
3009 u_data.d = value;
3010 u_minus_zero.d = - 0.0;
3011 for (i = 0; i < sizeof (double); i++)
3012 if (u_data.c[i] & u_minus_zero.c[i])
3014 value = - value;
3015 break;
3018 /* Now VALUE is a positive NaN. */
3019 break;
3020 default:
3021 value = atof (read_buffer + negative);
3022 break;
3025 return make_float (negative ? - value : value);
3029 Lisp_Object name, result;
3030 EMACS_INT nbytes = p - read_buffer;
3031 EMACS_INT nchars
3032 = (multibyte ? multibyte_chars_in_text (read_buffer, nbytes)
3033 : nbytes);
3035 if (uninterned_symbol && ! NILP (Vpurify_flag))
3036 name = make_pure_string (read_buffer, nchars, nbytes, multibyte);
3037 else
3038 name = make_specified_string (read_buffer, nchars, nbytes,multibyte);
3039 result = (uninterned_symbol ? Fmake_symbol (name)
3040 : Fintern (name, Qnil));
3042 if (EQ (Vread_with_symbol_positions, Qt)
3043 || EQ (Vread_with_symbol_positions, readcharfun))
3044 Vread_symbol_positions_list =
3045 /* Kind of a hack; this will probably fail if characters
3046 in the symbol name were escaped. Not really a big
3047 deal, though. */
3048 Fcons (Fcons (result,
3049 make_number (readchar_count
3050 - XFASTINT (Flength (Fsymbol_name (result))))),
3051 Vread_symbol_positions_list);
3052 return result;
3059 /* List of nodes we've seen during substitute_object_in_subtree. */
3060 static Lisp_Object seen_list;
3062 static void
3063 substitute_object_in_subtree (Lisp_Object object, Lisp_Object placeholder)
3065 Lisp_Object check_object;
3067 /* We haven't seen any objects when we start. */
3068 seen_list = Qnil;
3070 /* Make all the substitutions. */
3071 check_object
3072 = substitute_object_recurse (object, placeholder, object);
3074 /* Clear seen_list because we're done with it. */
3075 seen_list = Qnil;
3077 /* The returned object here is expected to always eq the
3078 original. */
3079 if (!EQ (check_object, object))
3080 error ("Unexpected mutation error in reader");
3083 /* Feval doesn't get called from here, so no gc protection is needed. */
3084 #define SUBSTITUTE(get_val, set_val) \
3085 do { \
3086 Lisp_Object old_value = get_val; \
3087 Lisp_Object true_value \
3088 = substitute_object_recurse (object, placeholder, \
3089 old_value); \
3091 if (!EQ (old_value, true_value)) \
3093 set_val; \
3095 } while (0)
3097 static Lisp_Object
3098 substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Object subtree)
3100 /* If we find the placeholder, return the target object. */
3101 if (EQ (placeholder, subtree))
3102 return object;
3104 /* If we've been to this node before, don't explore it again. */
3105 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
3106 return subtree;
3108 /* If this node can be the entry point to a cycle, remember that
3109 we've seen it. It can only be such an entry point if it was made
3110 by #n=, which means that we can find it as a value in
3111 read_objects. */
3112 if (!EQ (Qnil, Frassq (subtree, read_objects)))
3113 seen_list = Fcons (subtree, seen_list);
3115 /* Recurse according to subtree's type.
3116 Every branch must return a Lisp_Object. */
3117 switch (XTYPE (subtree))
3119 case Lisp_Vectorlike:
3121 int i, length = 0;
3122 if (BOOL_VECTOR_P (subtree))
3123 return subtree; /* No sub-objects anyway. */
3124 else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
3125 || COMPILEDP (subtree))
3126 length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK;
3127 else if (VECTORP (subtree))
3128 length = ASIZE (subtree);
3129 else
3130 /* An unknown pseudovector may contain non-Lisp fields, so we
3131 can't just blindly traverse all its fields. We used to call
3132 `Flength' which signaled `sequencep', so I just preserved this
3133 behavior. */
3134 wrong_type_argument (Qsequencep, subtree);
3136 for (i = 0; i < length; i++)
3137 SUBSTITUTE (AREF (subtree, i),
3138 ASET (subtree, i, true_value));
3139 return subtree;
3142 case Lisp_Cons:
3144 SUBSTITUTE (XCAR (subtree),
3145 XSETCAR (subtree, true_value));
3146 SUBSTITUTE (XCDR (subtree),
3147 XSETCDR (subtree, true_value));
3148 return subtree;
3151 case Lisp_String:
3153 /* Check for text properties in each interval.
3154 substitute_in_interval contains part of the logic. */
3156 INTERVAL root_interval = STRING_INTERVALS (subtree);
3157 Lisp_Object arg = Fcons (object, placeholder);
3159 traverse_intervals_noorder (root_interval,
3160 &substitute_in_interval, arg);
3162 return subtree;
3165 /* Other types don't recurse any further. */
3166 default:
3167 return subtree;
3171 /* Helper function for substitute_object_recurse. */
3172 static void
3173 substitute_in_interval (INTERVAL interval, Lisp_Object arg)
3175 Lisp_Object object = Fcar (arg);
3176 Lisp_Object placeholder = Fcdr (arg);
3178 SUBSTITUTE (interval->plist, interval->plist = true_value);
3182 #define LEAD_INT 1
3183 #define DOT_CHAR 2
3184 #define TRAIL_INT 4
3185 #define E_CHAR 8
3186 #define EXP_INT 16
3189 isfloat_string (const char *cp, int ignore_trailing)
3191 int state;
3192 const char *start = cp;
3194 state = 0;
3195 if (*cp == '+' || *cp == '-')
3196 cp++;
3198 if (*cp >= '0' && *cp <= '9')
3200 state |= LEAD_INT;
3201 while (*cp >= '0' && *cp <= '9')
3202 cp++;
3204 if (*cp == '.')
3206 state |= DOT_CHAR;
3207 cp++;
3209 if (*cp >= '0' && *cp <= '9')
3211 state |= TRAIL_INT;
3212 while (*cp >= '0' && *cp <= '9')
3213 cp++;
3215 if (*cp == 'e' || *cp == 'E')
3217 state |= E_CHAR;
3218 cp++;
3219 if (*cp == '+' || *cp == '-')
3220 cp++;
3223 if (*cp >= '0' && *cp <= '9')
3225 state |= EXP_INT;
3226 while (*cp >= '0' && *cp <= '9')
3227 cp++;
3229 else if (cp == start)
3231 else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
3233 state |= EXP_INT;
3234 cp += 3;
3236 else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
3238 state |= EXP_INT;
3239 cp += 3;
3242 return ((ignore_trailing
3243 || *cp == 0 || *cp == ' ' || *cp == '\t' || *cp == '\n'
3244 || *cp == '\r' || *cp == '\f')
3245 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
3246 || state == (DOT_CHAR|TRAIL_INT)
3247 || state == (LEAD_INT|E_CHAR|EXP_INT)
3248 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
3249 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
3253 static Lisp_Object
3254 read_vector (Lisp_Object readcharfun, int bytecodeflag)
3256 register int i;
3257 register int size;
3258 register Lisp_Object *ptr;
3259 register Lisp_Object tem, item, vector;
3260 register struct Lisp_Cons *otem;
3261 Lisp_Object len;
3263 tem = read_list (1, readcharfun);
3264 len = Flength (tem);
3265 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
3267 size = XVECTOR (vector)->size;
3268 ptr = XVECTOR (vector)->contents;
3269 for (i = 0; i < size; i++)
3271 item = Fcar (tem);
3272 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3273 bytecode object, the docstring containing the bytecode and
3274 constants values must be treated as unibyte and passed to
3275 Fread, to get the actual bytecode string and constants vector. */
3276 if (bytecodeflag && load_force_doc_strings)
3278 if (i == COMPILED_BYTECODE)
3280 if (!STRINGP (item))
3281 error ("Invalid byte code");
3283 /* Delay handling the bytecode slot until we know whether
3284 it is lazily-loaded (we can tell by whether the
3285 constants slot is nil). */
3286 ptr[COMPILED_CONSTANTS] = item;
3287 item = Qnil;
3289 else if (i == COMPILED_CONSTANTS)
3291 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
3293 if (NILP (item))
3295 /* Coerce string to unibyte (like string-as-unibyte,
3296 but without generating extra garbage and
3297 guaranteeing no change in the contents). */
3298 STRING_SET_CHARS (bytestr, SBYTES (bytestr));
3299 STRING_SET_UNIBYTE (bytestr);
3301 item = Fread (Fcons (bytestr, readcharfun));
3302 if (!CONSP (item))
3303 error ("Invalid byte code");
3305 otem = XCONS (item);
3306 bytestr = XCAR (item);
3307 item = XCDR (item);
3308 free_cons (otem);
3311 /* Now handle the bytecode slot. */
3312 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
3314 else if (i == COMPILED_DOC_STRING
3315 && STRINGP (item)
3316 && ! STRING_MULTIBYTE (item))
3318 if (EQ (readcharfun, Qget_emacs_mule_file_char))
3319 item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil);
3320 else
3321 item = Fstring_as_multibyte (item);
3324 ptr[i] = read_pure ? Fpurecopy (item) : item;
3325 otem = XCONS (tem);
3326 tem = Fcdr (tem);
3327 free_cons (otem);
3329 return vector;
3332 /* FLAG = 1 means check for ] to terminate rather than ) and .
3333 FLAG = -1 means check for starting with defun
3334 and make structure pure. */
3336 static Lisp_Object
3337 read_list (int flag, register Lisp_Object readcharfun)
3339 /* -1 means check next element for defun,
3340 0 means don't check,
3341 1 means already checked and found defun. */
3342 int defunflag = flag < 0 ? -1 : 0;
3343 Lisp_Object val, tail;
3344 register Lisp_Object elt, tem;
3345 struct gcpro gcpro1, gcpro2;
3346 /* 0 is the normal case.
3347 1 means this list is a doc reference; replace it with the number 0.
3348 2 means this list is a doc reference; replace it with the doc string. */
3349 int doc_reference = 0;
3351 /* Initialize this to 1 if we are reading a list. */
3352 int first_in_list = flag <= 0;
3354 val = Qnil;
3355 tail = Qnil;
3357 while (1)
3359 int ch;
3360 GCPRO2 (val, tail);
3361 elt = read1 (readcharfun, &ch, first_in_list);
3362 UNGCPRO;
3364 first_in_list = 0;
3366 /* While building, if the list starts with #$, treat it specially. */
3367 if (EQ (elt, Vload_file_name)
3368 && ! NILP (elt)
3369 && !NILP (Vpurify_flag))
3371 if (NILP (Vdoc_file_name))
3372 /* We have not yet called Snarf-documentation, so assume
3373 this file is described in the DOC-MM.NN file
3374 and Snarf-documentation will fill in the right value later.
3375 For now, replace the whole list with 0. */
3376 doc_reference = 1;
3377 else
3378 /* We have already called Snarf-documentation, so make a relative
3379 file name for this file, so it can be found properly
3380 in the installed Lisp directory.
3381 We don't use Fexpand_file_name because that would make
3382 the directory absolute now. */
3383 elt = concat2 (build_string ("../lisp/"),
3384 Ffile_name_nondirectory (elt));
3386 else if (EQ (elt, Vload_file_name)
3387 && ! NILP (elt)
3388 && load_force_doc_strings)
3389 doc_reference = 2;
3391 if (ch)
3393 if (flag > 0)
3395 if (ch == ']')
3396 return val;
3397 invalid_syntax (") or . in a vector", 18);
3399 if (ch == ')')
3400 return val;
3401 if (ch == '.')
3403 GCPRO2 (val, tail);
3404 if (!NILP (tail))
3405 XSETCDR (tail, read0 (readcharfun));
3406 else
3407 val = read0 (readcharfun);
3408 read1 (readcharfun, &ch, 0);
3409 UNGCPRO;
3410 if (ch == ')')
3412 if (doc_reference == 1)
3413 return make_number (0);
3414 if (doc_reference == 2)
3416 /* Get a doc string from the file we are loading.
3417 If it's in saved_doc_string, get it from there.
3419 Here, we don't know if the string is a
3420 bytecode string or a doc string. As a
3421 bytecode string must be unibyte, we always
3422 return a unibyte string. If it is actually a
3423 doc string, caller must make it
3424 multibyte. */
3426 int pos = XINT (XCDR (val));
3427 /* Position is negative for user variables. */
3428 if (pos < 0) pos = -pos;
3429 if (pos >= saved_doc_string_position
3430 && pos < (saved_doc_string_position
3431 + saved_doc_string_length))
3433 int start = pos - saved_doc_string_position;
3434 int from, to;
3436 /* Process quoting with ^A,
3437 and find the end of the string,
3438 which is marked with ^_ (037). */
3439 for (from = start, to = start;
3440 saved_doc_string[from] != 037;)
3442 int c = saved_doc_string[from++];
3443 if (c == 1)
3445 c = saved_doc_string[from++];
3446 if (c == 1)
3447 saved_doc_string[to++] = c;
3448 else if (c == '0')
3449 saved_doc_string[to++] = 0;
3450 else if (c == '_')
3451 saved_doc_string[to++] = 037;
3453 else
3454 saved_doc_string[to++] = c;
3457 return make_unibyte_string (saved_doc_string + start,
3458 to - start);
3460 /* Look in prev_saved_doc_string the same way. */
3461 else if (pos >= prev_saved_doc_string_position
3462 && pos < (prev_saved_doc_string_position
3463 + prev_saved_doc_string_length))
3465 int start = pos - prev_saved_doc_string_position;
3466 int from, to;
3468 /* Process quoting with ^A,
3469 and find the end of the string,
3470 which is marked with ^_ (037). */
3471 for (from = start, to = start;
3472 prev_saved_doc_string[from] != 037;)
3474 int c = prev_saved_doc_string[from++];
3475 if (c == 1)
3477 c = prev_saved_doc_string[from++];
3478 if (c == 1)
3479 prev_saved_doc_string[to++] = c;
3480 else if (c == '0')
3481 prev_saved_doc_string[to++] = 0;
3482 else if (c == '_')
3483 prev_saved_doc_string[to++] = 037;
3485 else
3486 prev_saved_doc_string[to++] = c;
3489 return make_unibyte_string (prev_saved_doc_string
3490 + start,
3491 to - start);
3493 else
3494 return get_doc_string (val, 1, 0);
3497 return val;
3499 invalid_syntax (". in wrong context", 18);
3501 invalid_syntax ("] in a list", 11);
3503 tem = (read_pure && flag <= 0
3504 ? pure_cons (elt, Qnil)
3505 : Fcons (elt, Qnil));
3506 if (!NILP (tail))
3507 XSETCDR (tail, tem);
3508 else
3509 val = tem;
3510 tail = tem;
3511 if (defunflag < 0)
3512 defunflag = EQ (elt, Qdefun);
3513 else if (defunflag > 0)
3514 read_pure = 1;
3518 Lisp_Object Vobarray;
3519 Lisp_Object initial_obarray;
3521 /* oblookup stores the bucket number here, for the sake of Funintern. */
3523 int oblookup_last_bucket_number;
3525 static int hash_string (const unsigned char *ptr, int len);
3527 /* Get an error if OBARRAY is not an obarray.
3528 If it is one, return it. */
3530 Lisp_Object
3531 check_obarray (Lisp_Object obarray)
3533 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3535 /* If Vobarray is now invalid, force it to be valid. */
3536 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
3537 wrong_type_argument (Qvectorp, obarray);
3539 return obarray;
3542 /* Intern the C string STR: return a symbol with that name,
3543 interned in the current obarray. */
3545 Lisp_Object
3546 intern (const char *str)
3548 Lisp_Object tem;
3549 int len = strlen (str);
3550 Lisp_Object obarray;
3552 obarray = Vobarray;
3553 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3554 obarray = check_obarray (obarray);
3555 tem = oblookup (obarray, str, len, len);
3556 if (SYMBOLP (tem))
3557 return tem;
3558 return Fintern (make_string (str, len), obarray);
3561 Lisp_Object
3562 intern_c_string (const char *str)
3564 Lisp_Object tem;
3565 int len = strlen (str);
3566 Lisp_Object obarray;
3568 obarray = Vobarray;
3569 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3570 obarray = check_obarray (obarray);
3571 tem = oblookup (obarray, str, len, len);
3572 if (SYMBOLP (tem))
3573 return tem;
3575 if (NILP (Vpurify_flag))
3576 /* Creating a non-pure string from a string literal not
3577 implemented yet. We could just use make_string here and live
3578 with the extra copy. */
3579 abort ();
3581 return Fintern (make_pure_c_string (str), obarray);
3584 /* Create an uninterned symbol with name STR. */
3586 Lisp_Object
3587 make_symbol (const char *str)
3589 int len = strlen (str);
3591 return Fmake_symbol (!NILP (Vpurify_flag)
3592 ? make_pure_string (str, len, len, 0)
3593 : make_string (str, len));
3596 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
3597 doc: /* Return the canonical symbol whose name is STRING.
3598 If there is none, one is created by this function and returned.
3599 A second optional argument specifies the obarray to use;
3600 it defaults to the value of `obarray'. */)
3601 (Lisp_Object string, Lisp_Object obarray)
3603 register Lisp_Object tem, sym, *ptr;
3605 if (NILP (obarray)) obarray = Vobarray;
3606 obarray = check_obarray (obarray);
3608 CHECK_STRING (string);
3610 tem = oblookup (obarray, SDATA (string),
3611 SCHARS (string),
3612 SBYTES (string));
3613 if (!INTEGERP (tem))
3614 return tem;
3616 if (!NILP (Vpurify_flag))
3617 string = Fpurecopy (string);
3618 sym = Fmake_symbol (string);
3620 if (EQ (obarray, initial_obarray))
3621 XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3622 else
3623 XSYMBOL (sym)->interned = SYMBOL_INTERNED;
3625 if ((SREF (string, 0) == ':')
3626 && EQ (obarray, initial_obarray))
3628 XSYMBOL (sym)->constant = 1;
3629 XSYMBOL (sym)->redirect = SYMBOL_PLAINVAL;
3630 SET_SYMBOL_VAL (XSYMBOL (sym), sym);
3633 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
3634 if (SYMBOLP (*ptr))
3635 XSYMBOL (sym)->next = XSYMBOL (*ptr);
3636 else
3637 XSYMBOL (sym)->next = 0;
3638 *ptr = sym;
3639 return sym;
3642 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
3643 doc: /* Return the canonical symbol named NAME, or nil if none exists.
3644 NAME may be a string or a symbol. If it is a symbol, that exact
3645 symbol is searched for.
3646 A second optional argument specifies the obarray to use;
3647 it defaults to the value of `obarray'. */)
3648 (Lisp_Object name, Lisp_Object obarray)
3650 register Lisp_Object tem, string;
3652 if (NILP (obarray)) obarray = Vobarray;
3653 obarray = check_obarray (obarray);
3655 if (!SYMBOLP (name))
3657 CHECK_STRING (name);
3658 string = name;
3660 else
3661 string = SYMBOL_NAME (name);
3663 tem = oblookup (obarray, SDATA (string), SCHARS (string), SBYTES (string));
3664 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
3665 return Qnil;
3666 else
3667 return tem;
3670 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
3671 doc: /* Delete the symbol named NAME, if any, from OBARRAY.
3672 The value is t if a symbol was found and deleted, nil otherwise.
3673 NAME may be a string or a symbol. If it is a symbol, that symbol
3674 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3675 OBARRAY defaults to the value of the variable `obarray'. */)
3676 (Lisp_Object name, Lisp_Object obarray)
3678 register Lisp_Object string, tem;
3679 int hash;
3681 if (NILP (obarray)) obarray = Vobarray;
3682 obarray = check_obarray (obarray);
3684 if (SYMBOLP (name))
3685 string = SYMBOL_NAME (name);
3686 else
3688 CHECK_STRING (name);
3689 string = name;
3692 tem = oblookup (obarray, SDATA (string),
3693 SCHARS (string),
3694 SBYTES (string));
3695 if (INTEGERP (tem))
3696 return Qnil;
3697 /* If arg was a symbol, don't delete anything but that symbol itself. */
3698 if (SYMBOLP (name) && !EQ (name, tem))
3699 return Qnil;
3701 /* There are plenty of other symbols which will screw up the Emacs
3702 session if we unintern them, as well as even more ways to use
3703 `setq' or `fset' or whatnot to make the Emacs session
3704 unusable. Let's not go down this silly road. --Stef */
3705 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
3706 error ("Attempt to unintern t or nil"); */
3708 XSYMBOL (tem)->interned = SYMBOL_UNINTERNED;
3710 hash = oblookup_last_bucket_number;
3712 if (EQ (XVECTOR (obarray)->contents[hash], tem))
3714 if (XSYMBOL (tem)->next)
3715 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
3716 else
3717 XSETINT (XVECTOR (obarray)->contents[hash], 0);
3719 else
3721 Lisp_Object tail, following;
3723 for (tail = XVECTOR (obarray)->contents[hash];
3724 XSYMBOL (tail)->next;
3725 tail = following)
3727 XSETSYMBOL (following, XSYMBOL (tail)->next);
3728 if (EQ (following, tem))
3730 XSYMBOL (tail)->next = XSYMBOL (following)->next;
3731 break;
3736 return Qt;
3739 /* Return the symbol in OBARRAY whose names matches the string
3740 of SIZE characters (SIZE_BYTE bytes) at PTR.
3741 If there is no such symbol in OBARRAY, return nil.
3743 Also store the bucket number in oblookup_last_bucket_number. */
3745 Lisp_Object
3746 oblookup (Lisp_Object obarray, register const char *ptr, int size, int size_byte)
3748 int hash;
3749 int obsize;
3750 register Lisp_Object tail;
3751 Lisp_Object bucket, tem;
3753 if (!VECTORP (obarray)
3754 || (obsize = XVECTOR (obarray)->size) == 0)
3756 obarray = check_obarray (obarray);
3757 obsize = XVECTOR (obarray)->size;
3759 /* This is sometimes needed in the middle of GC. */
3760 obsize &= ~ARRAY_MARK_FLAG;
3761 hash = hash_string (ptr, size_byte) % obsize;
3762 bucket = XVECTOR (obarray)->contents[hash];
3763 oblookup_last_bucket_number = hash;
3764 if (EQ (bucket, make_number (0)))
3766 else if (!SYMBOLP (bucket))
3767 error ("Bad data in guts of obarray"); /* Like CADR error message */
3768 else
3769 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
3771 if (SBYTES (SYMBOL_NAME (tail)) == size_byte
3772 && SCHARS (SYMBOL_NAME (tail)) == size
3773 && !memcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
3774 return tail;
3775 else if (XSYMBOL (tail)->next == 0)
3776 break;
3778 XSETINT (tem, hash);
3779 return tem;
3782 static int
3783 hash_string (const unsigned char *ptr, int len)
3785 register const unsigned char *p = ptr;
3786 register const unsigned char *end = p + len;
3787 register unsigned char c;
3788 register int hash = 0;
3790 while (p != end)
3792 c = *p++;
3793 if (c >= 0140) c -= 40;
3794 hash = ((hash<<3) + (hash>>28) + c);
3796 return hash & 07777777777;
3799 void
3800 map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg)
3802 register int i;
3803 register Lisp_Object tail;
3804 CHECK_VECTOR (obarray);
3805 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
3807 tail = XVECTOR (obarray)->contents[i];
3808 if (SYMBOLP (tail))
3809 while (1)
3811 (*fn) (tail, arg);
3812 if (XSYMBOL (tail)->next == 0)
3813 break;
3814 XSETSYMBOL (tail, XSYMBOL (tail)->next);
3819 static void
3820 mapatoms_1 (Lisp_Object sym, Lisp_Object function)
3822 call1 (function, sym);
3825 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
3826 doc: /* Call FUNCTION on every symbol in OBARRAY.
3827 OBARRAY defaults to the value of `obarray'. */)
3828 (Lisp_Object function, Lisp_Object obarray)
3830 if (NILP (obarray)) obarray = Vobarray;
3831 obarray = check_obarray (obarray);
3833 map_obarray (obarray, mapatoms_1, function);
3834 return Qnil;
3837 #define OBARRAY_SIZE 1511
3839 void
3840 init_obarray (void)
3842 Lisp_Object oblength;
3844 XSETFASTINT (oblength, OBARRAY_SIZE);
3846 Vobarray = Fmake_vector (oblength, make_number (0));
3847 initial_obarray = Vobarray;
3848 staticpro (&initial_obarray);
3850 Qunbound = Fmake_symbol (make_pure_c_string ("unbound"));
3851 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the
3852 NILP (Vpurify_flag) check in intern_c_string. */
3853 Qnil = make_number (-1); Vpurify_flag = make_number (1);
3854 Qnil = intern_c_string ("nil");
3856 /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil,
3857 so those two need to be fixed manally. */
3858 SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound);
3859 XSYMBOL (Qunbound)->function = Qunbound;
3860 XSYMBOL (Qunbound)->plist = Qnil;
3861 /* XSYMBOL (Qnil)->function = Qunbound; */
3862 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil);
3863 XSYMBOL (Qnil)->constant = 1;
3864 XSYMBOL (Qnil)->plist = Qnil;
3866 Qt = intern_c_string ("t");
3867 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt);
3868 XSYMBOL (Qt)->constant = 1;
3870 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3871 Vpurify_flag = Qt;
3873 Qvariable_documentation = intern_c_string ("variable-documentation");
3874 staticpro (&Qvariable_documentation);
3876 read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
3877 read_buffer = (char *) xmalloc (read_buffer_size);
3880 void
3881 defsubr (struct Lisp_Subr *sname)
3883 Lisp_Object sym;
3884 sym = intern_c_string (sname->symbol_name);
3885 XSETPVECTYPE (sname, PVEC_SUBR);
3886 XSETSUBR (XSYMBOL (sym)->function, sname);
3889 #ifdef NOTDEF /* use fset in subr.el now */
3890 void
3891 defalias (sname, string)
3892 struct Lisp_Subr *sname;
3893 char *string;
3895 Lisp_Object sym;
3896 sym = intern (string);
3897 XSETSUBR (XSYMBOL (sym)->function, sname);
3899 #endif /* NOTDEF */
3901 /* Define an "integer variable"; a symbol whose value is forwarded
3902 to a C variable of type int. Sample call:
3903 DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
3904 void
3905 defvar_int (struct Lisp_Intfwd *i_fwd,
3906 const char *namestring, EMACS_INT *address)
3908 Lisp_Object sym;
3909 sym = intern_c_string (namestring);
3910 i_fwd->type = Lisp_Fwd_Int;
3911 i_fwd->intvar = address;
3912 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3913 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)i_fwd);
3916 /* Similar but define a variable whose value is t if address contains 1,
3917 nil if address contains 0. */
3918 void
3919 defvar_bool (struct Lisp_Boolfwd *b_fwd,
3920 const char *namestring, int *address)
3922 Lisp_Object sym;
3923 sym = intern_c_string (namestring);
3924 b_fwd->type = Lisp_Fwd_Bool;
3925 b_fwd->boolvar = address;
3926 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3927 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)b_fwd);
3928 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
3931 /* Similar but define a variable whose value is the Lisp Object stored
3932 at address. Two versions: with and without gc-marking of the C
3933 variable. The nopro version is used when that variable will be
3934 gc-marked for some other reason, since marking the same slot twice
3935 can cause trouble with strings. */
3936 void
3937 defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd,
3938 const char *namestring, Lisp_Object *address)
3940 Lisp_Object sym;
3941 sym = intern_c_string (namestring);
3942 o_fwd->type = Lisp_Fwd_Obj;
3943 o_fwd->objvar = address;
3944 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3945 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)o_fwd);
3948 void
3949 defvar_lisp (struct Lisp_Objfwd *o_fwd,
3950 const char *namestring, Lisp_Object *address)
3952 defvar_lisp_nopro (o_fwd, namestring, address);
3953 staticpro (address);
3956 /* Similar but define a variable whose value is the Lisp Object stored
3957 at a particular offset in the current kboard object. */
3959 void
3960 defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd,
3961 const char *namestring, int offset)
3963 Lisp_Object sym;
3964 sym = intern_c_string (namestring);
3965 ko_fwd->type = Lisp_Fwd_Kboard_Obj;
3966 ko_fwd->offset = offset;
3967 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3968 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd);
3971 /* Record the value of load-path used at the start of dumping
3972 so we can see if the site changed it later during dumping. */
3973 static Lisp_Object dump_path;
3975 void
3976 init_lread (void)
3978 char *normal;
3979 int turn_off_warning = 0;
3981 /* Compute the default load-path. */
3982 #ifdef CANNOT_DUMP
3983 normal = PATH_LOADSEARCH;
3984 Vload_path = decode_env_path (0, normal);
3985 #else
3986 if (NILP (Vpurify_flag))
3987 normal = PATH_LOADSEARCH;
3988 else
3989 normal = PATH_DUMPLOADSEARCH;
3991 /* In a dumped Emacs, we normally have to reset the value of
3992 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3993 uses ../lisp, instead of the path of the installed elisp
3994 libraries. However, if it appears that Vload_path was changed
3995 from the default before dumping, don't override that value. */
3996 if (initialized)
3998 if (! NILP (Fequal (dump_path, Vload_path)))
4000 Vload_path = decode_env_path (0, normal);
4001 if (!NILP (Vinstallation_directory))
4003 Lisp_Object tem, tem1, sitelisp;
4005 /* Remove site-lisp dirs from path temporarily and store
4006 them in sitelisp, then conc them on at the end so
4007 they're always first in path. */
4008 sitelisp = Qnil;
4009 while (1)
4011 tem = Fcar (Vload_path);
4012 tem1 = Fstring_match (build_string ("site-lisp"),
4013 tem, Qnil);
4014 if (!NILP (tem1))
4016 Vload_path = Fcdr (Vload_path);
4017 sitelisp = Fcons (tem, sitelisp);
4019 else
4020 break;
4023 /* Add to the path the lisp subdir of the
4024 installation dir, if it exists. */
4025 tem = Fexpand_file_name (build_string ("lisp"),
4026 Vinstallation_directory);
4027 tem1 = Ffile_exists_p (tem);
4028 if (!NILP (tem1))
4030 if (NILP (Fmember (tem, Vload_path)))
4032 turn_off_warning = 1;
4033 Vload_path = Fcons (tem, Vload_path);
4036 else
4037 /* That dir doesn't exist, so add the build-time
4038 Lisp dirs instead. */
4039 Vload_path = nconc2 (Vload_path, dump_path);
4041 /* Add leim under the installation dir, if it exists. */
4042 tem = Fexpand_file_name (build_string ("leim"),
4043 Vinstallation_directory);
4044 tem1 = Ffile_exists_p (tem);
4045 if (!NILP (tem1))
4047 if (NILP (Fmember (tem, Vload_path)))
4048 Vload_path = Fcons (tem, Vload_path);
4051 /* Add site-lisp under the installation dir, if it exists. */
4052 tem = Fexpand_file_name (build_string ("site-lisp"),
4053 Vinstallation_directory);
4054 tem1 = Ffile_exists_p (tem);
4055 if (!NILP (tem1))
4057 if (NILP (Fmember (tem, Vload_path)))
4058 Vload_path = Fcons (tem, Vload_path);
4061 /* If Emacs was not built in the source directory,
4062 and it is run from where it was built, add to load-path
4063 the lisp, leim and site-lisp dirs under that directory. */
4065 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
4067 Lisp_Object tem2;
4069 tem = Fexpand_file_name (build_string ("src/Makefile"),
4070 Vinstallation_directory);
4071 tem1 = Ffile_exists_p (tem);
4073 /* Don't be fooled if they moved the entire source tree
4074 AFTER dumping Emacs. If the build directory is indeed
4075 different from the source dir, src/Makefile.in and
4076 src/Makefile will not be found together. */
4077 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
4078 Vinstallation_directory);
4079 tem2 = Ffile_exists_p (tem);
4080 if (!NILP (tem1) && NILP (tem2))
4082 tem = Fexpand_file_name (build_string ("lisp"),
4083 Vsource_directory);
4085 if (NILP (Fmember (tem, Vload_path)))
4086 Vload_path = Fcons (tem, Vload_path);
4088 tem = Fexpand_file_name (build_string ("leim"),
4089 Vsource_directory);
4091 if (NILP (Fmember (tem, Vload_path)))
4092 Vload_path = Fcons (tem, Vload_path);
4094 tem = Fexpand_file_name (build_string ("site-lisp"),
4095 Vsource_directory);
4097 if (NILP (Fmember (tem, Vload_path)))
4098 Vload_path = Fcons (tem, Vload_path);
4101 if (!NILP (sitelisp))
4102 Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path);
4106 else
4108 /* NORMAL refers to the lisp dir in the source directory. */
4109 /* We used to add ../lisp at the front here, but
4110 that caused trouble because it was copied from dump_path
4111 into Vload_path, above, when Vinstallation_directory was non-nil.
4112 It should be unnecessary. */
4113 Vload_path = decode_env_path (0, normal);
4114 dump_path = Vload_path;
4116 #endif
4118 #if (!(defined (WINDOWSNT) || (defined (HAVE_NS))))
4119 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
4120 almost never correct, thereby causing a warning to be printed out that
4121 confuses users. Since PATH_LOADSEARCH is always overridden by the
4122 EMACSLOADPATH environment variable below, disable the warning on NT. */
4124 /* Warn if dirs in the *standard* path don't exist. */
4125 if (!turn_off_warning)
4127 Lisp_Object path_tail;
4129 for (path_tail = Vload_path;
4130 !NILP (path_tail);
4131 path_tail = XCDR (path_tail))
4133 Lisp_Object dirfile;
4134 dirfile = Fcar (path_tail);
4135 if (STRINGP (dirfile))
4137 dirfile = Fdirectory_file_name (dirfile);
4138 if (access (SDATA (dirfile), 0) < 0)
4139 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4140 XCAR (path_tail));
4144 #endif /* !(WINDOWSNT || HAVE_NS) */
4146 /* If the EMACSLOADPATH environment variable is set, use its value.
4147 This doesn't apply if we're dumping. */
4148 #ifndef CANNOT_DUMP
4149 if (NILP (Vpurify_flag)
4150 && egetenv ("EMACSLOADPATH"))
4151 #endif
4152 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4154 Vvalues = Qnil;
4156 load_in_progress = 0;
4157 Vload_file_name = Qnil;
4159 load_descriptor_list = Qnil;
4161 Vstandard_input = Qt;
4162 Vloads_in_progress = Qnil;
4165 /* Print a warning, using format string FORMAT, that directory DIRNAME
4166 does not exist. Print it on stderr and put it in *Messages*. */
4168 void
4169 dir_warning (const char *format, Lisp_Object dirname)
4171 char *buffer
4172 = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);
4174 fprintf (stderr, format, SDATA (dirname));
4175 sprintf (buffer, format, SDATA (dirname));
4176 /* Don't log the warning before we've initialized!! */
4177 if (initialized)
4178 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
4181 void
4182 syms_of_lread (void)
4184 defsubr (&Sread);
4185 defsubr (&Sread_from_string);
4186 defsubr (&Sintern);
4187 defsubr (&Sintern_soft);
4188 defsubr (&Sunintern);
4189 defsubr (&Sget_load_suffixes);
4190 defsubr (&Sload);
4191 defsubr (&Seval_buffer);
4192 defsubr (&Seval_region);
4193 defsubr (&Sread_char);
4194 defsubr (&Sread_char_exclusive);
4195 defsubr (&Sread_event);
4196 defsubr (&Sget_file_char);
4197 defsubr (&Smapatoms);
4198 defsubr (&Slocate_file_internal);
4200 DEFVAR_LISP ("obarray", &Vobarray,
4201 doc: /* Symbol table for use by `intern' and `read'.
4202 It is a vector whose length ought to be prime for best results.
4203 The vector's contents don't make sense if examined from Lisp programs;
4204 to find all the symbols in an obarray, use `mapatoms'. */);
4206 DEFVAR_LISP ("values", &Vvalues,
4207 doc: /* List of values of all expressions which were read, evaluated and printed.
4208 Order is reverse chronological. */);
4210 DEFVAR_LISP ("standard-input", &Vstandard_input,
4211 doc: /* Stream for read to get input from.
4212 See documentation of `read' for possible values. */);
4213 Vstandard_input = Qt;
4215 DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions,
4216 doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4218 If this variable is a buffer, then only forms read from that buffer
4219 will be added to `read-symbol-positions-list'.
4220 If this variable is t, then all read forms will be added.
4221 The effect of all other values other than nil are not currently
4222 defined, although they may be in the future.
4224 The positions are relative to the last call to `read' or
4225 `read-from-string'. It is probably a bad idea to set this variable at
4226 the toplevel; bind it instead. */);
4227 Vread_with_symbol_positions = Qnil;
4229 DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list,
4230 doc: /* A list mapping read symbols to their positions.
4231 This variable is modified during calls to `read' or
4232 `read-from-string', but only when `read-with-symbol-positions' is
4233 non-nil.
4235 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4236 CHAR-POSITION is an integer giving the offset of that occurrence of the
4237 symbol from the position where `read' or `read-from-string' started.
4239 Note that a symbol will appear multiple times in this list, if it was
4240 read multiple times. The list is in the same order as the symbols
4241 were read in. */);
4242 Vread_symbol_positions_list = Qnil;
4244 DEFVAR_LISP ("read-circle", &Vread_circle,
4245 doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4246 Vread_circle = Qt;
4248 DEFVAR_LISP ("load-path", &Vload_path,
4249 doc: /* *List of directories to search for files to load.
4250 Each element is a string (directory name) or nil (try default directory).
4251 Initialized based on EMACSLOADPATH environment variable, if any,
4252 otherwise to default specified by file `epaths.h' when Emacs was built. */);
4254 DEFVAR_LISP ("load-suffixes", &Vload_suffixes,
4255 doc: /* List of suffixes for (compiled or source) Emacs Lisp files.
4256 This list should not include the empty string.
4257 `load' and related functions try to append these suffixes, in order,
4258 to the specified file name if a Lisp suffix is allowed or required. */);
4259 Vload_suffixes = Fcons (make_pure_c_string (".elc"),
4260 Fcons (make_pure_c_string (".el"), Qnil));
4261 DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes,
4262 doc: /* List of suffixes that indicate representations of \
4263 the same file.
4264 This list should normally start with the empty string.
4266 Enabling Auto Compression mode appends the suffixes in
4267 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4268 mode removes them again. `load' and related functions use this list to
4269 determine whether they should look for compressed versions of a file
4270 and, if so, which suffixes they should try to append to the file name
4271 in order to do so. However, if you want to customize which suffixes
4272 the loading functions recognize as compression suffixes, you should
4273 customize `jka-compr-load-suffixes' rather than the present variable. */);
4274 Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil);
4276 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
4277 doc: /* Non-nil if inside of `load'. */);
4278 Qload_in_progress = intern_c_string ("load-in-progress");
4279 staticpro (&Qload_in_progress);
4281 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
4282 doc: /* An alist of expressions to be evalled when particular files are loaded.
4283 Each element looks like (REGEXP-OR-FEATURE FORMS...).
4285 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4286 a symbol \(a feature name).
4288 When `load' is run and the file-name argument matches an element's
4289 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4290 REGEXP-OR-FEATURE, the FORMS in the element are executed.
4292 An error in FORMS does not undo the load, but does prevent execution of
4293 the rest of the FORMS. */);
4294 Vafter_load_alist = Qnil;
4296 DEFVAR_LISP ("load-history", &Vload_history,
4297 doc: /* Alist mapping loaded file names to symbols and features.
4298 Each alist element should be a list (FILE-NAME ENTRIES...), where
4299 FILE-NAME is the name of a file that has been loaded into Emacs.
4300 The file name is absolute and true (i.e. it doesn't contain symlinks).
4301 As an exception, one of the alist elements may have FILE-NAME nil,
4302 for symbols and features not associated with any file.
4304 The remaining ENTRIES in the alist element describe the functions and
4305 variables defined in that file, the features provided, and the
4306 features required. Each entry has the form `(provide . FEATURE)',
4307 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4308 `(defface . SYMBOL)', or `(t . SYMBOL)'. In addition, an entry `(t
4309 . SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
4310 SYMBOL was an autoload before this file redefined it as a function.
4312 During preloading, the file name recorded is relative to the main Lisp
4313 directory. These file names are converted to absolute at startup. */);
4314 Vload_history = Qnil;
4316 DEFVAR_LISP ("load-file-name", &Vload_file_name,
4317 doc: /* Full name of file being loaded by `load'. */);
4318 Vload_file_name = Qnil;
4320 DEFVAR_LISP ("user-init-file", &Vuser_init_file,
4321 doc: /* File name, including directory, of user's initialization file.
4322 If the file loaded had extension `.elc', and the corresponding source file
4323 exists, this variable contains the name of source file, suitable for use
4324 by functions like `custom-save-all' which edit the init file.
4325 While Emacs loads and evaluates the init file, value is the real name
4326 of the file, regardless of whether or not it has the `.elc' extension. */);
4327 Vuser_init_file = Qnil;
4329 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
4330 doc: /* Used for internal purposes by `load'. */);
4331 Vcurrent_load_list = Qnil;
4333 DEFVAR_LISP ("load-read-function", &Vload_read_function,
4334 doc: /* Function used by `load' and `eval-region' for reading expressions.
4335 The default is nil, which means use the function `read'. */);
4336 Vload_read_function = Qnil;
4338 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
4339 doc: /* Function called in `load' for loading an Emacs Lisp source file.
4340 This function is for doing code conversion before reading the source file.
4341 If nil, loading is done without any code conversion.
4342 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
4343 FULLNAME is the full name of FILE.
4344 See `load' for the meaning of the remaining arguments. */);
4345 Vload_source_file_function = Qnil;
4347 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
4348 doc: /* Non-nil means `load' should force-load all dynamic doc strings.
4349 This is useful when the file being loaded is a temporary copy. */);
4350 load_force_doc_strings = 0;
4352 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
4353 doc: /* Non-nil means `read' converts strings to unibyte whenever possible.
4354 This is normally bound by `load' and `eval-buffer' to control `read',
4355 and is not meant for users to change. */);
4356 load_convert_to_unibyte = 0;
4358 DEFVAR_LISP ("source-directory", &Vsource_directory,
4359 doc: /* Directory in which Emacs sources were found when Emacs was built.
4360 You cannot count on them to still be there! */);
4361 Vsource_directory
4362 = Fexpand_file_name (build_string ("../"),
4363 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
4365 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
4366 doc: /* List of files that were preloaded (when dumping Emacs). */);
4367 Vpreloaded_file_list = Qnil;
4369 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
4370 doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4371 Vbyte_boolean_vars = Qnil;
4373 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries,
4374 doc: /* Non-nil means load dangerous compiled Lisp files.
4375 Some versions of XEmacs use different byte codes than Emacs. These
4376 incompatible byte codes can make Emacs crash when it tries to execute
4377 them. */);
4378 load_dangerous_libraries = 0;
4380 DEFVAR_BOOL ("force-load-messages", &force_load_messages,
4381 doc: /* Non-nil means force printing messages when loading Lisp files.
4382 This overrides the value of the NOMESSAGE argument to `load'. */);
4383 force_load_messages = 0;
4385 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp,
4386 doc: /* Regular expression matching safe to load compiled Lisp files.
4387 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4388 from the file, and matches them against this regular expression.
4389 When the regular expression matches, the file is considered to be safe
4390 to load. See also `load-dangerous-libraries'. */);
4391 Vbytecomp_version_regexp
4392 = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4394 DEFVAR_LISP ("eval-buffer-list", &Veval_buffer_list,
4395 doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4396 Veval_buffer_list = Qnil;
4398 DEFVAR_LISP ("old-style-backquotes", &Vold_style_backquotes,
4399 doc: /* Set to non-nil when `read' encounters an old-style backquote. */);
4400 Vold_style_backquotes = Qnil;
4401 Qold_style_backquotes = intern_c_string ("old-style-backquotes");
4402 staticpro (&Qold_style_backquotes);
4404 /* Vsource_directory was initialized in init_lread. */
4406 load_descriptor_list = Qnil;
4407 staticpro (&load_descriptor_list);
4409 Qcurrent_load_list = intern_c_string ("current-load-list");
4410 staticpro (&Qcurrent_load_list);
4412 Qstandard_input = intern_c_string ("standard-input");
4413 staticpro (&Qstandard_input);
4415 Qread_char = intern_c_string ("read-char");
4416 staticpro (&Qread_char);
4418 Qget_file_char = intern_c_string ("get-file-char");
4419 staticpro (&Qget_file_char);
4421 Qget_emacs_mule_file_char = intern_c_string ("get-emacs-mule-file-char");
4422 staticpro (&Qget_emacs_mule_file_char);
4424 Qload_force_doc_strings = intern_c_string ("load-force-doc-strings");
4425 staticpro (&Qload_force_doc_strings);
4427 Qbackquote = intern_c_string ("`");
4428 staticpro (&Qbackquote);
4429 Qcomma = intern_c_string (",");
4430 staticpro (&Qcomma);
4431 Qcomma_at = intern_c_string (",@");
4432 staticpro (&Qcomma_at);
4433 Qcomma_dot = intern_c_string (",.");
4434 staticpro (&Qcomma_dot);
4436 Qinhibit_file_name_operation = intern_c_string ("inhibit-file-name-operation");
4437 staticpro (&Qinhibit_file_name_operation);
4439 Qascii_character = intern_c_string ("ascii-character");
4440 staticpro (&Qascii_character);
4442 Qfunction = intern_c_string ("function");
4443 staticpro (&Qfunction);
4445 Qload = intern_c_string ("load");
4446 staticpro (&Qload);
4448 Qload_file_name = intern_c_string ("load-file-name");
4449 staticpro (&Qload_file_name);
4451 Qeval_buffer_list = intern_c_string ("eval-buffer-list");
4452 staticpro (&Qeval_buffer_list);
4454 Qfile_truename = intern_c_string ("file-truename");
4455 staticpro (&Qfile_truename) ;
4457 Qdo_after_load_evaluation = intern_c_string ("do-after-load-evaluation");
4458 staticpro (&Qdo_after_load_evaluation) ;
4460 staticpro (&dump_path);
4462 staticpro (&read_objects);
4463 read_objects = Qnil;
4464 staticpro (&seen_list);
4465 seen_list = Qnil;
4467 Vloads_in_progress = Qnil;
4468 staticpro (&Vloads_in_progress);
4470 Qhash_table = intern_c_string ("hash-table");
4471 staticpro (&Qhash_table);
4472 Qdata = intern_c_string ("data");
4473 staticpro (&Qdata);
4474 Qtest = intern_c_string ("test");
4475 staticpro (&Qtest);
4476 Qsize = intern_c_string ("size");
4477 staticpro (&Qsize);
4478 Qweakness = intern_c_string ("weakness");
4479 staticpro (&Qweakness);
4480 Qrehash_size = intern_c_string ("rehash-size");
4481 staticpro (&Qrehash_size);
4482 Qrehash_threshold = intern_c_string ("rehash-threshold");
4483 staticpro (&Qrehash_threshold);
4486 /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d
4487 (do not change this comment) */