* xterm.c (x_fully_uncatch_errors, x_trace_wire, x_check_font): Convert old-style...
[emacs.git] / src / lread.c
blob96108ec4a72758bf89a684f75a49317b4af349dd
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 */
1281 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
1282 if (stream != NULL)
1284 BLOCK_INPUT;
1285 fclose (stream);
1286 UNBLOCK_INPUT;
1288 return Qnil;
1291 static Lisp_Object
1292 load_descriptor_unwind (Lisp_Object oldlist)
1294 load_descriptor_list = oldlist;
1295 return Qnil;
1298 /* Close all descriptors in use for Floads.
1299 This is used when starting a subprocess. */
1301 void
1302 close_load_descs (void)
1304 #ifndef WINDOWSNT
1305 Lisp_Object tail;
1306 for (tail = load_descriptor_list; CONSP (tail); tail = XCDR (tail))
1307 emacs_close (XFASTINT (XCAR (tail)));
1308 #endif
1311 static int
1312 complete_filename_p (Lisp_Object pathname)
1314 register const unsigned char *s = SDATA (pathname);
1315 return (IS_DIRECTORY_SEP (s[0])
1316 || (SCHARS (pathname) > 2
1317 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])));
1320 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
1321 doc: /* Search for FILENAME through PATH.
1322 Returns the file's name in absolute form, or nil if not found.
1323 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1324 file name when searching.
1325 If non-nil, PREDICATE is used instead of `file-readable-p'.
1326 PREDICATE can also be an integer to pass to the access(2) function,
1327 in which case file-name-handlers are ignored. */)
1328 (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate)
1330 Lisp_Object file;
1331 int fd = openp (path, filename, suffixes, &file, predicate);
1332 if (NILP (predicate) && fd > 0)
1333 close (fd);
1334 return file;
1338 /* Search for a file whose name is STR, looking in directories
1339 in the Lisp list PATH, and trying suffixes from SUFFIX.
1340 On success, returns a file descriptor. On failure, returns -1.
1342 SUFFIXES is a list of strings containing possible suffixes.
1343 The empty suffix is automatically added if the list is empty.
1345 PREDICATE non-nil means don't open the files,
1346 just look for one that satisfies the predicate. In this case,
1347 returns 1 on success. The predicate can be a lisp function or
1348 an integer to pass to `access' (in which case file-name-handlers
1349 are ignored).
1351 If STOREPTR is nonzero, it points to a slot where the name of
1352 the file actually found should be stored as a Lisp string.
1353 nil is stored there on failure.
1355 If the file we find is remote, return -2
1356 but store the found remote file name in *STOREPTR. */
1359 openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate)
1361 register int fd;
1362 int fn_size = 100;
1363 char buf[100];
1364 register char *fn = buf;
1365 int absolute = 0;
1366 int want_size;
1367 Lisp_Object filename;
1368 struct stat st;
1369 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1370 Lisp_Object string, tail, encoded_fn;
1371 int max_suffix_len = 0;
1373 CHECK_STRING (str);
1375 for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
1377 CHECK_STRING_CAR (tail);
1378 max_suffix_len = max (max_suffix_len,
1379 SBYTES (XCAR (tail)));
1382 string = filename = encoded_fn = Qnil;
1383 GCPRO6 (str, string, filename, path, suffixes, encoded_fn);
1385 if (storeptr)
1386 *storeptr = Qnil;
1388 if (complete_filename_p (str))
1389 absolute = 1;
1391 for (; CONSP (path); path = XCDR (path))
1393 filename = Fexpand_file_name (str, XCAR (path));
1394 if (!complete_filename_p (filename))
1395 /* If there are non-absolute elts in PATH (eg ".") */
1396 /* Of course, this could conceivably lose if luser sets
1397 default-directory to be something non-absolute... */
1399 filename = Fexpand_file_name (filename, current_buffer->directory);
1400 if (!complete_filename_p (filename))
1401 /* Give up on this path element! */
1402 continue;
1405 /* Calculate maximum size of any filename made from
1406 this path element/specified file name and any possible suffix. */
1407 want_size = max_suffix_len + SBYTES (filename) + 1;
1408 if (fn_size < want_size)
1409 fn = (char *) alloca (fn_size = 100 + want_size);
1411 /* Loop over suffixes. */
1412 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1413 CONSP (tail); tail = XCDR (tail))
1415 int lsuffix = SBYTES (XCAR (tail));
1416 Lisp_Object handler;
1417 int exists;
1419 /* Concatenate path element/specified name with the suffix.
1420 If the directory starts with /:, remove that. */
1421 if (SCHARS (filename) > 2
1422 && SREF (filename, 0) == '/'
1423 && SREF (filename, 1) == ':')
1425 strncpy (fn, SDATA (filename) + 2,
1426 SBYTES (filename) - 2);
1427 fn[SBYTES (filename) - 2] = 0;
1429 else
1431 strncpy (fn, SDATA (filename),
1432 SBYTES (filename));
1433 fn[SBYTES (filename)] = 0;
1436 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1437 strncat (fn, SDATA (XCAR (tail)), lsuffix);
1439 /* Check that the file exists and is not a directory. */
1440 /* We used to only check for handlers on non-absolute file names:
1441 if (absolute)
1442 handler = Qnil;
1443 else
1444 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1445 It's not clear why that was the case and it breaks things like
1446 (load "/bar.el") where the file is actually "/bar.el.gz". */
1447 string = build_string (fn);
1448 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1449 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1451 if (NILP (predicate))
1452 exists = !NILP (Ffile_readable_p (string));
1453 else
1454 exists = !NILP (call1 (predicate, string));
1455 if (exists && !NILP (Ffile_directory_p (string)))
1456 exists = 0;
1458 if (exists)
1460 /* We succeeded; return this descriptor and filename. */
1461 if (storeptr)
1462 *storeptr = string;
1463 UNGCPRO;
1464 return -2;
1467 else
1469 const char *pfn;
1471 encoded_fn = ENCODE_FILE (string);
1472 pfn = SDATA (encoded_fn);
1473 exists = (stat (pfn, &st) >= 0
1474 && (st.st_mode & S_IFMT) != S_IFDIR);
1475 if (exists)
1477 /* Check that we can access or open it. */
1478 if (NATNUMP (predicate))
1479 fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1;
1480 else
1481 fd = emacs_open (pfn, O_RDONLY, 0);
1483 if (fd >= 0)
1485 /* We succeeded; return this descriptor and filename. */
1486 if (storeptr)
1487 *storeptr = string;
1488 UNGCPRO;
1489 return fd;
1494 if (absolute)
1495 break;
1498 UNGCPRO;
1499 return -1;
1503 /* Merge the list we've accumulated of globals from the current input source
1504 into the load_history variable. The details depend on whether
1505 the source has an associated file name or not.
1507 FILENAME is the file name that we are loading from.
1508 ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */
1510 static void
1511 build_load_history (Lisp_Object filename, int entire)
1513 register Lisp_Object tail, prev, newelt;
1514 register Lisp_Object tem, tem2;
1515 register int foundit = 0;
1517 tail = Vload_history;
1518 prev = Qnil;
1520 while (CONSP (tail))
1522 tem = XCAR (tail);
1524 /* Find the feature's previous assoc list... */
1525 if (!NILP (Fequal (filename, Fcar (tem))))
1527 foundit = 1;
1529 /* If we're loading the entire file, remove old data. */
1530 if (entire)
1532 if (NILP (prev))
1533 Vload_history = XCDR (tail);
1534 else
1535 Fsetcdr (prev, XCDR (tail));
1538 /* Otherwise, cons on new symbols that are not already members. */
1539 else
1541 tem2 = Vcurrent_load_list;
1543 while (CONSP (tem2))
1545 newelt = XCAR (tem2);
1547 if (NILP (Fmember (newelt, tem)))
1548 Fsetcar (tail, Fcons (XCAR (tem),
1549 Fcons (newelt, XCDR (tem))));
1551 tem2 = XCDR (tem2);
1552 QUIT;
1556 else
1557 prev = tail;
1558 tail = XCDR (tail);
1559 QUIT;
1562 /* If we're loading an entire file, cons the new assoc onto the
1563 front of load-history, the most-recently-loaded position. Also
1564 do this if we didn't find an existing member for the file. */
1565 if (entire || !foundit)
1566 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1567 Vload_history);
1570 Lisp_Object
1571 unreadpure (Lisp_Object junk) /* Used as unwind-protect function in readevalloop */
1574 read_pure = 0;
1575 return Qnil;
1578 static Lisp_Object
1579 readevalloop_1 (Lisp_Object old)
1581 load_convert_to_unibyte = ! NILP (old);
1582 return Qnil;
1585 /* Signal an `end-of-file' error, if possible with file name
1586 information. */
1588 static void
1589 end_of_file_error (void)
1591 if (STRINGP (Vload_file_name))
1592 xsignal1 (Qend_of_file, Vload_file_name);
1594 xsignal0 (Qend_of_file);
1597 /* UNIBYTE specifies how to set load_convert_to_unibyte
1598 for this invocation.
1599 READFUN, if non-nil, is used instead of `read'.
1601 START, END specify region to read in current buffer (from eval-region).
1602 If the input is not from a buffer, they must be nil. */
1604 static void
1605 readevalloop (Lisp_Object readcharfun,
1606 FILE *stream,
1607 Lisp_Object sourcename,
1608 Lisp_Object (*evalfun) (Lisp_Object),
1609 int printflag,
1610 Lisp_Object unibyte, Lisp_Object readfun,
1611 Lisp_Object start, Lisp_Object end)
1613 register int c;
1614 register Lisp_Object val;
1615 int count = SPECPDL_INDEX ();
1616 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1617 struct buffer *b = 0;
1618 int continue_reading_p;
1619 /* Nonzero if reading an entire buffer. */
1620 int whole_buffer = 0;
1621 /* 1 on the first time around. */
1622 int first_sexp = 1;
1624 if (MARKERP (readcharfun))
1626 if (NILP (start))
1627 start = readcharfun;
1630 if (BUFFERP (readcharfun))
1631 b = XBUFFER (readcharfun);
1632 else if (MARKERP (readcharfun))
1633 b = XMARKER (readcharfun)->buffer;
1635 /* We assume START is nil when input is not from a buffer. */
1636 if (! NILP (start) && !b)
1637 abort ();
1639 specbind (Qstandard_input, readcharfun); /* GCPROs readcharfun. */
1640 specbind (Qcurrent_load_list, Qnil);
1641 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
1642 load_convert_to_unibyte = !NILP (unibyte);
1644 GCPRO4 (sourcename, readfun, start, end);
1646 /* Try to ensure sourcename is a truename, except whilst preloading. */
1647 if (NILP (Vpurify_flag)
1648 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename))
1649 && !NILP (Ffboundp (Qfile_truename)))
1650 sourcename = call1 (Qfile_truename, sourcename) ;
1652 LOADHIST_ATTACH (sourcename);
1654 continue_reading_p = 1;
1655 while (continue_reading_p)
1657 int count1 = SPECPDL_INDEX ();
1659 if (b != 0 && NILP (b->name))
1660 error ("Reading from killed buffer");
1662 if (!NILP (start))
1664 /* Switch to the buffer we are reading from. */
1665 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1666 set_buffer_internal (b);
1668 /* Save point in it. */
1669 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1670 /* Save ZV in it. */
1671 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1672 /* Those get unbound after we read one expression. */
1674 /* Set point and ZV around stuff to be read. */
1675 Fgoto_char (start);
1676 if (!NILP (end))
1677 Fnarrow_to_region (make_number (BEGV), end);
1679 /* Just for cleanliness, convert END to a marker
1680 if it is an integer. */
1681 if (INTEGERP (end))
1682 end = Fpoint_max_marker ();
1685 /* On the first cycle, we can easily test here
1686 whether we are reading the whole buffer. */
1687 if (b && first_sexp)
1688 whole_buffer = (PT == BEG && ZV == Z);
1690 instream = stream;
1691 read_next:
1692 c = READCHAR;
1693 if (c == ';')
1695 while ((c = READCHAR) != '\n' && c != -1);
1696 goto read_next;
1698 if (c < 0)
1700 unbind_to (count1, Qnil);
1701 break;
1704 /* Ignore whitespace here, so we can detect eof. */
1705 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'
1706 || c == 0x8a0) /* NBSP */
1707 goto read_next;
1709 if (!NILP (Vpurify_flag) && c == '(')
1711 record_unwind_protect (unreadpure, Qnil);
1712 val = read_list (-1, readcharfun);
1714 else
1716 UNREAD (c);
1717 read_objects = Qnil;
1718 if (!NILP (readfun))
1720 val = call1 (readfun, readcharfun);
1722 /* If READCHARFUN has set point to ZV, we should
1723 stop reading, even if the form read sets point
1724 to a different value when evaluated. */
1725 if (BUFFERP (readcharfun))
1727 struct buffer *b = XBUFFER (readcharfun);
1728 if (BUF_PT (b) == BUF_ZV (b))
1729 continue_reading_p = 0;
1732 else if (! NILP (Vload_read_function))
1733 val = call1 (Vload_read_function, readcharfun);
1734 else
1735 val = read_internal_start (readcharfun, Qnil, Qnil);
1738 if (!NILP (start) && continue_reading_p)
1739 start = Fpoint_marker ();
1741 /* Restore saved point and BEGV. */
1742 unbind_to (count1, Qnil);
1744 /* Now eval what we just read. */
1745 val = (*evalfun) (val);
1747 if (printflag)
1749 Vvalues = Fcons (val, Vvalues);
1750 if (EQ (Vstandard_output, Qt))
1751 Fprin1 (val, Qnil);
1752 else
1753 Fprint (val, Qnil);
1756 first_sexp = 0;
1759 build_load_history (sourcename,
1760 stream || whole_buffer);
1762 UNGCPRO;
1764 unbind_to (count, Qnil);
1767 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
1768 doc: /* Execute the current buffer as Lisp code.
1769 When called from a Lisp program (i.e., not interactively), this
1770 function accepts up to five optional arguments:
1771 BUFFER is the buffer to evaluate (nil means use current buffer).
1772 PRINTFLAG controls printing of output:
1773 A value of nil means discard it; anything else is stream for print.
1774 FILENAME specifies the file name to use for `load-history'.
1775 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
1776 invocation.
1777 DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1778 functions should work normally even if PRINTFLAG is nil.
1780 This function preserves the position of point. */)
1781 (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print)
1783 int count = SPECPDL_INDEX ();
1784 Lisp_Object tem, buf;
1786 if (NILP (buffer))
1787 buf = Fcurrent_buffer ();
1788 else
1789 buf = Fget_buffer (buffer);
1790 if (NILP (buf))
1791 error ("No such buffer");
1793 if (NILP (printflag) && NILP (do_allow_print))
1794 tem = Qsymbolp;
1795 else
1796 tem = printflag;
1798 if (NILP (filename))
1799 filename = XBUFFER (buf)->filename;
1801 specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
1802 specbind (Qstandard_output, tem);
1803 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1804 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
1805 readevalloop (buf, 0, filename, Feval,
1806 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
1807 unbind_to (count, Qnil);
1809 return Qnil;
1812 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
1813 doc: /* Execute the region as Lisp code.
1814 When called from programs, expects two arguments,
1815 giving starting and ending indices in the current buffer
1816 of the text to be executed.
1817 Programs can pass third argument PRINTFLAG which controls output:
1818 A value of nil means discard it; anything else is stream for printing it.
1819 Also the fourth argument READ-FUNCTION, if non-nil, is used
1820 instead of `read' to read each expression. It gets one argument
1821 which is the input stream for reading characters.
1823 This function does not move point. */)
1824 (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function)
1826 int count = SPECPDL_INDEX ();
1827 Lisp_Object tem, cbuf;
1829 cbuf = Fcurrent_buffer ();
1831 if (NILP (printflag))
1832 tem = Qsymbolp;
1833 else
1834 tem = printflag;
1835 specbind (Qstandard_output, tem);
1836 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list));
1838 /* readevalloop calls functions which check the type of start and end. */
1839 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
1840 !NILP (printflag), Qnil, read_function,
1841 start, end);
1843 return unbind_to (count, Qnil);
1847 DEFUN ("read", Fread, Sread, 0, 1, 0,
1848 doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1849 If STREAM is nil, use the value of `standard-input' (which see).
1850 STREAM or the value of `standard-input' may be:
1851 a buffer (read from point and advance it)
1852 a marker (read from where it points and advance it)
1853 a function (call it with no arguments for each character,
1854 call it with a char as argument to push a char back)
1855 a string (takes text from string, starting at the beginning)
1856 t (read text line using minibuffer and use it, or read from
1857 standard input in batch mode). */)
1858 (Lisp_Object stream)
1860 if (NILP (stream))
1861 stream = Vstandard_input;
1862 if (EQ (stream, Qt))
1863 stream = Qread_char;
1864 if (EQ (stream, Qread_char))
1865 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
1867 return read_internal_start (stream, Qnil, Qnil);
1870 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
1871 doc: /* Read one Lisp expression which is represented as text by STRING.
1872 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1873 START and END optionally delimit a substring of STRING from which to read;
1874 they default to 0 and (length STRING) respectively. */)
1875 (Lisp_Object string, Lisp_Object start, Lisp_Object end)
1877 Lisp_Object ret;
1878 CHECK_STRING (string);
1879 /* read_internal_start sets read_from_string_index. */
1880 ret = read_internal_start (string, start, end);
1881 return Fcons (ret, make_number (read_from_string_index));
1884 /* Function to set up the global context we need in toplevel read
1885 calls. */
1886 static Lisp_Object
1887 read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
1888 /* start, end only used when stream is a string. */
1890 Lisp_Object retval;
1892 readchar_count = 0;
1893 new_backquote_flag = 0;
1894 read_objects = Qnil;
1895 if (EQ (Vread_with_symbol_positions, Qt)
1896 || EQ (Vread_with_symbol_positions, stream))
1897 Vread_symbol_positions_list = Qnil;
1899 if (STRINGP (stream)
1900 || ((CONSP (stream) && STRINGP (XCAR (stream)))))
1902 int startval, endval;
1903 Lisp_Object string;
1905 if (STRINGP (stream))
1906 string = stream;
1907 else
1908 string = XCAR (stream);
1910 if (NILP (end))
1911 endval = SCHARS (string);
1912 else
1914 CHECK_NUMBER (end);
1915 endval = XINT (end);
1916 if (endval < 0 || endval > SCHARS (string))
1917 args_out_of_range (string, end);
1920 if (NILP (start))
1921 startval = 0;
1922 else
1924 CHECK_NUMBER (start);
1925 startval = XINT (start);
1926 if (startval < 0 || startval > endval)
1927 args_out_of_range (string, start);
1929 read_from_string_index = startval;
1930 read_from_string_index_byte = string_char_to_byte (string, startval);
1931 read_from_string_limit = endval;
1934 retval = read0 (stream);
1935 if (EQ (Vread_with_symbol_positions, Qt)
1936 || EQ (Vread_with_symbol_positions, stream))
1937 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list);
1938 return retval;
1942 /* Signal Qinvalid_read_syntax error.
1943 S is error string of length N (if > 0) */
1945 static void
1946 invalid_syntax (const char *s, int n)
1948 if (!n)
1949 n = strlen (s);
1950 xsignal1 (Qinvalid_read_syntax, make_string (s, n));
1954 /* Use this for recursive reads, in contexts where internal tokens
1955 are not allowed. */
1957 static Lisp_Object
1958 read0 (Lisp_Object readcharfun)
1960 register Lisp_Object val;
1961 int c;
1963 val = read1 (readcharfun, &c, 0);
1964 if (!c)
1965 return val;
1967 xsignal1 (Qinvalid_read_syntax,
1968 Fmake_string (make_number (1), make_number (c)));
1971 static int read_buffer_size;
1972 static char *read_buffer;
1974 /* Read a \-escape sequence, assuming we already read the `\'.
1975 If the escape sequence forces unibyte, return eight-bit char. */
1977 static int
1978 read_escape (Lisp_Object readcharfun, int stringp)
1980 register int c = READCHAR;
1981 /* \u allows up to four hex digits, \U up to eight. Default to the
1982 behavior for \u, and change this value in the case that \U is seen. */
1983 int unicode_hex_count = 4;
1985 switch (c)
1987 case -1:
1988 end_of_file_error ();
1990 case 'a':
1991 return '\007';
1992 case 'b':
1993 return '\b';
1994 case 'd':
1995 return 0177;
1996 case 'e':
1997 return 033;
1998 case 'f':
1999 return '\f';
2000 case 'n':
2001 return '\n';
2002 case 'r':
2003 return '\r';
2004 case 't':
2005 return '\t';
2006 case 'v':
2007 return '\v';
2008 case '\n':
2009 return -1;
2010 case ' ':
2011 if (stringp)
2012 return -1;
2013 return ' ';
2015 case 'M':
2016 c = READCHAR;
2017 if (c != '-')
2018 error ("Invalid escape character syntax");
2019 c = READCHAR;
2020 if (c == '\\')
2021 c = read_escape (readcharfun, 0);
2022 return c | meta_modifier;
2024 case 'S':
2025 c = READCHAR;
2026 if (c != '-')
2027 error ("Invalid escape character syntax");
2028 c = READCHAR;
2029 if (c == '\\')
2030 c = read_escape (readcharfun, 0);
2031 return c | shift_modifier;
2033 case 'H':
2034 c = READCHAR;
2035 if (c != '-')
2036 error ("Invalid escape character syntax");
2037 c = READCHAR;
2038 if (c == '\\')
2039 c = read_escape (readcharfun, 0);
2040 return c | hyper_modifier;
2042 case 'A':
2043 c = READCHAR;
2044 if (c != '-')
2045 error ("Invalid escape character syntax");
2046 c = READCHAR;
2047 if (c == '\\')
2048 c = read_escape (readcharfun, 0);
2049 return c | alt_modifier;
2051 case 's':
2052 c = READCHAR;
2053 if (stringp || c != '-')
2055 UNREAD (c);
2056 return ' ';
2058 c = READCHAR;
2059 if (c == '\\')
2060 c = read_escape (readcharfun, 0);
2061 return c | super_modifier;
2063 case 'C':
2064 c = READCHAR;
2065 if (c != '-')
2066 error ("Invalid escape character syntax");
2067 case '^':
2068 c = READCHAR;
2069 if (c == '\\')
2070 c = read_escape (readcharfun, 0);
2071 if ((c & ~CHAR_MODIFIER_MASK) == '?')
2072 return 0177 | (c & CHAR_MODIFIER_MASK);
2073 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
2074 return c | ctrl_modifier;
2075 /* ASCII control chars are made from letters (both cases),
2076 as well as the non-letters within 0100...0137. */
2077 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
2078 return (c & (037 | ~0177));
2079 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
2080 return (c & (037 | ~0177));
2081 else
2082 return c | ctrl_modifier;
2084 case '0':
2085 case '1':
2086 case '2':
2087 case '3':
2088 case '4':
2089 case '5':
2090 case '6':
2091 case '7':
2092 /* An octal escape, as in ANSI C. */
2094 register int i = c - '0';
2095 register int count = 0;
2096 while (++count < 3)
2098 if ((c = READCHAR) >= '0' && c <= '7')
2100 i *= 8;
2101 i += c - '0';
2103 else
2105 UNREAD (c);
2106 break;
2110 if (i >= 0x80 && i < 0x100)
2111 i = BYTE8_TO_CHAR (i);
2112 return i;
2115 case 'x':
2116 /* A hex escape, as in ANSI C. */
2118 int i = 0;
2119 int count = 0;
2120 while (1)
2122 c = READCHAR;
2123 if (c >= '0' && c <= '9')
2125 i *= 16;
2126 i += c - '0';
2128 else if ((c >= 'a' && c <= 'f')
2129 || (c >= 'A' && c <= 'F'))
2131 i *= 16;
2132 if (c >= 'a' && c <= 'f')
2133 i += c - 'a' + 10;
2134 else
2135 i += c - 'A' + 10;
2137 else
2139 UNREAD (c);
2140 break;
2142 count++;
2145 if (count < 3 && i >= 0x80)
2146 return BYTE8_TO_CHAR (i);
2147 return i;
2150 case 'U':
2151 /* Post-Unicode-2.0: Up to eight hex chars. */
2152 unicode_hex_count = 8;
2153 case 'u':
2155 /* A Unicode escape. We only permit them in strings and characters,
2156 not arbitrarily in the source code, as in some other languages. */
2158 unsigned int i = 0;
2159 int count = 0;
2161 while (++count <= unicode_hex_count)
2163 c = READCHAR;
2164 /* isdigit and isalpha may be locale-specific, which we don't
2165 want. */
2166 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
2167 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
2168 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
2169 else
2171 error ("Non-hex digit used for Unicode escape");
2172 break;
2175 if (i > 0x10FFFF)
2176 error ("Non-Unicode character: 0x%x", i);
2177 return i;
2180 default:
2181 return c;
2185 /* Read an integer in radix RADIX using READCHARFUN to read
2186 characters. RADIX must be in the interval [2..36]; if it isn't, a
2187 read error is signaled . Value is the integer read. Signals an
2188 error if encountering invalid read syntax or if RADIX is out of
2189 range. */
2191 static Lisp_Object
2192 read_integer (Lisp_Object readcharfun, int radix)
2194 int ndigits = 0, invalid_p, c, sign = 0;
2195 /* We use a floating point number because */
2196 double number = 0;
2198 if (radix < 2 || radix > 36)
2199 invalid_p = 1;
2200 else
2202 number = ndigits = invalid_p = 0;
2203 sign = 1;
2205 c = READCHAR;
2206 if (c == '-')
2208 c = READCHAR;
2209 sign = -1;
2211 else if (c == '+')
2212 c = READCHAR;
2214 while (c >= 0)
2216 int digit;
2218 if (c >= '0' && c <= '9')
2219 digit = c - '0';
2220 else if (c >= 'a' && c <= 'z')
2221 digit = c - 'a' + 10;
2222 else if (c >= 'A' && c <= 'Z')
2223 digit = c - 'A' + 10;
2224 else
2226 UNREAD (c);
2227 break;
2230 if (digit < 0 || digit >= radix)
2231 invalid_p = 1;
2233 number = radix * number + digit;
2234 ++ndigits;
2235 c = READCHAR;
2239 if (ndigits == 0 || invalid_p)
2241 char buf[50];
2242 sprintf (buf, "integer, radix %d", radix);
2243 invalid_syntax (buf, 0);
2246 return make_fixnum_or_float (sign * number);
2250 /* If the next token is ')' or ']' or '.', we store that character
2251 in *PCH and the return value is not interesting. Else, we store
2252 zero in *PCH and we read and return one lisp object.
2254 FIRST_IN_LIST is nonzero if this is the first element of a list. */
2256 static Lisp_Object
2257 read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2259 register int c;
2260 int uninterned_symbol = 0;
2261 int multibyte;
2263 *pch = 0;
2264 load_each_byte = 0;
2266 retry:
2268 c = READCHAR_REPORT_MULTIBYTE (&multibyte);
2269 if (c < 0)
2270 end_of_file_error ();
2272 switch (c)
2274 case '(':
2275 return read_list (0, readcharfun);
2277 case '[':
2278 return read_vector (readcharfun, 0);
2280 case ')':
2281 case ']':
2283 *pch = c;
2284 return Qnil;
2287 case '#':
2288 c = READCHAR;
2289 if (c == 's')
2291 c = READCHAR;
2292 if (c == '(')
2294 /* Accept extended format for hashtables (extensible to
2295 other types), e.g.
2296 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2297 Lisp_Object tmp = read_list (0, readcharfun);
2298 Lisp_Object head = CAR_SAFE (tmp);
2299 Lisp_Object data = Qnil;
2300 Lisp_Object val = Qnil;
2301 /* The size is 2 * number of allowed keywords to
2302 make-hash-table. */
2303 Lisp_Object params[10];
2304 Lisp_Object ht;
2305 Lisp_Object key = Qnil;
2306 int param_count = 0;
2308 if (!EQ (head, Qhash_table))
2309 error ("Invalid extended read marker at head of #s list "
2310 "(only hash-table allowed)");
2312 tmp = CDR_SAFE (tmp);
2314 /* This is repetitive but fast and simple. */
2315 params[param_count] = QCsize;
2316 params[param_count+1] = Fplist_get (tmp, Qsize);
2317 if (!NILP (params[param_count + 1]))
2318 param_count += 2;
2320 params[param_count] = QCtest;
2321 params[param_count+1] = Fplist_get (tmp, Qtest);
2322 if (!NILP (params[param_count + 1]))
2323 param_count += 2;
2325 params[param_count] = QCweakness;
2326 params[param_count+1] = Fplist_get (tmp, Qweakness);
2327 if (!NILP (params[param_count + 1]))
2328 param_count += 2;
2330 params[param_count] = QCrehash_size;
2331 params[param_count+1] = Fplist_get (tmp, Qrehash_size);
2332 if (!NILP (params[param_count + 1]))
2333 param_count += 2;
2335 params[param_count] = QCrehash_threshold;
2336 params[param_count+1] = Fplist_get (tmp, Qrehash_threshold);
2337 if (!NILP (params[param_count + 1]))
2338 param_count += 2;
2340 /* This is the hashtable data. */
2341 data = Fplist_get (tmp, Qdata);
2343 /* Now use params to make a new hashtable and fill it. */
2344 ht = Fmake_hash_table (param_count, params);
2346 while (CONSP (data))
2348 key = XCAR (data);
2349 data = XCDR (data);
2350 if (!CONSP (data))
2351 error ("Odd number of elements in hashtable data");
2352 val = XCAR (data);
2353 data = XCDR (data);
2354 Fputhash (key, val, ht);
2357 return ht;
2359 UNREAD (c);
2360 invalid_syntax ("#", 1);
2362 if (c == '^')
2364 c = READCHAR;
2365 if (c == '[')
2367 Lisp_Object tmp;
2368 tmp = read_vector (readcharfun, 0);
2369 if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS)
2370 error ("Invalid size char-table");
2371 XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE);
2372 return tmp;
2374 else if (c == '^')
2376 c = READCHAR;
2377 if (c == '[')
2379 Lisp_Object tmp;
2380 int depth, size;
2382 tmp = read_vector (readcharfun, 0);
2383 if (!INTEGERP (AREF (tmp, 0)))
2384 error ("Invalid depth in char-table");
2385 depth = XINT (AREF (tmp, 0));
2386 if (depth < 1 || depth > 3)
2387 error ("Invalid depth in char-table");
2388 size = XVECTOR (tmp)->size - 2;
2389 if (chartab_size [depth] != size)
2390 error ("Invalid size char-table");
2391 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
2392 return tmp;
2394 invalid_syntax ("#^^", 3);
2396 invalid_syntax ("#^", 2);
2398 if (c == '&')
2400 Lisp_Object length;
2401 length = read1 (readcharfun, pch, first_in_list);
2402 c = READCHAR;
2403 if (c == '"')
2405 Lisp_Object tmp, val;
2406 int size_in_chars
2407 = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2408 / BOOL_VECTOR_BITS_PER_CHAR);
2410 UNREAD (c);
2411 tmp = read1 (readcharfun, pch, first_in_list);
2412 if (STRING_MULTIBYTE (tmp)
2413 || (size_in_chars != SCHARS (tmp)
2414 /* We used to print 1 char too many
2415 when the number of bits was a multiple of 8.
2416 Accept such input in case it came from an old
2417 version. */
2418 && ! (XFASTINT (length)
2419 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
2420 invalid_syntax ("#&...", 5);
2422 val = Fmake_bool_vector (length, Qnil);
2423 memcpy (XBOOL_VECTOR (val)->data, SDATA (tmp), size_in_chars);
2424 /* Clear the extraneous bits in the last byte. */
2425 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
2426 XBOOL_VECTOR (val)->data[size_in_chars - 1]
2427 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2428 return val;
2430 invalid_syntax ("#&...", 5);
2432 if (c == '[')
2434 /* Accept compiled functions at read-time so that we don't have to
2435 build them using function calls. */
2436 Lisp_Object tmp;
2437 tmp = read_vector (readcharfun, 1);
2438 return Fmake_byte_code (XVECTOR (tmp)->size,
2439 XVECTOR (tmp)->contents);
2441 if (c == '(')
2443 Lisp_Object tmp;
2444 struct gcpro gcpro1;
2445 int ch;
2447 /* Read the string itself. */
2448 tmp = read1 (readcharfun, &ch, 0);
2449 if (ch != 0 || !STRINGP (tmp))
2450 invalid_syntax ("#", 1);
2451 GCPRO1 (tmp);
2452 /* Read the intervals and their properties. */
2453 while (1)
2455 Lisp_Object beg, end, plist;
2457 beg = read1 (readcharfun, &ch, 0);
2458 end = plist = Qnil;
2459 if (ch == ')')
2460 break;
2461 if (ch == 0)
2462 end = read1 (readcharfun, &ch, 0);
2463 if (ch == 0)
2464 plist = read1 (readcharfun, &ch, 0);
2465 if (ch)
2466 invalid_syntax ("Invalid string property list", 0);
2467 Fset_text_properties (beg, end, plist, tmp);
2469 UNGCPRO;
2470 return tmp;
2473 /* #@NUMBER is used to skip NUMBER following characters.
2474 That's used in .elc files to skip over doc strings
2475 and function definitions. */
2476 if (c == '@')
2478 int i, nskip = 0;
2480 load_each_byte = 1;
2481 /* Read a decimal integer. */
2482 while ((c = READCHAR) >= 0
2483 && c >= '0' && c <= '9')
2485 nskip *= 10;
2486 nskip += c - '0';
2488 if (c >= 0)
2489 UNREAD (c);
2491 if (load_force_doc_strings
2492 && (EQ (readcharfun, Qget_file_char)
2493 || EQ (readcharfun, Qget_emacs_mule_file_char)))
2495 /* If we are supposed to force doc strings into core right now,
2496 record the last string that we skipped,
2497 and record where in the file it comes from. */
2499 /* But first exchange saved_doc_string
2500 with prev_saved_doc_string, so we save two strings. */
2502 char *temp = saved_doc_string;
2503 int temp_size = saved_doc_string_size;
2504 file_offset temp_pos = saved_doc_string_position;
2505 int temp_len = saved_doc_string_length;
2507 saved_doc_string = prev_saved_doc_string;
2508 saved_doc_string_size = prev_saved_doc_string_size;
2509 saved_doc_string_position = prev_saved_doc_string_position;
2510 saved_doc_string_length = prev_saved_doc_string_length;
2512 prev_saved_doc_string = temp;
2513 prev_saved_doc_string_size = temp_size;
2514 prev_saved_doc_string_position = temp_pos;
2515 prev_saved_doc_string_length = temp_len;
2518 if (saved_doc_string_size == 0)
2520 saved_doc_string_size = nskip + 100;
2521 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
2523 if (nskip > saved_doc_string_size)
2525 saved_doc_string_size = nskip + 100;
2526 saved_doc_string = (char *) xrealloc (saved_doc_string,
2527 saved_doc_string_size);
2530 saved_doc_string_position = file_tell (instream);
2532 /* Copy that many characters into saved_doc_string. */
2533 for (i = 0; i < nskip && c >= 0; i++)
2534 saved_doc_string[i] = c = READCHAR;
2536 saved_doc_string_length = i;
2538 else
2540 /* Skip that many characters. */
2541 for (i = 0; i < nskip && c >= 0; i++)
2542 c = READCHAR;
2545 load_each_byte = 0;
2546 goto retry;
2548 if (c == '!')
2550 /* #! appears at the beginning of an executable file.
2551 Skip the first line. */
2552 while (c != '\n' && c >= 0)
2553 c = READCHAR;
2554 goto retry;
2556 if (c == '$')
2557 return Vload_file_name;
2558 if (c == '\'')
2559 return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
2560 /* #:foo is the uninterned symbol named foo. */
2561 if (c == ':')
2563 uninterned_symbol = 1;
2564 c = READCHAR;
2565 goto default_label;
2567 /* Reader forms that can reuse previously read objects. */
2568 if (c >= '0' && c <= '9')
2570 int n = 0;
2571 Lisp_Object tem;
2573 /* Read a non-negative integer. */
2574 while (c >= '0' && c <= '9')
2576 n *= 10;
2577 n += c - '0';
2578 c = READCHAR;
2580 /* #n=object returns object, but associates it with n for #n#. */
2581 if (c == '=' && !NILP (Vread_circle))
2583 /* Make a placeholder for #n# to use temporarily */
2584 Lisp_Object placeholder;
2585 Lisp_Object cell;
2587 placeholder = Fcons (Qnil, Qnil);
2588 cell = Fcons (make_number (n), placeholder);
2589 read_objects = Fcons (cell, read_objects);
2591 /* Read the object itself. */
2592 tem = read0 (readcharfun);
2594 /* Now put it everywhere the placeholder was... */
2595 substitute_object_in_subtree (tem, placeholder);
2597 /* ...and #n# will use the real value from now on. */
2598 Fsetcdr (cell, tem);
2600 return tem;
2602 /* #n# returns a previously read object. */
2603 if (c == '#' && !NILP (Vread_circle))
2605 tem = Fassq (make_number (n), read_objects);
2606 if (CONSP (tem))
2607 return XCDR (tem);
2608 /* Fall through to error message. */
2610 else if (c == 'r' || c == 'R')
2611 return read_integer (readcharfun, n);
2613 /* Fall through to error message. */
2615 else if (c == 'x' || c == 'X')
2616 return read_integer (readcharfun, 16);
2617 else if (c == 'o' || c == 'O')
2618 return read_integer (readcharfun, 8);
2619 else if (c == 'b' || c == 'B')
2620 return read_integer (readcharfun, 2);
2622 UNREAD (c);
2623 invalid_syntax ("#", 1);
2625 case ';':
2626 while ((c = READCHAR) >= 0 && c != '\n');
2627 goto retry;
2629 case '\'':
2631 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
2634 case '`':
2636 int next_char = READCHAR;
2637 UNREAD (next_char);
2638 /* Transition from old-style to new-style:
2639 If we see "(`" it used to mean old-style, which usually works
2640 fine because ` should almost never appear in such a position
2641 for new-style. But occasionally we need "(`" to mean new
2642 style, so we try to distinguish the two by the fact that we
2643 can either write "( `foo" or "(` foo", where the first
2644 intends to use new-style whereas the second intends to use
2645 old-style. For Emacs-25, we should completely remove this
2646 first_in_list exception (old-style can still be obtained via
2647 "(\`" anyway). */
2648 if (first_in_list && next_char == ' ')
2650 Vold_style_backquotes = Qt;
2651 goto default_label;
2653 else
2655 Lisp_Object value;
2657 new_backquote_flag++;
2658 value = read0 (readcharfun);
2659 new_backquote_flag--;
2661 return Fcons (Qbackquote, Fcons (value, Qnil));
2664 case ',':
2665 if (new_backquote_flag)
2667 Lisp_Object comma_type = Qnil;
2668 Lisp_Object value;
2669 int ch = READCHAR;
2671 if (ch == '@')
2672 comma_type = Qcomma_at;
2673 else if (ch == '.')
2674 comma_type = Qcomma_dot;
2675 else
2677 if (ch >= 0) UNREAD (ch);
2678 comma_type = Qcomma;
2681 new_backquote_flag--;
2682 value = read0 (readcharfun);
2683 new_backquote_flag++;
2684 return Fcons (comma_type, Fcons (value, Qnil));
2686 else
2688 Vold_style_backquotes = Qt;
2689 goto default_label;
2692 case '?':
2694 int modifiers;
2695 int next_char;
2696 int ok;
2698 c = READCHAR;
2699 if (c < 0)
2700 end_of_file_error ();
2702 /* Accept `single space' syntax like (list ? x) where the
2703 whitespace character is SPC or TAB.
2704 Other literal whitespace like NL, CR, and FF are not accepted,
2705 as there are well-established escape sequences for these. */
2706 if (c == ' ' || c == '\t')
2707 return make_number (c);
2709 if (c == '\\')
2710 c = read_escape (readcharfun, 0);
2711 modifiers = c & CHAR_MODIFIER_MASK;
2712 c &= ~CHAR_MODIFIER_MASK;
2713 if (CHAR_BYTE8_P (c))
2714 c = CHAR_TO_BYTE8 (c);
2715 c |= modifiers;
2717 next_char = READCHAR;
2718 if (next_char == '.')
2720 /* Only a dotted-pair dot is valid after a char constant. */
2721 int next_next_char = READCHAR;
2722 UNREAD (next_next_char);
2724 ok = (next_next_char <= 040
2725 || (next_next_char < 0200
2726 && (strchr ("\"';([#?", next_next_char)
2727 || (!first_in_list && next_next_char == '`')
2728 || (new_backquote_flag && next_next_char == ','))));
2730 else
2732 ok = (next_char <= 040
2733 || (next_char < 0200
2734 && (strchr ("\"';()[]#?", next_char)
2735 || (!first_in_list && next_char == '`')
2736 || (new_backquote_flag && next_char == ','))));
2738 UNREAD (next_char);
2739 if (ok)
2740 return make_number (c);
2742 invalid_syntax ("?", 1);
2745 case '"':
2747 char *p = read_buffer;
2748 char *end = read_buffer + read_buffer_size;
2749 register int c;
2750 /* Nonzero if we saw an escape sequence specifying
2751 a multibyte character. */
2752 int force_multibyte = 0;
2753 /* Nonzero if we saw an escape sequence specifying
2754 a single-byte character. */
2755 int force_singlebyte = 0;
2756 int cancel = 0;
2757 int nchars = 0;
2759 while ((c = READCHAR) >= 0
2760 && c != '\"')
2762 if (end - p < MAX_MULTIBYTE_LENGTH)
2764 int offset = p - read_buffer;
2765 read_buffer = (char *) xrealloc (read_buffer,
2766 read_buffer_size *= 2);
2767 p = read_buffer + offset;
2768 end = read_buffer + read_buffer_size;
2771 if (c == '\\')
2773 int modifiers;
2775 c = read_escape (readcharfun, 1);
2777 /* C is -1 if \ newline has just been seen */
2778 if (c == -1)
2780 if (p == read_buffer)
2781 cancel = 1;
2782 continue;
2785 modifiers = c & CHAR_MODIFIER_MASK;
2786 c = c & ~CHAR_MODIFIER_MASK;
2788 if (CHAR_BYTE8_P (c))
2789 force_singlebyte = 1;
2790 else if (! ASCII_CHAR_P (c))
2791 force_multibyte = 1;
2792 else /* i.e. ASCII_CHAR_P (c) */
2794 /* Allow `\C- ' and `\C-?'. */
2795 if (modifiers == CHAR_CTL)
2797 if (c == ' ')
2798 c = 0, modifiers = 0;
2799 else if (c == '?')
2800 c = 127, modifiers = 0;
2802 if (modifiers & CHAR_SHIFT)
2804 /* Shift modifier is valid only with [A-Za-z]. */
2805 if (c >= 'A' && c <= 'Z')
2806 modifiers &= ~CHAR_SHIFT;
2807 else if (c >= 'a' && c <= 'z')
2808 c -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
2811 if (modifiers & CHAR_META)
2813 /* Move the meta bit to the right place for a
2814 string. */
2815 modifiers &= ~CHAR_META;
2816 c = BYTE8_TO_CHAR (c | 0x80);
2817 force_singlebyte = 1;
2821 /* Any modifiers remaining are invalid. */
2822 if (modifiers)
2823 error ("Invalid modifier in string");
2824 p += CHAR_STRING (c, (unsigned char *) p);
2826 else
2828 p += CHAR_STRING (c, (unsigned char *) p);
2829 if (CHAR_BYTE8_P (c))
2830 force_singlebyte = 1;
2831 else if (! ASCII_CHAR_P (c))
2832 force_multibyte = 1;
2834 nchars++;
2837 if (c < 0)
2838 end_of_file_error ();
2840 /* If purifying, and string starts with \ newline,
2841 return zero instead. This is for doc strings
2842 that we are really going to find in etc/DOC.nn.nn */
2843 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
2844 return make_number (0);
2846 if (force_multibyte)
2847 /* READ_BUFFER already contains valid multibyte forms. */
2849 else if (force_singlebyte)
2851 nchars = str_as_unibyte (read_buffer, p - read_buffer);
2852 p = read_buffer + nchars;
2854 else
2855 /* Otherwise, READ_BUFFER contains only ASCII. */
2858 /* We want readchar_count to be the number of characters, not
2859 bytes. Hence we adjust for multibyte characters in the
2860 string. ... But it doesn't seem to be necessary, because
2861 READCHAR *does* read multibyte characters from buffers. */
2862 /* readchar_count -= (p - read_buffer) - nchars; */
2863 if (read_pure)
2864 return make_pure_string (read_buffer, nchars, p - read_buffer,
2865 (force_multibyte
2866 || (p - read_buffer != nchars)));
2867 return make_specified_string (read_buffer, nchars, p - read_buffer,
2868 (force_multibyte
2869 || (p - read_buffer != nchars)));
2872 case '.':
2874 int next_char = READCHAR;
2875 UNREAD (next_char);
2877 if (next_char <= 040
2878 || (next_char < 0200
2879 && (strchr ("\"';([#?", next_char)
2880 || (!first_in_list && next_char == '`')
2881 || (new_backquote_flag && next_char == ','))))
2883 *pch = c;
2884 return Qnil;
2887 /* Otherwise, we fall through! Note that the atom-reading loop
2888 below will now loop at least once, assuring that we will not
2889 try to UNREAD two characters in a row. */
2891 default:
2892 default_label:
2893 if (c <= 040) goto retry;
2894 if (c == 0x8a0) /* NBSP */
2895 goto retry;
2897 char *p = read_buffer;
2898 int quoted = 0;
2901 char *end = read_buffer + read_buffer_size;
2903 while (c > 040
2904 && c != 0x8a0 /* NBSP */
2905 && (c >= 0200
2906 || (!strchr ("\"';()[]#", c)
2907 && !(!first_in_list && c == '`')
2908 && !(new_backquote_flag && c == ','))))
2910 if (end - p < MAX_MULTIBYTE_LENGTH)
2912 int offset = p - read_buffer;
2913 read_buffer = (char *) xrealloc (read_buffer,
2914 read_buffer_size *= 2);
2915 p = read_buffer + offset;
2916 end = read_buffer + read_buffer_size;
2919 if (c == '\\')
2921 c = READCHAR;
2922 if (c == -1)
2923 end_of_file_error ();
2924 quoted = 1;
2927 if (multibyte)
2928 p += CHAR_STRING (c, p);
2929 else
2930 *p++ = c;
2931 c = READCHAR;
2934 if (p == end)
2936 int offset = p - read_buffer;
2937 read_buffer = (char *) xrealloc (read_buffer,
2938 read_buffer_size *= 2);
2939 p = read_buffer + offset;
2940 end = read_buffer + read_buffer_size;
2942 *p = 0;
2943 if (c >= 0)
2944 UNREAD (c);
2947 if (!quoted && !uninterned_symbol)
2949 register char *p1;
2950 p1 = read_buffer;
2951 if (*p1 == '+' || *p1 == '-') p1++;
2952 /* Is it an integer? */
2953 if (p1 != p)
2955 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
2956 /* Integers can have trailing decimal points. */
2957 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
2958 if (p1 == p)
2959 /* It is an integer. */
2961 if (p1[-1] == '.')
2962 p1[-1] = '\0';
2964 /* EMACS_INT n = atol (read_buffer); */
2965 char *endptr = NULL;
2966 EMACS_INT n = (errno = 0,
2967 strtol (read_buffer, &endptr, 10));
2968 if (errno == ERANGE && endptr)
2970 Lisp_Object args
2971 = Fcons (make_string (read_buffer,
2972 endptr - read_buffer),
2973 Qnil);
2974 xsignal (Qoverflow_error, args);
2976 return make_fixnum_or_float (n);
2980 if (isfloat_string (read_buffer, 0))
2982 /* Compute NaN and infinities using 0.0 in a variable,
2983 to cope with compilers that think they are smarter
2984 than we are. */
2985 double zero = 0.0;
2987 double value;
2989 /* Negate the value ourselves. This treats 0, NaNs,
2990 and infinity properly on IEEE floating point hosts,
2991 and works around a common bug where atof ("-0.0")
2992 drops the sign. */
2993 int negative = read_buffer[0] == '-';
2995 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2996 returns 1, is if the input ends in e+INF or e+NaN. */
2997 switch (p[-1])
2999 case 'F':
3000 value = 1.0 / zero;
3001 break;
3002 case 'N':
3003 value = zero / zero;
3005 /* If that made a "negative" NaN, negate it. */
3008 int i;
3009 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
3011 u_data.d = value;
3012 u_minus_zero.d = - 0.0;
3013 for (i = 0; i < sizeof (double); i++)
3014 if (u_data.c[i] & u_minus_zero.c[i])
3016 value = - value;
3017 break;
3020 /* Now VALUE is a positive NaN. */
3021 break;
3022 default:
3023 value = atof (read_buffer + negative);
3024 break;
3027 return make_float (negative ? - value : value);
3031 Lisp_Object name, result;
3032 EMACS_INT nbytes = p - read_buffer;
3033 EMACS_INT nchars
3034 = (multibyte ? multibyte_chars_in_text (read_buffer, nbytes)
3035 : nbytes);
3037 if (uninterned_symbol && ! NILP (Vpurify_flag))
3038 name = make_pure_string (read_buffer, nchars, nbytes, multibyte);
3039 else
3040 name = make_specified_string (read_buffer, nchars, nbytes,multibyte);
3041 result = (uninterned_symbol ? Fmake_symbol (name)
3042 : Fintern (name, Qnil));
3044 if (EQ (Vread_with_symbol_positions, Qt)
3045 || EQ (Vread_with_symbol_positions, readcharfun))
3046 Vread_symbol_positions_list =
3047 /* Kind of a hack; this will probably fail if characters
3048 in the symbol name were escaped. Not really a big
3049 deal, though. */
3050 Fcons (Fcons (result,
3051 make_number (readchar_count
3052 - XFASTINT (Flength (Fsymbol_name (result))))),
3053 Vread_symbol_positions_list);
3054 return result;
3061 /* List of nodes we've seen during substitute_object_in_subtree. */
3062 static Lisp_Object seen_list;
3064 static void
3065 substitute_object_in_subtree (Lisp_Object object, Lisp_Object placeholder)
3067 Lisp_Object check_object;
3069 /* We haven't seen any objects when we start. */
3070 seen_list = Qnil;
3072 /* Make all the substitutions. */
3073 check_object
3074 = substitute_object_recurse (object, placeholder, object);
3076 /* Clear seen_list because we're done with it. */
3077 seen_list = Qnil;
3079 /* The returned object here is expected to always eq the
3080 original. */
3081 if (!EQ (check_object, object))
3082 error ("Unexpected mutation error in reader");
3085 /* Feval doesn't get called from here, so no gc protection is needed. */
3086 #define SUBSTITUTE(get_val, set_val) \
3087 do { \
3088 Lisp_Object old_value = get_val; \
3089 Lisp_Object true_value \
3090 = substitute_object_recurse (object, placeholder, \
3091 old_value); \
3093 if (!EQ (old_value, true_value)) \
3095 set_val; \
3097 } while (0)
3099 static Lisp_Object
3100 substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Object subtree)
3102 /* If we find the placeholder, return the target object. */
3103 if (EQ (placeholder, subtree))
3104 return object;
3106 /* If we've been to this node before, don't explore it again. */
3107 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
3108 return subtree;
3110 /* If this node can be the entry point to a cycle, remember that
3111 we've seen it. It can only be such an entry point if it was made
3112 by #n=, which means that we can find it as a value in
3113 read_objects. */
3114 if (!EQ (Qnil, Frassq (subtree, read_objects)))
3115 seen_list = Fcons (subtree, seen_list);
3117 /* Recurse according to subtree's type.
3118 Every branch must return a Lisp_Object. */
3119 switch (XTYPE (subtree))
3121 case Lisp_Vectorlike:
3123 int i, length = 0;
3124 if (BOOL_VECTOR_P (subtree))
3125 return subtree; /* No sub-objects anyway. */
3126 else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
3127 || COMPILEDP (subtree))
3128 length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK;
3129 else if (VECTORP (subtree))
3130 length = ASIZE (subtree);
3131 else
3132 /* An unknown pseudovector may contain non-Lisp fields, so we
3133 can't just blindly traverse all its fields. We used to call
3134 `Flength' which signaled `sequencep', so I just preserved this
3135 behavior. */
3136 wrong_type_argument (Qsequencep, subtree);
3138 for (i = 0; i < length; i++)
3139 SUBSTITUTE (AREF (subtree, i),
3140 ASET (subtree, i, true_value));
3141 return subtree;
3144 case Lisp_Cons:
3146 SUBSTITUTE (XCAR (subtree),
3147 XSETCAR (subtree, true_value));
3148 SUBSTITUTE (XCDR (subtree),
3149 XSETCDR (subtree, true_value));
3150 return subtree;
3153 case Lisp_String:
3155 /* Check for text properties in each interval.
3156 substitute_in_interval contains part of the logic. */
3158 INTERVAL root_interval = STRING_INTERVALS (subtree);
3159 Lisp_Object arg = Fcons (object, placeholder);
3161 traverse_intervals_noorder (root_interval,
3162 &substitute_in_interval, arg);
3164 return subtree;
3167 /* Other types don't recurse any further. */
3168 default:
3169 return subtree;
3173 /* Helper function for substitute_object_recurse. */
3174 static void
3175 substitute_in_interval (INTERVAL interval, Lisp_Object arg)
3177 Lisp_Object object = Fcar (arg);
3178 Lisp_Object placeholder = Fcdr (arg);
3180 SUBSTITUTE (interval->plist, interval->plist = true_value);
3184 #define LEAD_INT 1
3185 #define DOT_CHAR 2
3186 #define TRAIL_INT 4
3187 #define E_CHAR 8
3188 #define EXP_INT 16
3191 isfloat_string (const char *cp, int ignore_trailing)
3193 int state;
3194 const char *start = cp;
3196 state = 0;
3197 if (*cp == '+' || *cp == '-')
3198 cp++;
3200 if (*cp >= '0' && *cp <= '9')
3202 state |= LEAD_INT;
3203 while (*cp >= '0' && *cp <= '9')
3204 cp++;
3206 if (*cp == '.')
3208 state |= DOT_CHAR;
3209 cp++;
3211 if (*cp >= '0' && *cp <= '9')
3213 state |= TRAIL_INT;
3214 while (*cp >= '0' && *cp <= '9')
3215 cp++;
3217 if (*cp == 'e' || *cp == 'E')
3219 state |= E_CHAR;
3220 cp++;
3221 if (*cp == '+' || *cp == '-')
3222 cp++;
3225 if (*cp >= '0' && *cp <= '9')
3227 state |= EXP_INT;
3228 while (*cp >= '0' && *cp <= '9')
3229 cp++;
3231 else if (cp == start)
3233 else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
3235 state |= EXP_INT;
3236 cp += 3;
3238 else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
3240 state |= EXP_INT;
3241 cp += 3;
3244 return ((ignore_trailing
3245 || *cp == 0 || *cp == ' ' || *cp == '\t' || *cp == '\n'
3246 || *cp == '\r' || *cp == '\f')
3247 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
3248 || state == (DOT_CHAR|TRAIL_INT)
3249 || state == (LEAD_INT|E_CHAR|EXP_INT)
3250 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
3251 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
3255 static Lisp_Object
3256 read_vector (Lisp_Object readcharfun, int bytecodeflag)
3258 register int i;
3259 register int size;
3260 register Lisp_Object *ptr;
3261 register Lisp_Object tem, item, vector;
3262 register struct Lisp_Cons *otem;
3263 Lisp_Object len;
3265 tem = read_list (1, readcharfun);
3266 len = Flength (tem);
3267 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
3269 size = XVECTOR (vector)->size;
3270 ptr = XVECTOR (vector)->contents;
3271 for (i = 0; i < size; i++)
3273 item = Fcar (tem);
3274 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3275 bytecode object, the docstring containing the bytecode and
3276 constants values must be treated as unibyte and passed to
3277 Fread, to get the actual bytecode string and constants vector. */
3278 if (bytecodeflag && load_force_doc_strings)
3280 if (i == COMPILED_BYTECODE)
3282 if (!STRINGP (item))
3283 error ("Invalid byte code");
3285 /* Delay handling the bytecode slot until we know whether
3286 it is lazily-loaded (we can tell by whether the
3287 constants slot is nil). */
3288 ptr[COMPILED_CONSTANTS] = item;
3289 item = Qnil;
3291 else if (i == COMPILED_CONSTANTS)
3293 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
3295 if (NILP (item))
3297 /* Coerce string to unibyte (like string-as-unibyte,
3298 but without generating extra garbage and
3299 guaranteeing no change in the contents). */
3300 STRING_SET_CHARS (bytestr, SBYTES (bytestr));
3301 STRING_SET_UNIBYTE (bytestr);
3303 item = Fread (Fcons (bytestr, readcharfun));
3304 if (!CONSP (item))
3305 error ("Invalid byte code");
3307 otem = XCONS (item);
3308 bytestr = XCAR (item);
3309 item = XCDR (item);
3310 free_cons (otem);
3313 /* Now handle the bytecode slot. */
3314 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
3316 else if (i == COMPILED_DOC_STRING
3317 && STRINGP (item)
3318 && ! STRING_MULTIBYTE (item))
3320 if (EQ (readcharfun, Qget_emacs_mule_file_char))
3321 item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil);
3322 else
3323 item = Fstring_as_multibyte (item);
3326 ptr[i] = read_pure ? Fpurecopy (item) : item;
3327 otem = XCONS (tem);
3328 tem = Fcdr (tem);
3329 free_cons (otem);
3331 return vector;
3334 /* FLAG = 1 means check for ] to terminate rather than ) and .
3335 FLAG = -1 means check for starting with defun
3336 and make structure pure. */
3338 static Lisp_Object
3339 read_list (int flag, register Lisp_Object readcharfun)
3341 /* -1 means check next element for defun,
3342 0 means don't check,
3343 1 means already checked and found defun. */
3344 int defunflag = flag < 0 ? -1 : 0;
3345 Lisp_Object val, tail;
3346 register Lisp_Object elt, tem;
3347 struct gcpro gcpro1, gcpro2;
3348 /* 0 is the normal case.
3349 1 means this list is a doc reference; replace it with the number 0.
3350 2 means this list is a doc reference; replace it with the doc string. */
3351 int doc_reference = 0;
3353 /* Initialize this to 1 if we are reading a list. */
3354 int first_in_list = flag <= 0;
3356 val = Qnil;
3357 tail = Qnil;
3359 while (1)
3361 int ch;
3362 GCPRO2 (val, tail);
3363 elt = read1 (readcharfun, &ch, first_in_list);
3364 UNGCPRO;
3366 first_in_list = 0;
3368 /* While building, if the list starts with #$, treat it specially. */
3369 if (EQ (elt, Vload_file_name)
3370 && ! NILP (elt)
3371 && !NILP (Vpurify_flag))
3373 if (NILP (Vdoc_file_name))
3374 /* We have not yet called Snarf-documentation, so assume
3375 this file is described in the DOC-MM.NN file
3376 and Snarf-documentation will fill in the right value later.
3377 For now, replace the whole list with 0. */
3378 doc_reference = 1;
3379 else
3380 /* We have already called Snarf-documentation, so make a relative
3381 file name for this file, so it can be found properly
3382 in the installed Lisp directory.
3383 We don't use Fexpand_file_name because that would make
3384 the directory absolute now. */
3385 elt = concat2 (build_string ("../lisp/"),
3386 Ffile_name_nondirectory (elt));
3388 else if (EQ (elt, Vload_file_name)
3389 && ! NILP (elt)
3390 && load_force_doc_strings)
3391 doc_reference = 2;
3393 if (ch)
3395 if (flag > 0)
3397 if (ch == ']')
3398 return val;
3399 invalid_syntax (") or . in a vector", 18);
3401 if (ch == ')')
3402 return val;
3403 if (ch == '.')
3405 GCPRO2 (val, tail);
3406 if (!NILP (tail))
3407 XSETCDR (tail, read0 (readcharfun));
3408 else
3409 val = read0 (readcharfun);
3410 read1 (readcharfun, &ch, 0);
3411 UNGCPRO;
3412 if (ch == ')')
3414 if (doc_reference == 1)
3415 return make_number (0);
3416 if (doc_reference == 2)
3418 /* Get a doc string from the file we are loading.
3419 If it's in saved_doc_string, get it from there.
3421 Here, we don't know if the string is a
3422 bytecode string or a doc string. As a
3423 bytecode string must be unibyte, we always
3424 return a unibyte string. If it is actually a
3425 doc string, caller must make it
3426 multibyte. */
3428 int pos = XINT (XCDR (val));
3429 /* Position is negative for user variables. */
3430 if (pos < 0) pos = -pos;
3431 if (pos >= saved_doc_string_position
3432 && pos < (saved_doc_string_position
3433 + saved_doc_string_length))
3435 int start = pos - saved_doc_string_position;
3436 int from, to;
3438 /* Process quoting with ^A,
3439 and find the end of the string,
3440 which is marked with ^_ (037). */
3441 for (from = start, to = start;
3442 saved_doc_string[from] != 037;)
3444 int c = saved_doc_string[from++];
3445 if (c == 1)
3447 c = saved_doc_string[from++];
3448 if (c == 1)
3449 saved_doc_string[to++] = c;
3450 else if (c == '0')
3451 saved_doc_string[to++] = 0;
3452 else if (c == '_')
3453 saved_doc_string[to++] = 037;
3455 else
3456 saved_doc_string[to++] = c;
3459 return make_unibyte_string (saved_doc_string + start,
3460 to - start);
3462 /* Look in prev_saved_doc_string the same way. */
3463 else if (pos >= prev_saved_doc_string_position
3464 && pos < (prev_saved_doc_string_position
3465 + prev_saved_doc_string_length))
3467 int start = pos - prev_saved_doc_string_position;
3468 int from, to;
3470 /* Process quoting with ^A,
3471 and find the end of the string,
3472 which is marked with ^_ (037). */
3473 for (from = start, to = start;
3474 prev_saved_doc_string[from] != 037;)
3476 int c = prev_saved_doc_string[from++];
3477 if (c == 1)
3479 c = prev_saved_doc_string[from++];
3480 if (c == 1)
3481 prev_saved_doc_string[to++] = c;
3482 else if (c == '0')
3483 prev_saved_doc_string[to++] = 0;
3484 else if (c == '_')
3485 prev_saved_doc_string[to++] = 037;
3487 else
3488 prev_saved_doc_string[to++] = c;
3491 return make_unibyte_string (prev_saved_doc_string
3492 + start,
3493 to - start);
3495 else
3496 return get_doc_string (val, 1, 0);
3499 return val;
3501 invalid_syntax (". in wrong context", 18);
3503 invalid_syntax ("] in a list", 11);
3505 tem = (read_pure && flag <= 0
3506 ? pure_cons (elt, Qnil)
3507 : Fcons (elt, Qnil));
3508 if (!NILP (tail))
3509 XSETCDR (tail, tem);
3510 else
3511 val = tem;
3512 tail = tem;
3513 if (defunflag < 0)
3514 defunflag = EQ (elt, Qdefun);
3515 else if (defunflag > 0)
3516 read_pure = 1;
3520 Lisp_Object Vobarray;
3521 Lisp_Object initial_obarray;
3523 /* oblookup stores the bucket number here, for the sake of Funintern. */
3525 int oblookup_last_bucket_number;
3527 static int hash_string (const unsigned char *ptr, int len);
3529 /* Get an error if OBARRAY is not an obarray.
3530 If it is one, return it. */
3532 Lisp_Object
3533 check_obarray (Lisp_Object obarray)
3535 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3537 /* If Vobarray is now invalid, force it to be valid. */
3538 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
3539 wrong_type_argument (Qvectorp, obarray);
3541 return obarray;
3544 /* Intern the C string STR: return a symbol with that name,
3545 interned in the current obarray. */
3547 Lisp_Object
3548 intern (const char *str)
3550 Lisp_Object tem;
3551 int len = strlen (str);
3552 Lisp_Object obarray;
3554 obarray = Vobarray;
3555 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3556 obarray = check_obarray (obarray);
3557 tem = oblookup (obarray, str, len, len);
3558 if (SYMBOLP (tem))
3559 return tem;
3560 return Fintern (make_string (str, len), obarray);
3563 Lisp_Object
3564 intern_c_string (const char *str)
3566 Lisp_Object tem;
3567 int len = strlen (str);
3568 Lisp_Object obarray;
3570 obarray = Vobarray;
3571 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3572 obarray = check_obarray (obarray);
3573 tem = oblookup (obarray, str, len, len);
3574 if (SYMBOLP (tem))
3575 return tem;
3577 if (NILP (Vpurify_flag))
3578 /* Creating a non-pure string from a string literal not
3579 implemented yet. We could just use make_string here and live
3580 with the extra copy. */
3581 abort ();
3583 return Fintern (make_pure_c_string (str), obarray);
3586 /* Create an uninterned symbol with name STR. */
3588 Lisp_Object
3589 make_symbol (const char *str)
3591 int len = strlen (str);
3593 return Fmake_symbol (!NILP (Vpurify_flag)
3594 ? make_pure_string (str, len, len, 0)
3595 : make_string (str, len));
3598 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
3599 doc: /* Return the canonical symbol whose name is STRING.
3600 If there is none, one is created by this function and returned.
3601 A second optional argument specifies the obarray to use;
3602 it defaults to the value of `obarray'. */)
3603 (Lisp_Object string, Lisp_Object obarray)
3605 register Lisp_Object tem, sym, *ptr;
3607 if (NILP (obarray)) obarray = Vobarray;
3608 obarray = check_obarray (obarray);
3610 CHECK_STRING (string);
3612 tem = oblookup (obarray, SDATA (string),
3613 SCHARS (string),
3614 SBYTES (string));
3615 if (!INTEGERP (tem))
3616 return tem;
3618 if (!NILP (Vpurify_flag))
3619 string = Fpurecopy (string);
3620 sym = Fmake_symbol (string);
3622 if (EQ (obarray, initial_obarray))
3623 XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3624 else
3625 XSYMBOL (sym)->interned = SYMBOL_INTERNED;
3627 if ((SREF (string, 0) == ':')
3628 && EQ (obarray, initial_obarray))
3630 XSYMBOL (sym)->constant = 1;
3631 XSYMBOL (sym)->redirect = SYMBOL_PLAINVAL;
3632 SET_SYMBOL_VAL (XSYMBOL (sym), sym);
3635 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
3636 if (SYMBOLP (*ptr))
3637 XSYMBOL (sym)->next = XSYMBOL (*ptr);
3638 else
3639 XSYMBOL (sym)->next = 0;
3640 *ptr = sym;
3641 return sym;
3644 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
3645 doc: /* Return the canonical symbol named NAME, or nil if none exists.
3646 NAME may be a string or a symbol. If it is a symbol, that exact
3647 symbol is searched for.
3648 A second optional argument specifies the obarray to use;
3649 it defaults to the value of `obarray'. */)
3650 (Lisp_Object name, Lisp_Object obarray)
3652 register Lisp_Object tem, string;
3654 if (NILP (obarray)) obarray = Vobarray;
3655 obarray = check_obarray (obarray);
3657 if (!SYMBOLP (name))
3659 CHECK_STRING (name);
3660 string = name;
3662 else
3663 string = SYMBOL_NAME (name);
3665 tem = oblookup (obarray, SDATA (string), SCHARS (string), SBYTES (string));
3666 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
3667 return Qnil;
3668 else
3669 return tem;
3672 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
3673 doc: /* Delete the symbol named NAME, if any, from OBARRAY.
3674 The value is t if a symbol was found and deleted, nil otherwise.
3675 NAME may be a string or a symbol. If it is a symbol, that symbol
3676 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3677 OBARRAY defaults to the value of the variable `obarray'. */)
3678 (Lisp_Object name, Lisp_Object obarray)
3680 register Lisp_Object string, tem;
3681 int hash;
3683 if (NILP (obarray)) obarray = Vobarray;
3684 obarray = check_obarray (obarray);
3686 if (SYMBOLP (name))
3687 string = SYMBOL_NAME (name);
3688 else
3690 CHECK_STRING (name);
3691 string = name;
3694 tem = oblookup (obarray, SDATA (string),
3695 SCHARS (string),
3696 SBYTES (string));
3697 if (INTEGERP (tem))
3698 return Qnil;
3699 /* If arg was a symbol, don't delete anything but that symbol itself. */
3700 if (SYMBOLP (name) && !EQ (name, tem))
3701 return Qnil;
3703 /* There are plenty of other symbols which will screw up the Emacs
3704 session if we unintern them, as well as even more ways to use
3705 `setq' or `fset' or whatnot to make the Emacs session
3706 unusable. Let's not go down this silly road. --Stef */
3707 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
3708 error ("Attempt to unintern t or nil"); */
3710 XSYMBOL (tem)->interned = SYMBOL_UNINTERNED;
3712 hash = oblookup_last_bucket_number;
3714 if (EQ (XVECTOR (obarray)->contents[hash], tem))
3716 if (XSYMBOL (tem)->next)
3717 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
3718 else
3719 XSETINT (XVECTOR (obarray)->contents[hash], 0);
3721 else
3723 Lisp_Object tail, following;
3725 for (tail = XVECTOR (obarray)->contents[hash];
3726 XSYMBOL (tail)->next;
3727 tail = following)
3729 XSETSYMBOL (following, XSYMBOL (tail)->next);
3730 if (EQ (following, tem))
3732 XSYMBOL (tail)->next = XSYMBOL (following)->next;
3733 break;
3738 return Qt;
3741 /* Return the symbol in OBARRAY whose names matches the string
3742 of SIZE characters (SIZE_BYTE bytes) at PTR.
3743 If there is no such symbol in OBARRAY, return nil.
3745 Also store the bucket number in oblookup_last_bucket_number. */
3747 Lisp_Object
3748 oblookup (Lisp_Object obarray, register const char *ptr, int size, int size_byte)
3750 int hash;
3751 int obsize;
3752 register Lisp_Object tail;
3753 Lisp_Object bucket, tem;
3755 if (!VECTORP (obarray)
3756 || (obsize = XVECTOR (obarray)->size) == 0)
3758 obarray = check_obarray (obarray);
3759 obsize = XVECTOR (obarray)->size;
3761 /* This is sometimes needed in the middle of GC. */
3762 obsize &= ~ARRAY_MARK_FLAG;
3763 hash = hash_string (ptr, size_byte) % obsize;
3764 bucket = XVECTOR (obarray)->contents[hash];
3765 oblookup_last_bucket_number = hash;
3766 if (EQ (bucket, make_number (0)))
3768 else if (!SYMBOLP (bucket))
3769 error ("Bad data in guts of obarray"); /* Like CADR error message */
3770 else
3771 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
3773 if (SBYTES (SYMBOL_NAME (tail)) == size_byte
3774 && SCHARS (SYMBOL_NAME (tail)) == size
3775 && !memcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
3776 return tail;
3777 else if (XSYMBOL (tail)->next == 0)
3778 break;
3780 XSETINT (tem, hash);
3781 return tem;
3784 static int
3785 hash_string (const unsigned char *ptr, int len)
3787 register const unsigned char *p = ptr;
3788 register const unsigned char *end = p + len;
3789 register unsigned char c;
3790 register int hash = 0;
3792 while (p != end)
3794 c = *p++;
3795 if (c >= 0140) c -= 40;
3796 hash = ((hash<<3) + (hash>>28) + c);
3798 return hash & 07777777777;
3801 void
3802 map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg)
3804 register int i;
3805 register Lisp_Object tail;
3806 CHECK_VECTOR (obarray);
3807 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
3809 tail = XVECTOR (obarray)->contents[i];
3810 if (SYMBOLP (tail))
3811 while (1)
3813 (*fn) (tail, arg);
3814 if (XSYMBOL (tail)->next == 0)
3815 break;
3816 XSETSYMBOL (tail, XSYMBOL (tail)->next);
3821 void
3822 mapatoms_1 (Lisp_Object sym, Lisp_Object function)
3824 call1 (function, sym);
3827 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
3828 doc: /* Call FUNCTION on every symbol in OBARRAY.
3829 OBARRAY defaults to the value of `obarray'. */)
3830 (Lisp_Object function, Lisp_Object obarray)
3832 if (NILP (obarray)) obarray = Vobarray;
3833 obarray = check_obarray (obarray);
3835 map_obarray (obarray, mapatoms_1, function);
3836 return Qnil;
3839 #define OBARRAY_SIZE 1511
3841 void
3842 init_obarray (void)
3844 Lisp_Object oblength;
3846 XSETFASTINT (oblength, OBARRAY_SIZE);
3848 Vobarray = Fmake_vector (oblength, make_number (0));
3849 initial_obarray = Vobarray;
3850 staticpro (&initial_obarray);
3852 Qunbound = Fmake_symbol (make_pure_c_string ("unbound"));
3853 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the
3854 NILP (Vpurify_flag) check in intern_c_string. */
3855 Qnil = make_number (-1); Vpurify_flag = make_number (1);
3856 Qnil = intern_c_string ("nil");
3858 /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil,
3859 so those two need to be fixed manally. */
3860 SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound);
3861 XSYMBOL (Qunbound)->function = Qunbound;
3862 XSYMBOL (Qunbound)->plist = Qnil;
3863 /* XSYMBOL (Qnil)->function = Qunbound; */
3864 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil);
3865 XSYMBOL (Qnil)->constant = 1;
3866 XSYMBOL (Qnil)->plist = Qnil;
3868 Qt = intern_c_string ("t");
3869 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt);
3870 XSYMBOL (Qt)->constant = 1;
3872 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3873 Vpurify_flag = Qt;
3875 Qvariable_documentation = intern_c_string ("variable-documentation");
3876 staticpro (&Qvariable_documentation);
3878 read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
3879 read_buffer = (char *) xmalloc (read_buffer_size);
3882 void
3883 defsubr (struct Lisp_Subr *sname)
3885 Lisp_Object sym;
3886 sym = intern_c_string (sname->symbol_name);
3887 XSETPVECTYPE (sname, PVEC_SUBR);
3888 XSETSUBR (XSYMBOL (sym)->function, sname);
3891 #ifdef NOTDEF /* use fset in subr.el now */
3892 void
3893 defalias (sname, string)
3894 struct Lisp_Subr *sname;
3895 char *string;
3897 Lisp_Object sym;
3898 sym = intern (string);
3899 XSETSUBR (XSYMBOL (sym)->function, sname);
3901 #endif /* NOTDEF */
3903 /* Define an "integer variable"; a symbol whose value is forwarded
3904 to a C variable of type int. Sample call:
3905 DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
3906 void
3907 defvar_int (struct Lisp_Intfwd *i_fwd,
3908 const char *namestring, EMACS_INT *address)
3910 Lisp_Object sym;
3911 sym = intern_c_string (namestring);
3912 i_fwd->type = Lisp_Fwd_Int;
3913 i_fwd->intvar = address;
3914 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3915 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)i_fwd);
3918 /* Similar but define a variable whose value is t if address contains 1,
3919 nil if address contains 0. */
3920 void
3921 defvar_bool (struct Lisp_Boolfwd *b_fwd,
3922 const char *namestring, int *address)
3924 Lisp_Object sym;
3925 sym = intern_c_string (namestring);
3926 b_fwd->type = Lisp_Fwd_Bool;
3927 b_fwd->boolvar = address;
3928 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3929 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)b_fwd);
3930 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
3933 /* Similar but define a variable whose value is the Lisp Object stored
3934 at address. Two versions: with and without gc-marking of the C
3935 variable. The nopro version is used when that variable will be
3936 gc-marked for some other reason, since marking the same slot twice
3937 can cause trouble with strings. */
3938 void
3939 defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd,
3940 const char *namestring, Lisp_Object *address)
3942 Lisp_Object sym;
3943 sym = intern_c_string (namestring);
3944 o_fwd->type = Lisp_Fwd_Obj;
3945 o_fwd->objvar = address;
3946 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3947 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)o_fwd);
3950 void
3951 defvar_lisp (struct Lisp_Objfwd *o_fwd,
3952 const char *namestring, Lisp_Object *address)
3954 defvar_lisp_nopro (o_fwd, namestring, address);
3955 staticpro (address);
3958 /* Similar but define a variable whose value is the Lisp Object stored
3959 at a particular offset in the current kboard object. */
3961 void
3962 defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd,
3963 const char *namestring, int offset)
3965 Lisp_Object sym;
3966 sym = intern_c_string (namestring);
3967 ko_fwd->type = Lisp_Fwd_Kboard_Obj;
3968 ko_fwd->offset = offset;
3969 XSYMBOL (sym)->redirect = SYMBOL_FORWARDED;
3970 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd);
3973 /* Record the value of load-path used at the start of dumping
3974 so we can see if the site changed it later during dumping. */
3975 static Lisp_Object dump_path;
3977 void
3978 init_lread (void)
3980 char *normal;
3981 int turn_off_warning = 0;
3983 /* Compute the default load-path. */
3984 #ifdef CANNOT_DUMP
3985 normal = PATH_LOADSEARCH;
3986 Vload_path = decode_env_path (0, normal);
3987 #else
3988 if (NILP (Vpurify_flag))
3989 normal = PATH_LOADSEARCH;
3990 else
3991 normal = PATH_DUMPLOADSEARCH;
3993 /* In a dumped Emacs, we normally have to reset the value of
3994 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3995 uses ../lisp, instead of the path of the installed elisp
3996 libraries. However, if it appears that Vload_path was changed
3997 from the default before dumping, don't override that value. */
3998 if (initialized)
4000 if (! NILP (Fequal (dump_path, Vload_path)))
4002 Vload_path = decode_env_path (0, normal);
4003 if (!NILP (Vinstallation_directory))
4005 Lisp_Object tem, tem1, sitelisp;
4007 /* Remove site-lisp dirs from path temporarily and store
4008 them in sitelisp, then conc them on at the end so
4009 they're always first in path. */
4010 sitelisp = Qnil;
4011 while (1)
4013 tem = Fcar (Vload_path);
4014 tem1 = Fstring_match (build_string ("site-lisp"),
4015 tem, Qnil);
4016 if (!NILP (tem1))
4018 Vload_path = Fcdr (Vload_path);
4019 sitelisp = Fcons (tem, sitelisp);
4021 else
4022 break;
4025 /* Add to the path the lisp subdir of the
4026 installation dir, if it exists. */
4027 tem = Fexpand_file_name (build_string ("lisp"),
4028 Vinstallation_directory);
4029 tem1 = Ffile_exists_p (tem);
4030 if (!NILP (tem1))
4032 if (NILP (Fmember (tem, Vload_path)))
4034 turn_off_warning = 1;
4035 Vload_path = Fcons (tem, Vload_path);
4038 else
4039 /* That dir doesn't exist, so add the build-time
4040 Lisp dirs instead. */
4041 Vload_path = nconc2 (Vload_path, dump_path);
4043 /* Add leim under the installation dir, if it exists. */
4044 tem = Fexpand_file_name (build_string ("leim"),
4045 Vinstallation_directory);
4046 tem1 = Ffile_exists_p (tem);
4047 if (!NILP (tem1))
4049 if (NILP (Fmember (tem, Vload_path)))
4050 Vload_path = Fcons (tem, Vload_path);
4053 /* Add site-lisp under the installation dir, if it exists. */
4054 tem = Fexpand_file_name (build_string ("site-lisp"),
4055 Vinstallation_directory);
4056 tem1 = Ffile_exists_p (tem);
4057 if (!NILP (tem1))
4059 if (NILP (Fmember (tem, Vload_path)))
4060 Vload_path = Fcons (tem, Vload_path);
4063 /* If Emacs was not built in the source directory,
4064 and it is run from where it was built, add to load-path
4065 the lisp, leim and site-lisp dirs under that directory. */
4067 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
4069 Lisp_Object tem2;
4071 tem = Fexpand_file_name (build_string ("src/Makefile"),
4072 Vinstallation_directory);
4073 tem1 = Ffile_exists_p (tem);
4075 /* Don't be fooled if they moved the entire source tree
4076 AFTER dumping Emacs. If the build directory is indeed
4077 different from the source dir, src/Makefile.in and
4078 src/Makefile will not be found together. */
4079 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
4080 Vinstallation_directory);
4081 tem2 = Ffile_exists_p (tem);
4082 if (!NILP (tem1) && NILP (tem2))
4084 tem = Fexpand_file_name (build_string ("lisp"),
4085 Vsource_directory);
4087 if (NILP (Fmember (tem, Vload_path)))
4088 Vload_path = Fcons (tem, Vload_path);
4090 tem = Fexpand_file_name (build_string ("leim"),
4091 Vsource_directory);
4093 if (NILP (Fmember (tem, Vload_path)))
4094 Vload_path = Fcons (tem, Vload_path);
4096 tem = Fexpand_file_name (build_string ("site-lisp"),
4097 Vsource_directory);
4099 if (NILP (Fmember (tem, Vload_path)))
4100 Vload_path = Fcons (tem, Vload_path);
4103 if (!NILP (sitelisp))
4104 Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path);
4108 else
4110 /* NORMAL refers to the lisp dir in the source directory. */
4111 /* We used to add ../lisp at the front here, but
4112 that caused trouble because it was copied from dump_path
4113 into Vload_path, above, when Vinstallation_directory was non-nil.
4114 It should be unnecessary. */
4115 Vload_path = decode_env_path (0, normal);
4116 dump_path = Vload_path;
4118 #endif
4120 #if (!(defined (WINDOWSNT) || (defined (HAVE_NS))))
4121 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
4122 almost never correct, thereby causing a warning to be printed out that
4123 confuses users. Since PATH_LOADSEARCH is always overridden by the
4124 EMACSLOADPATH environment variable below, disable the warning on NT. */
4126 /* Warn if dirs in the *standard* path don't exist. */
4127 if (!turn_off_warning)
4129 Lisp_Object path_tail;
4131 for (path_tail = Vload_path;
4132 !NILP (path_tail);
4133 path_tail = XCDR (path_tail))
4135 Lisp_Object dirfile;
4136 dirfile = Fcar (path_tail);
4137 if (STRINGP (dirfile))
4139 dirfile = Fdirectory_file_name (dirfile);
4140 if (access (SDATA (dirfile), 0) < 0)
4141 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4142 XCAR (path_tail));
4146 #endif /* !(WINDOWSNT || HAVE_NS) */
4148 /* If the EMACSLOADPATH environment variable is set, use its value.
4149 This doesn't apply if we're dumping. */
4150 #ifndef CANNOT_DUMP
4151 if (NILP (Vpurify_flag)
4152 && egetenv ("EMACSLOADPATH"))
4153 #endif
4154 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4156 Vvalues = Qnil;
4158 load_in_progress = 0;
4159 Vload_file_name = Qnil;
4161 load_descriptor_list = Qnil;
4163 Vstandard_input = Qt;
4164 Vloads_in_progress = Qnil;
4167 /* Print a warning, using format string FORMAT, that directory DIRNAME
4168 does not exist. Print it on stderr and put it in *Messages*. */
4170 void
4171 dir_warning (const char *format, Lisp_Object dirname)
4173 char *buffer
4174 = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);
4176 fprintf (stderr, format, SDATA (dirname));
4177 sprintf (buffer, format, SDATA (dirname));
4178 /* Don't log the warning before we've initialized!! */
4179 if (initialized)
4180 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
4183 void
4184 syms_of_lread (void)
4186 defsubr (&Sread);
4187 defsubr (&Sread_from_string);
4188 defsubr (&Sintern);
4189 defsubr (&Sintern_soft);
4190 defsubr (&Sunintern);
4191 defsubr (&Sget_load_suffixes);
4192 defsubr (&Sload);
4193 defsubr (&Seval_buffer);
4194 defsubr (&Seval_region);
4195 defsubr (&Sread_char);
4196 defsubr (&Sread_char_exclusive);
4197 defsubr (&Sread_event);
4198 defsubr (&Sget_file_char);
4199 defsubr (&Smapatoms);
4200 defsubr (&Slocate_file_internal);
4202 DEFVAR_LISP ("obarray", &Vobarray,
4203 doc: /* Symbol table for use by `intern' and `read'.
4204 It is a vector whose length ought to be prime for best results.
4205 The vector's contents don't make sense if examined from Lisp programs;
4206 to find all the symbols in an obarray, use `mapatoms'. */);
4208 DEFVAR_LISP ("values", &Vvalues,
4209 doc: /* List of values of all expressions which were read, evaluated and printed.
4210 Order is reverse chronological. */);
4212 DEFVAR_LISP ("standard-input", &Vstandard_input,
4213 doc: /* Stream for read to get input from.
4214 See documentation of `read' for possible values. */);
4215 Vstandard_input = Qt;
4217 DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions,
4218 doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4220 If this variable is a buffer, then only forms read from that buffer
4221 will be added to `read-symbol-positions-list'.
4222 If this variable is t, then all read forms will be added.
4223 The effect of all other values other than nil are not currently
4224 defined, although they may be in the future.
4226 The positions are relative to the last call to `read' or
4227 `read-from-string'. It is probably a bad idea to set this variable at
4228 the toplevel; bind it instead. */);
4229 Vread_with_symbol_positions = Qnil;
4231 DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list,
4232 doc: /* A list mapping read symbols to their positions.
4233 This variable is modified during calls to `read' or
4234 `read-from-string', but only when `read-with-symbol-positions' is
4235 non-nil.
4237 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4238 CHAR-POSITION is an integer giving the offset of that occurrence of the
4239 symbol from the position where `read' or `read-from-string' started.
4241 Note that a symbol will appear multiple times in this list, if it was
4242 read multiple times. The list is in the same order as the symbols
4243 were read in. */);
4244 Vread_symbol_positions_list = Qnil;
4246 DEFVAR_LISP ("read-circle", &Vread_circle,
4247 doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4248 Vread_circle = Qt;
4250 DEFVAR_LISP ("load-path", &Vload_path,
4251 doc: /* *List of directories to search for files to load.
4252 Each element is a string (directory name) or nil (try default directory).
4253 Initialized based on EMACSLOADPATH environment variable, if any,
4254 otherwise to default specified by file `epaths.h' when Emacs was built. */);
4256 DEFVAR_LISP ("load-suffixes", &Vload_suffixes,
4257 doc: /* List of suffixes for (compiled or source) Emacs Lisp files.
4258 This list should not include the empty string.
4259 `load' and related functions try to append these suffixes, in order,
4260 to the specified file name if a Lisp suffix is allowed or required. */);
4261 Vload_suffixes = Fcons (make_pure_c_string (".elc"),
4262 Fcons (make_pure_c_string (".el"), Qnil));
4263 DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes,
4264 doc: /* List of suffixes that indicate representations of \
4265 the same file.
4266 This list should normally start with the empty string.
4268 Enabling Auto Compression mode appends the suffixes in
4269 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4270 mode removes them again. `load' and related functions use this list to
4271 determine whether they should look for compressed versions of a file
4272 and, if so, which suffixes they should try to append to the file name
4273 in order to do so. However, if you want to customize which suffixes
4274 the loading functions recognize as compression suffixes, you should
4275 customize `jka-compr-load-suffixes' rather than the present variable. */);
4276 Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil);
4278 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
4279 doc: /* Non-nil if inside of `load'. */);
4280 Qload_in_progress = intern_c_string ("load-in-progress");
4281 staticpro (&Qload_in_progress);
4283 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
4284 doc: /* An alist of expressions to be evalled when particular files are loaded.
4285 Each element looks like (REGEXP-OR-FEATURE FORMS...).
4287 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4288 a symbol \(a feature name).
4290 When `load' is run and the file-name argument matches an element's
4291 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4292 REGEXP-OR-FEATURE, the FORMS in the element are executed.
4294 An error in FORMS does not undo the load, but does prevent execution of
4295 the rest of the FORMS. */);
4296 Vafter_load_alist = Qnil;
4298 DEFVAR_LISP ("load-history", &Vload_history,
4299 doc: /* Alist mapping loaded file names to symbols and features.
4300 Each alist element should be a list (FILE-NAME ENTRIES...), where
4301 FILE-NAME is the name of a file that has been loaded into Emacs.
4302 The file name is absolute and true (i.e. it doesn't contain symlinks).
4303 As an exception, one of the alist elements may have FILE-NAME nil,
4304 for symbols and features not associated with any file.
4306 The remaining ENTRIES in the alist element describe the functions and
4307 variables defined in that file, the features provided, and the
4308 features required. Each entry has the form `(provide . FEATURE)',
4309 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4310 `(defface . SYMBOL)', or `(t . SYMBOL)'. In addition, an entry `(t
4311 . SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
4312 SYMBOL was an autoload before this file redefined it as a function.
4314 During preloading, the file name recorded is relative to the main Lisp
4315 directory. These file names are converted to absolute at startup. */);
4316 Vload_history = Qnil;
4318 DEFVAR_LISP ("load-file-name", &Vload_file_name,
4319 doc: /* Full name of file being loaded by `load'. */);
4320 Vload_file_name = Qnil;
4322 DEFVAR_LISP ("user-init-file", &Vuser_init_file,
4323 doc: /* File name, including directory, of user's initialization file.
4324 If the file loaded had extension `.elc', and the corresponding source file
4325 exists, this variable contains the name of source file, suitable for use
4326 by functions like `custom-save-all' which edit the init file.
4327 While Emacs loads and evaluates the init file, value is the real name
4328 of the file, regardless of whether or not it has the `.elc' extension. */);
4329 Vuser_init_file = Qnil;
4331 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
4332 doc: /* Used for internal purposes by `load'. */);
4333 Vcurrent_load_list = Qnil;
4335 DEFVAR_LISP ("load-read-function", &Vload_read_function,
4336 doc: /* Function used by `load' and `eval-region' for reading expressions.
4337 The default is nil, which means use the function `read'. */);
4338 Vload_read_function = Qnil;
4340 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
4341 doc: /* Function called in `load' for loading an Emacs Lisp source file.
4342 This function is for doing code conversion before reading the source file.
4343 If nil, loading is done without any code conversion.
4344 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
4345 FULLNAME is the full name of FILE.
4346 See `load' for the meaning of the remaining arguments. */);
4347 Vload_source_file_function = Qnil;
4349 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
4350 doc: /* Non-nil means `load' should force-load all dynamic doc strings.
4351 This is useful when the file being loaded is a temporary copy. */);
4352 load_force_doc_strings = 0;
4354 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
4355 doc: /* Non-nil means `read' converts strings to unibyte whenever possible.
4356 This is normally bound by `load' and `eval-buffer' to control `read',
4357 and is not meant for users to change. */);
4358 load_convert_to_unibyte = 0;
4360 DEFVAR_LISP ("source-directory", &Vsource_directory,
4361 doc: /* Directory in which Emacs sources were found when Emacs was built.
4362 You cannot count on them to still be there! */);
4363 Vsource_directory
4364 = Fexpand_file_name (build_string ("../"),
4365 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
4367 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
4368 doc: /* List of files that were preloaded (when dumping Emacs). */);
4369 Vpreloaded_file_list = Qnil;
4371 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
4372 doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4373 Vbyte_boolean_vars = Qnil;
4375 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries,
4376 doc: /* Non-nil means load dangerous compiled Lisp files.
4377 Some versions of XEmacs use different byte codes than Emacs. These
4378 incompatible byte codes can make Emacs crash when it tries to execute
4379 them. */);
4380 load_dangerous_libraries = 0;
4382 DEFVAR_BOOL ("force-load-messages", &force_load_messages,
4383 doc: /* Non-nil means force printing messages when loading Lisp files.
4384 This overrides the value of the NOMESSAGE argument to `load'. */);
4385 force_load_messages = 0;
4387 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp,
4388 doc: /* Regular expression matching safe to load compiled Lisp files.
4389 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4390 from the file, and matches them against this regular expression.
4391 When the regular expression matches, the file is considered to be safe
4392 to load. See also `load-dangerous-libraries'. */);
4393 Vbytecomp_version_regexp
4394 = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4396 DEFVAR_LISP ("eval-buffer-list", &Veval_buffer_list,
4397 doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4398 Veval_buffer_list = Qnil;
4400 DEFVAR_LISP ("old-style-backquotes", &Vold_style_backquotes,
4401 doc: /* Set to non-nil when `read' encounters an old-style backquote. */);
4402 Vold_style_backquotes = Qnil;
4403 Qold_style_backquotes = intern_c_string ("old-style-backquotes");
4404 staticpro (&Qold_style_backquotes);
4406 /* Vsource_directory was initialized in init_lread. */
4408 load_descriptor_list = Qnil;
4409 staticpro (&load_descriptor_list);
4411 Qcurrent_load_list = intern_c_string ("current-load-list");
4412 staticpro (&Qcurrent_load_list);
4414 Qstandard_input = intern_c_string ("standard-input");
4415 staticpro (&Qstandard_input);
4417 Qread_char = intern_c_string ("read-char");
4418 staticpro (&Qread_char);
4420 Qget_file_char = intern_c_string ("get-file-char");
4421 staticpro (&Qget_file_char);
4423 Qget_emacs_mule_file_char = intern_c_string ("get-emacs-mule-file-char");
4424 staticpro (&Qget_emacs_mule_file_char);
4426 Qload_force_doc_strings = intern_c_string ("load-force-doc-strings");
4427 staticpro (&Qload_force_doc_strings);
4429 Qbackquote = intern_c_string ("`");
4430 staticpro (&Qbackquote);
4431 Qcomma = intern_c_string (",");
4432 staticpro (&Qcomma);
4433 Qcomma_at = intern_c_string (",@");
4434 staticpro (&Qcomma_at);
4435 Qcomma_dot = intern_c_string (",.");
4436 staticpro (&Qcomma_dot);
4438 Qinhibit_file_name_operation = intern_c_string ("inhibit-file-name-operation");
4439 staticpro (&Qinhibit_file_name_operation);
4441 Qascii_character = intern_c_string ("ascii-character");
4442 staticpro (&Qascii_character);
4444 Qfunction = intern_c_string ("function");
4445 staticpro (&Qfunction);
4447 Qload = intern_c_string ("load");
4448 staticpro (&Qload);
4450 Qload_file_name = intern_c_string ("load-file-name");
4451 staticpro (&Qload_file_name);
4453 Qeval_buffer_list = intern_c_string ("eval-buffer-list");
4454 staticpro (&Qeval_buffer_list);
4456 Qfile_truename = intern_c_string ("file-truename");
4457 staticpro (&Qfile_truename) ;
4459 Qdo_after_load_evaluation = intern_c_string ("do-after-load-evaluation");
4460 staticpro (&Qdo_after_load_evaluation) ;
4462 staticpro (&dump_path);
4464 staticpro (&read_objects);
4465 read_objects = Qnil;
4466 staticpro (&seen_list);
4467 seen_list = Qnil;
4469 Vloads_in_progress = Qnil;
4470 staticpro (&Vloads_in_progress);
4472 Qhash_table = intern_c_string ("hash-table");
4473 staticpro (&Qhash_table);
4474 Qdata = intern_c_string ("data");
4475 staticpro (&Qdata);
4476 Qtest = intern_c_string ("test");
4477 staticpro (&Qtest);
4478 Qsize = intern_c_string ("size");
4479 staticpro (&Qsize);
4480 Qweakness = intern_c_string ("weakness");
4481 staticpro (&Qweakness);
4482 Qrehash_size = intern_c_string ("rehash-size");
4483 staticpro (&Qrehash_size);
4484 Qrehash_threshold = intern_c_string ("rehash-threshold");
4485 staticpro (&Qrehash_threshold);
4488 /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d
4489 (do not change this comment) */