Don't remove highlight of misspelled word on pdict save
[emacs.git] / src / lread.c
blob72523c057f17ddc399d508172611f9f1f3c3b582
1 /* Lisp parsing and input streams.
3 Copyright (C) 1985-1989, 1993-1995, 1997-2018 Free Software Foundation,
4 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 (at
11 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 <https://www.gnu.org/licenses/>. */
21 /* Tell globals.h to define tables needed by init_obarray. */
22 #define DEFINE_SYMBOLS
24 #include <config.h>
25 #include "sysstdio.h"
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <sys/file.h>
30 #include <errno.h>
31 #include <math.h>
32 #include <stat-time.h>
33 #include "lisp.h"
34 #include "dispextern.h"
35 #include "intervals.h"
36 #include "character.h"
37 #include "buffer.h"
38 #include "charset.h"
39 #include <epaths.h>
40 #include "commands.h"
41 #include "keyboard.h"
42 #include "systime.h"
43 #include "termhooks.h"
44 #include "blockinput.h"
45 #include <c-ctype.h>
47 #ifdef MSDOS
48 #include "msdos.h"
49 #if __DJGPP__ == 2 && __DJGPP_MINOR__ < 5
50 # define INFINITY __builtin_inf()
51 # define NAN __builtin_nan("")
52 #endif
53 #endif
55 #ifdef HAVE_NS
56 #include "nsterm.h"
57 #endif
59 #include <unistd.h>
61 #ifdef HAVE_SETLOCALE
62 #include <locale.h>
63 #endif /* HAVE_SETLOCALE */
65 #include <fcntl.h>
67 #ifdef HAVE_FSEEKO
68 #define file_offset off_t
69 #define file_tell ftello
70 #else
71 #define file_offset long
72 #define file_tell ftell
73 #endif
75 /* The objects or placeholders read with the #n=object form.
77 A hash table maps a number to either a placeholder (while the
78 object is still being parsed, in case it's referenced within its
79 own definition) or to the completed object. With small integers
80 for keys, it's effectively little more than a vector, but it'll
81 manage any needed resizing for us.
83 The variable must be reset to an empty hash table before all
84 top-level calls to read0. In between calls, it may be an empty
85 hash table left unused from the previous call (to reduce
86 allocations), or nil. */
87 static Lisp_Object read_objects_map;
89 /* The recursive objects read with the #n=object form.
91 Objects that might have circular references are stored here, so
92 that recursive substitution knows not to keep processing them
93 multiple times.
95 Only objects that are completely processed, including substituting
96 references to themselves (but not necessarily replacing
97 placeholders for other objects still being read), are stored.
99 A hash table is used for efficient lookups of keys. We don't care
100 what the value slots hold. The variable must be set to an empty
101 hash table before all top-level calls to read0. In between calls,
102 it may be an empty hash table left unused from the previous call
103 (to reduce allocations), or nil. */
104 static Lisp_Object read_objects_completed;
106 /* File and lookahead for get-file-char and get-emacs-mule-file-char
107 to read from. Used by Fload. */
108 static struct infile
110 /* The input stream. */
111 FILE *stream;
113 /* Lookahead byte count. */
114 signed char lookahead;
116 /* Lookahead bytes, in reverse order. Keep these here because it is
117 not portable to ungetc more than one byte at a time. */
118 unsigned char buf[MAX_MULTIBYTE_LENGTH - 1];
119 } *infile;
121 /* For use within read-from-string (this reader is non-reentrant!!) */
122 static ptrdiff_t read_from_string_index;
123 static ptrdiff_t read_from_string_index_byte;
124 static ptrdiff_t read_from_string_limit;
126 /* Number of characters read in the current call to Fread or
127 Fread_from_string. */
128 static EMACS_INT readchar_count;
130 /* This contains the last string skipped with #@. */
131 static char *saved_doc_string;
132 /* Length of buffer allocated in saved_doc_string. */
133 static ptrdiff_t saved_doc_string_size;
134 /* Length of actual data in saved_doc_string. */
135 static ptrdiff_t saved_doc_string_length;
136 /* This is the file position that string came from. */
137 static file_offset saved_doc_string_position;
139 /* This contains the previous string skipped with #@.
140 We copy it from saved_doc_string when a new string
141 is put in saved_doc_string. */
142 static char *prev_saved_doc_string;
143 /* Length of buffer allocated in prev_saved_doc_string. */
144 static ptrdiff_t prev_saved_doc_string_size;
145 /* Length of actual data in prev_saved_doc_string. */
146 static ptrdiff_t prev_saved_doc_string_length;
147 /* This is the file position that string came from. */
148 static file_offset prev_saved_doc_string_position;
150 /* True means inside a new-style backquote
151 with no surrounding parentheses.
152 Fread initializes this to false, so we need not specbind it
153 or worry about what happens to it when there is an error. */
154 static bool new_backquote_flag;
156 /* A list of file names for files being loaded in Fload. Used to
157 check for recursive loads. */
159 static Lisp_Object Vloads_in_progress;
161 static int read_emacs_mule_char (int, int (*) (int, Lisp_Object),
162 Lisp_Object);
164 static void readevalloop (Lisp_Object, struct infile *, Lisp_Object, bool,
165 Lisp_Object, Lisp_Object,
166 Lisp_Object, Lisp_Object);
168 /* Functions that read one byte from the current source READCHARFUN
169 or unreads one byte. If the integer argument C is -1, it returns
170 one read byte, or -1 when there's no more byte in the source. If C
171 is 0 or positive, it unreads C, and the return value is not
172 interesting. */
174 static int readbyte_for_lambda (int, Lisp_Object);
175 static int readbyte_from_file (int, Lisp_Object);
176 static int readbyte_from_string (int, Lisp_Object);
178 /* Handle unreading and rereading of characters.
179 Write READCHAR to read a character,
180 UNREAD(c) to unread c to be read again.
182 These macros correctly read/unread multibyte characters. */
184 #define READCHAR readchar (readcharfun, NULL)
185 #define UNREAD(c) unreadchar (readcharfun, c)
187 /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
188 #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
190 /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
191 Qlambda, or a cons, we use this to keep an unread character because
192 a file stream can't handle multibyte-char unreading. The value -1
193 means that there's no unread character. */
194 static int unread_char;
196 static int
197 readchar (Lisp_Object readcharfun, bool *multibyte)
199 Lisp_Object tem;
200 register int c;
201 int (*readbyte) (int, Lisp_Object);
202 unsigned char buf[MAX_MULTIBYTE_LENGTH];
203 int i, len;
204 bool emacs_mule_encoding = 0;
206 if (multibyte)
207 *multibyte = 0;
209 readchar_count++;
211 if (BUFFERP (readcharfun))
213 register struct buffer *inbuffer = XBUFFER (readcharfun);
215 ptrdiff_t pt_byte = BUF_PT_BYTE (inbuffer);
217 if (! BUFFER_LIVE_P (inbuffer))
218 return -1;
220 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
221 return -1;
223 if (! NILP (BVAR (inbuffer, enable_multibyte_characters)))
225 /* Fetch the character code from the buffer. */
226 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
227 BUF_INC_POS (inbuffer, pt_byte);
228 c = STRING_CHAR (p);
229 if (multibyte)
230 *multibyte = 1;
232 else
234 c = BUF_FETCH_BYTE (inbuffer, pt_byte);
235 if (! ASCII_CHAR_P (c))
236 c = BYTE8_TO_CHAR (c);
237 pt_byte++;
239 SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
241 return c;
243 if (MARKERP (readcharfun))
245 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
247 ptrdiff_t bytepos = marker_byte_position (readcharfun);
249 if (bytepos >= BUF_ZV_BYTE (inbuffer))
250 return -1;
252 if (! NILP (BVAR (inbuffer, enable_multibyte_characters)))
254 /* Fetch the character code from the buffer. */
255 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
256 BUF_INC_POS (inbuffer, bytepos);
257 c = STRING_CHAR (p);
258 if (multibyte)
259 *multibyte = 1;
261 else
263 c = BUF_FETCH_BYTE (inbuffer, bytepos);
264 if (! ASCII_CHAR_P (c))
265 c = BYTE8_TO_CHAR (c);
266 bytepos++;
269 XMARKER (readcharfun)->bytepos = bytepos;
270 XMARKER (readcharfun)->charpos++;
272 return c;
275 if (EQ (readcharfun, Qlambda))
277 readbyte = readbyte_for_lambda;
278 goto read_multibyte;
281 if (EQ (readcharfun, Qget_file_char))
283 readbyte = readbyte_from_file;
284 goto read_multibyte;
287 if (STRINGP (readcharfun))
289 if (read_from_string_index >= read_from_string_limit)
290 c = -1;
291 else if (STRING_MULTIBYTE (readcharfun))
293 if (multibyte)
294 *multibyte = 1;
295 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, readcharfun,
296 read_from_string_index,
297 read_from_string_index_byte);
299 else
301 c = SREF (readcharfun, read_from_string_index_byte);
302 read_from_string_index++;
303 read_from_string_index_byte++;
305 return c;
308 if (CONSP (readcharfun) && STRINGP (XCAR (readcharfun)))
310 /* This is the case that read_vector is reading from a unibyte
311 string that contains a byte sequence previously skipped
312 because of #@NUMBER. The car part of readcharfun is that
313 string, and the cdr part is a value of readcharfun given to
314 read_vector. */
315 readbyte = readbyte_from_string;
316 if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char))
317 emacs_mule_encoding = 1;
318 goto read_multibyte;
321 if (EQ (readcharfun, Qget_emacs_mule_file_char))
323 readbyte = readbyte_from_file;
324 emacs_mule_encoding = 1;
325 goto read_multibyte;
328 tem = call0 (readcharfun);
330 if (NILP (tem))
331 return -1;
332 return XINT (tem);
334 read_multibyte:
335 if (unread_char >= 0)
337 c = unread_char;
338 unread_char = -1;
339 return c;
341 c = (*readbyte) (-1, readcharfun);
342 if (c < 0)
343 return c;
344 if (multibyte)
345 *multibyte = 1;
346 if (ASCII_CHAR_P (c))
347 return c;
348 if (emacs_mule_encoding)
349 return read_emacs_mule_char (c, readbyte, readcharfun);
350 i = 0;
351 buf[i++] = c;
352 len = BYTES_BY_CHAR_HEAD (c);
353 while (i < len)
355 buf[i++] = c = (*readbyte) (-1, readcharfun);
356 if (c < 0 || ! TRAILING_CODE_P (c))
358 for (i -= c < 0; 0 < --i; )
359 (*readbyte) (buf[i], readcharfun);
360 return BYTE8_TO_CHAR (buf[0]);
363 return STRING_CHAR (buf);
366 #define FROM_FILE_P(readcharfun) \
367 (EQ (readcharfun, Qget_file_char) \
368 || EQ (readcharfun, Qget_emacs_mule_file_char))
370 static void
371 skip_dyn_bytes (Lisp_Object readcharfun, ptrdiff_t n)
373 if (FROM_FILE_P (readcharfun))
375 block_input (); /* FIXME: Not sure if it's needed. */
376 fseek (infile->stream, n - infile->lookahead, SEEK_CUR);
377 unblock_input ();
378 infile->lookahead = 0;
380 else
381 { /* We're not reading directly from a file. In that case, it's difficult
382 to reliably count bytes, since these are usually meant for the file's
383 encoding, whereas we're now typically in the internal encoding.
384 But luckily, skip_dyn_bytes is used to skip over a single
385 dynamic-docstring (or dynamic byte-code) which is always quoted such
386 that \037 is the final char. */
387 int c;
388 do {
389 c = READCHAR;
390 } while (c >= 0 && c != '\037');
394 static void
395 skip_dyn_eof (Lisp_Object readcharfun)
397 if (FROM_FILE_P (readcharfun))
399 block_input (); /* FIXME: Not sure if it's needed. */
400 fseek (infile->stream, 0, SEEK_END);
401 unblock_input ();
402 infile->lookahead = 0;
404 else
405 while (READCHAR >= 0);
408 /* Unread the character C in the way appropriate for the stream READCHARFUN.
409 If the stream is a user function, call it with the char as argument. */
411 static void
412 unreadchar (Lisp_Object readcharfun, int c)
414 readchar_count--;
415 if (c == -1)
416 /* Don't back up the pointer if we're unreading the end-of-input mark,
417 since readchar didn't advance it when we read it. */
419 else if (BUFFERP (readcharfun))
421 struct buffer *b = XBUFFER (readcharfun);
422 ptrdiff_t charpos = BUF_PT (b);
423 ptrdiff_t bytepos = BUF_PT_BYTE (b);
425 if (! NILP (BVAR (b, enable_multibyte_characters)))
426 BUF_DEC_POS (b, bytepos);
427 else
428 bytepos--;
430 SET_BUF_PT_BOTH (b, charpos - 1, bytepos);
432 else if (MARKERP (readcharfun))
434 struct buffer *b = XMARKER (readcharfun)->buffer;
435 ptrdiff_t bytepos = XMARKER (readcharfun)->bytepos;
437 XMARKER (readcharfun)->charpos--;
438 if (! NILP (BVAR (b, enable_multibyte_characters)))
439 BUF_DEC_POS (b, bytepos);
440 else
441 bytepos--;
443 XMARKER (readcharfun)->bytepos = bytepos;
445 else if (STRINGP (readcharfun))
447 read_from_string_index--;
448 read_from_string_index_byte
449 = string_char_to_byte (readcharfun, read_from_string_index);
451 else if (CONSP (readcharfun) && STRINGP (XCAR (readcharfun)))
453 unread_char = c;
455 else if (EQ (readcharfun, Qlambda))
457 unread_char = c;
459 else if (FROM_FILE_P (readcharfun))
461 unread_char = c;
463 else
464 call1 (readcharfun, make_number (c));
467 static int
468 readbyte_for_lambda (int c, Lisp_Object readcharfun)
470 return read_bytecode_char (c >= 0);
474 static int
475 readbyte_from_stdio (void)
477 if (infile->lookahead)
478 return infile->buf[--infile->lookahead];
480 int c;
481 FILE *instream = infile->stream;
483 block_input ();
485 /* Interrupted reads have been observed while reading over the network. */
486 while ((c = getc_unlocked (instream)) == EOF && errno == EINTR
487 && ferror_unlocked (instream))
489 unblock_input ();
490 maybe_quit ();
491 block_input ();
492 clearerr_unlocked (instream);
495 unblock_input ();
497 return (c == EOF ? -1 : c);
500 static int
501 readbyte_from_file (int c, Lisp_Object readcharfun)
503 if (c >= 0)
505 eassert (infile->lookahead < sizeof infile->buf);
506 infile->buf[infile->lookahead++] = c;
507 return 0;
510 return readbyte_from_stdio ();
513 static int
514 readbyte_from_string (int c, Lisp_Object readcharfun)
516 Lisp_Object string = XCAR (readcharfun);
518 if (c >= 0)
520 read_from_string_index--;
521 read_from_string_index_byte
522 = string_char_to_byte (string, read_from_string_index);
525 if (read_from_string_index >= read_from_string_limit)
526 c = -1;
527 else
528 FETCH_STRING_CHAR_ADVANCE (c, string,
529 read_from_string_index,
530 read_from_string_index_byte);
531 return c;
535 /* Read one non-ASCII character from INFILE. The character is
536 encoded in `emacs-mule' and the first byte is already read in
537 C. */
539 static int
540 read_emacs_mule_char (int c, int (*readbyte) (int, Lisp_Object), Lisp_Object readcharfun)
542 /* Emacs-mule coding uses at most 4-byte for one character. */
543 unsigned char buf[4];
544 int len = emacs_mule_bytes[c];
545 struct charset *charset;
546 int i;
547 unsigned code;
549 if (len == 1)
550 /* C is not a valid leading-code of `emacs-mule'. */
551 return BYTE8_TO_CHAR (c);
553 i = 0;
554 buf[i++] = c;
555 while (i < len)
557 buf[i++] = c = (*readbyte) (-1, readcharfun);
558 if (c < 0xA0)
560 for (i -= c < 0; 0 < --i; )
561 (*readbyte) (buf[i], readcharfun);
562 return BYTE8_TO_CHAR (buf[0]);
566 if (len == 2)
568 charset = CHARSET_FROM_ID (emacs_mule_charset[buf[0]]);
569 code = buf[1] & 0x7F;
571 else if (len == 3)
573 if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11
574 || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12)
576 charset = CHARSET_FROM_ID (emacs_mule_charset[buf[1]]);
577 code = buf[2] & 0x7F;
579 else
581 charset = CHARSET_FROM_ID (emacs_mule_charset[buf[0]]);
582 code = ((buf[1] << 8) | buf[2]) & 0x7F7F;
585 else
587 charset = CHARSET_FROM_ID (emacs_mule_charset[buf[1]]);
588 code = ((buf[2] << 8) | buf[3]) & 0x7F7F;
590 c = DECODE_CHAR (charset, code);
591 if (c < 0)
592 Fsignal (Qinvalid_read_syntax,
593 list1 (build_string ("invalid multibyte form")));
594 return c;
598 /* An in-progress substitution of OBJECT for PLACEHOLDER. */
599 struct subst
601 Lisp_Object object;
602 Lisp_Object placeholder;
604 /* Hash table of subobjects of OBJECT that might be circular. If
605 Qt, all such objects might be circular. */
606 Lisp_Object completed;
608 /* List of subobjects of OBJECT that have already been visited. */
609 Lisp_Object seen;
612 static Lisp_Object read_internal_start (Lisp_Object, Lisp_Object,
613 Lisp_Object);
614 static Lisp_Object read0 (Lisp_Object);
615 static Lisp_Object read1 (Lisp_Object, int *, bool);
617 static Lisp_Object read_list (bool, Lisp_Object);
618 static Lisp_Object read_vector (Lisp_Object, bool);
620 static Lisp_Object substitute_object_recurse (struct subst *, Lisp_Object);
621 static void substitute_in_interval (INTERVAL, void *);
624 /* Get a character from the tty. */
626 /* Read input events until we get one that's acceptable for our purposes.
628 If NO_SWITCH_FRAME, switch-frame events are stashed
629 until we get a character we like, and then stuffed into
630 unread_switch_frame.
632 If ASCII_REQUIRED, check function key events to see
633 if the unmodified version of the symbol has a Qascii_character
634 property, and use that character, if present.
636 If ERROR_NONASCII, signal an error if the input we
637 get isn't an ASCII character with modifiers. If it's false but
638 ASCII_REQUIRED is true, just re-read until we get an ASCII
639 character.
641 If INPUT_METHOD, invoke the current input method
642 if the character warrants that.
644 If SECONDS is a number, wait that many seconds for input, and
645 return Qnil if no input arrives within that time. */
647 static Lisp_Object
648 read_filtered_event (bool no_switch_frame, bool ascii_required,
649 bool error_nonascii, bool input_method, Lisp_Object seconds)
651 Lisp_Object val, delayed_switch_frame;
652 struct timespec end_time;
654 #ifdef HAVE_WINDOW_SYSTEM
655 if (display_hourglass_p)
656 cancel_hourglass ();
657 #endif
659 delayed_switch_frame = Qnil;
661 /* Compute timeout. */
662 if (NUMBERP (seconds))
664 double duration = XFLOATINT (seconds);
665 struct timespec wait_time = dtotimespec (duration);
666 end_time = timespec_add (current_timespec (), wait_time);
669 /* Read until we get an acceptable event. */
670 retry:
672 val = read_char (0, Qnil, (input_method ? Qnil : Qt), 0,
673 NUMBERP (seconds) ? &end_time : NULL);
674 while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */
676 if (BUFFERP (val))
677 goto retry;
679 /* `switch-frame' events are put off until after the next ASCII
680 character. This is better than signaling an error just because
681 the last characters were typed to a separate minibuffer frame,
682 for example. Eventually, some code which can deal with
683 switch-frame events will read it and process it. */
684 if (no_switch_frame
685 && EVENT_HAS_PARAMETERS (val)
686 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame))
688 delayed_switch_frame = val;
689 goto retry;
692 if (ascii_required && !(NUMBERP (seconds) && NILP (val)))
694 /* Convert certain symbols to their ASCII equivalents. */
695 if (SYMBOLP (val))
697 Lisp_Object tem, tem1;
698 tem = Fget (val, Qevent_symbol_element_mask);
699 if (!NILP (tem))
701 tem1 = Fget (Fcar (tem), Qascii_character);
702 /* Merge this symbol's modifier bits
703 with the ASCII equivalent of its basic code. */
704 if (!NILP (tem1))
705 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
709 /* If we don't have a character now, deal with it appropriately. */
710 if (!INTEGERP (val))
712 if (error_nonascii)
714 Vunread_command_events = list1 (val);
715 error ("Non-character input-event");
717 else
718 goto retry;
722 if (! NILP (delayed_switch_frame))
723 unread_switch_frame = delayed_switch_frame;
725 #if 0
727 #ifdef HAVE_WINDOW_SYSTEM
728 if (display_hourglass_p)
729 start_hourglass ();
730 #endif
732 #endif
734 return val;
737 DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
738 doc: /* Read a character from the command input (keyboard or macro).
739 It is returned as a number.
740 If the character has modifiers, they are resolved and reflected to the
741 character code if possible (e.g. C-SPC -> 0).
743 If the user generates an event which is not a character (i.e. a mouse
744 click or function key event), `read-char' signals an error. As an
745 exception, switch-frame events are put off until non-character events
746 can be read.
747 If you want to read non-character events, or ignore them, call
748 `read-event' or `read-char-exclusive' instead.
750 If the optional argument PROMPT is non-nil, display that as a prompt.
751 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
752 input method is turned on in the current buffer, that input method
753 is used for reading a character.
754 If the optional argument SECONDS is non-nil, it should be a number
755 specifying the maximum number of seconds to wait for input. If no
756 input arrives in that time, return nil. SECONDS may be a
757 floating-point value. */)
758 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
760 Lisp_Object val;
762 if (! NILP (prompt))
763 message_with_string ("%s", prompt, 0);
764 val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
766 return (NILP (val) ? Qnil
767 : make_number (char_resolve_modifier_mask (XINT (val))));
770 DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
771 doc: /* Read an event object from the input stream.
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 if (! NILP (prompt))
783 message_with_string ("%s", prompt, 0);
784 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds);
787 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0,
788 doc: /* Read a character from the command input (keyboard or macro).
789 It is returned as a number. Non-character events are ignored.
790 If the character has modifiers, they are resolved and reflected to the
791 character code if possible (e.g. C-SPC -> 0).
793 If the optional argument PROMPT is non-nil, display that as a prompt.
794 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
795 input method is turned on in the current buffer, that input method
796 is used for reading a character.
797 If the optional argument SECONDS is non-nil, it should be a number
798 specifying the maximum number of seconds to wait for input. If no
799 input arrives in that time, return nil. SECONDS may be a
800 floating-point value. */)
801 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
803 Lisp_Object val;
805 if (! NILP (prompt))
806 message_with_string ("%s", prompt, 0);
808 val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds);
810 return (NILP (val) ? Qnil
811 : make_number (char_resolve_modifier_mask (XINT (val))));
814 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
815 doc: /* Don't use this yourself. */)
816 (void)
818 if (!infile)
819 error ("get-file-char misused");
820 return make_number (readbyte_from_stdio ());
826 /* Return true if the lisp code read using READCHARFUN defines a non-nil
827 `lexical-binding' file variable. After returning, the stream is
828 positioned following the first line, if it is a comment or #! line,
829 otherwise nothing is read. */
831 static bool
832 lisp_file_lexically_bound_p (Lisp_Object readcharfun)
834 int ch = READCHAR;
836 if (ch == '#')
838 ch = READCHAR;
839 if (ch != '!')
841 UNREAD (ch);
842 UNREAD ('#');
843 return 0;
845 while (ch != '\n' && ch != EOF)
846 ch = READCHAR;
847 if (ch == '\n') ch = READCHAR;
848 /* It is OK to leave the position after a #! line, since
849 that is what read1 does. */
852 if (ch != ';')
853 /* The first line isn't a comment, just give up. */
855 UNREAD (ch);
856 return 0;
858 else
859 /* Look for an appropriate file-variable in the first line. */
861 bool rv = 0;
862 enum {
863 NOMINAL, AFTER_FIRST_DASH, AFTER_ASTERIX
864 } beg_end_state = NOMINAL;
865 bool in_file_vars = 0;
867 #define UPDATE_BEG_END_STATE(ch) \
868 if (beg_end_state == NOMINAL) \
869 beg_end_state = (ch == '-' ? AFTER_FIRST_DASH : NOMINAL); \
870 else if (beg_end_state == AFTER_FIRST_DASH) \
871 beg_end_state = (ch == '*' ? AFTER_ASTERIX : NOMINAL); \
872 else if (beg_end_state == AFTER_ASTERIX) \
874 if (ch == '-') \
875 in_file_vars = !in_file_vars; \
876 beg_end_state = NOMINAL; \
879 /* Skip until we get to the file vars, if any. */
882 ch = READCHAR;
883 UPDATE_BEG_END_STATE (ch);
885 while (!in_file_vars && ch != '\n' && ch != EOF);
887 while (in_file_vars)
889 char var[100], val[100];
890 unsigned i;
892 ch = READCHAR;
894 /* Read a variable name. */
895 while (ch == ' ' || ch == '\t')
896 ch = READCHAR;
898 i = 0;
899 beg_end_state = NOMINAL;
900 while (ch != ':' && ch != '\n' && ch != EOF && in_file_vars)
902 if (i < sizeof var - 1)
903 var[i++] = ch;
904 UPDATE_BEG_END_STATE (ch);
905 ch = READCHAR;
908 /* Stop scanning if no colon was found before end marker. */
909 if (!in_file_vars || ch == '\n' || ch == EOF)
910 break;
912 while (i > 0 && (var[i - 1] == ' ' || var[i - 1] == '\t'))
913 i--;
914 var[i] = '\0';
916 if (ch == ':')
918 /* Read a variable value. */
919 ch = READCHAR;
921 while (ch == ' ' || ch == '\t')
922 ch = READCHAR;
924 i = 0;
925 beg_end_state = NOMINAL;
926 while (ch != ';' && ch != '\n' && ch != EOF && in_file_vars)
928 if (i < sizeof val - 1)
929 val[i++] = ch;
930 UPDATE_BEG_END_STATE (ch);
931 ch = READCHAR;
933 if (! in_file_vars)
934 /* The value was terminated by an end-marker, which remove. */
935 i -= 3;
936 while (i > 0 && (val[i - 1] == ' ' || val[i - 1] == '\t'))
937 i--;
938 val[i] = '\0';
940 if (strcmp (var, "lexical-binding") == 0)
941 /* This is it... */
943 rv = (strcmp (val, "nil") != 0);
944 break;
949 while (ch != '\n' && ch != EOF)
950 ch = READCHAR;
952 return rv;
956 /* Value is a version number of byte compiled code if the file
957 associated with file descriptor FD is a compiled Lisp file that's
958 safe to load. Only files compiled with Emacs are safe to load.
959 Files compiled with XEmacs can lead to a crash in Fbyte_code
960 because of an incompatible change in the byte compiler. */
962 static int
963 safe_to_load_version (int fd)
965 char buf[512];
966 int nbytes, i;
967 int version = 1;
969 /* Read the first few bytes from the file, and look for a line
970 specifying the byte compiler version used. */
971 nbytes = emacs_read_quit (fd, buf, sizeof buf);
972 if (nbytes > 0)
974 /* Skip to the next newline, skipping over the initial `ELC'
975 with NUL bytes following it, but note the version. */
976 for (i = 0; i < nbytes && buf[i] != '\n'; ++i)
977 if (i == 4)
978 version = buf[i];
980 if (i >= nbytes
981 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
982 buf + i, nbytes - i) < 0)
983 version = 0;
986 lseek (fd, 0, SEEK_SET);
987 return version;
991 /* Callback for record_unwind_protect. Restore the old load list OLD,
992 after loading a file successfully. */
994 static void
995 record_load_unwind (Lisp_Object old)
997 Vloads_in_progress = old;
1000 /* This handler function is used via internal_condition_case_1. */
1002 static Lisp_Object
1003 load_error_handler (Lisp_Object data)
1005 return Qnil;
1008 static void
1009 load_warn_old_style_backquotes (Lisp_Object file)
1011 if (!NILP (Vlread_old_style_backquotes))
1013 AUTO_STRING (format, "Loading `%s': old-style backquotes detected!");
1014 CALLN (Fmessage, format, file);
1018 static void
1019 load_warn_unescaped_character_literals (Lisp_Object file)
1021 if (NILP (Vlread_unescaped_character_literals)) return;
1022 CHECK_CONS (Vlread_unescaped_character_literals);
1023 Lisp_Object format =
1024 build_string ("Loading `%s': unescaped character literals %s detected!");
1025 Lisp_Object separator = build_string (", ");
1026 Lisp_Object inner_format = build_string ("`?%c'");
1027 CALLN (Fmessage,
1028 format, file,
1029 Fmapconcat (list3 (Qlambda, list1 (Qchar),
1030 list3 (Qformat, inner_format, Qchar)),
1031 Fsort (Vlread_unescaped_character_literals, Qlss),
1032 separator));
1035 DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
1036 doc: /* Return the suffixes that `load' should try if a suffix is \
1037 required.
1038 This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
1039 (void)
1041 Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext;
1042 while (CONSP (suffixes))
1044 Lisp_Object exts = Vload_file_rep_suffixes;
1045 suffix = XCAR (suffixes);
1046 suffixes = XCDR (suffixes);
1047 while (CONSP (exts))
1049 ext = XCAR (exts);
1050 exts = XCDR (exts);
1051 lst = Fcons (concat2 (suffix, ext), lst);
1054 return Fnreverse (lst);
1057 /* Returns true if STRING ends with SUFFIX */
1058 static bool
1059 suffix_p (Lisp_Object string, const char *suffix)
1061 ptrdiff_t suffix_len = strlen (suffix);
1062 ptrdiff_t string_len = SBYTES (string);
1064 return string_len >= suffix_len && !strcmp (SSDATA (string) + string_len - suffix_len, suffix);
1067 static void
1068 close_infile_unwind (void *arg)
1070 FILE *stream = arg;
1071 eassert (infile == NULL || infile->stream == stream);
1072 infile = NULL;
1073 fclose (stream);
1076 DEFUN ("load", Fload, Sload, 1, 5, 0,
1077 doc: /* Execute a file of Lisp code named FILE.
1078 First try FILE with `.elc' appended, then try with `.el', then try
1079 with a system-dependent suffix of dynamic modules (see `load-suffixes'),
1080 then try FILE unmodified (the exact suffixes in the exact order are
1081 determined by `load-suffixes'). Environment variable references in
1082 FILE are replaced with their values by calling `substitute-in-file-name'.
1083 This function searches the directories in `load-path'.
1085 If optional second arg NOERROR is non-nil,
1086 report no error if FILE doesn't exist.
1087 Print messages at start and end of loading unless
1088 optional third arg NOMESSAGE is non-nil (but `force-load-messages'
1089 overrides that).
1090 If optional fourth arg NOSUFFIX is non-nil, don't try adding
1091 suffixes to the specified name FILE.
1092 If optional fifth arg MUST-SUFFIX is non-nil, insist on
1093 the suffix `.elc' or `.el' or the module suffix; don't accept just
1094 FILE unless it ends in one of those suffixes or includes a directory name.
1096 If NOSUFFIX is nil, then if a file could not be found, try looking for
1097 a different representation of the file by adding non-empty suffixes to
1098 its name, before trying another file. Emacs uses this feature to find
1099 compressed versions of files when Auto Compression mode is enabled.
1100 If NOSUFFIX is non-nil, disable this feature.
1102 The suffixes that this function tries out, when NOSUFFIX is nil, are
1103 given by the return value of `get-load-suffixes' and the values listed
1104 in `load-file-rep-suffixes'. If MUST-SUFFIX is non-nil, only the
1105 return value of `get-load-suffixes' is used, i.e. the file name is
1106 required to have a non-empty suffix.
1108 When searching suffixes, this function normally stops at the first
1109 one that exists. If the option `load-prefer-newer' is non-nil,
1110 however, it tries all suffixes, and uses whichever file is the newest.
1112 Loading a file records its definitions, and its `provide' and
1113 `require' calls, in an element of `load-history' whose
1114 car is the file name loaded. See `load-history'.
1116 While the file is in the process of being loaded, the variable
1117 `load-in-progress' is non-nil and the variable `load-file-name'
1118 is bound to the file's name.
1120 Return t if the file exists and loads successfully. */)
1121 (Lisp_Object file, Lisp_Object noerror, Lisp_Object nomessage,
1122 Lisp_Object nosuffix, Lisp_Object must_suffix)
1124 FILE *stream;
1125 int fd;
1126 int fd_index UNINIT;
1127 ptrdiff_t count = SPECPDL_INDEX ();
1128 Lisp_Object found, efound, hist_file_name;
1129 /* True means we printed the ".el is newer" message. */
1130 bool newer = 0;
1131 /* True means we are loading a compiled file. */
1132 bool compiled = 0;
1133 Lisp_Object handler;
1134 bool safe_p = 1;
1135 const char *fmode = "r" FOPEN_TEXT;
1136 int version;
1138 CHECK_STRING (file);
1140 /* If file name is magic, call the handler. */
1141 /* This shouldn't be necessary any more now that `openp' handles it right.
1142 handler = Ffind_file_name_handler (file, Qload);
1143 if (!NILP (handler))
1144 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
1146 /* The presence of this call is the result of a historical accident:
1147 it used to be in every file-operation and when it got removed
1148 everywhere, it accidentally stayed here. Since then, enough people
1149 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
1150 that it seemed risky to remove. */
1151 if (! NILP (noerror))
1153 file = internal_condition_case_1 (Fsubstitute_in_file_name, file,
1154 Qt, load_error_handler);
1155 if (NILP (file))
1156 return Qnil;
1158 else
1159 file = Fsubstitute_in_file_name (file);
1161 /* Avoid weird lossage with null string as arg,
1162 since it would try to load a directory as a Lisp file. */
1163 if (SCHARS (file) == 0)
1165 fd = -1;
1166 errno = ENOENT;
1168 else
1170 Lisp_Object suffixes;
1171 found = Qnil;
1173 if (! NILP (must_suffix))
1175 /* Don't insist on adding a suffix if FILE already ends with one. */
1176 if (suffix_p (file, ".el")
1177 || suffix_p (file, ".elc")
1178 #ifdef HAVE_MODULES
1179 || suffix_p (file, MODULES_SUFFIX)
1180 #endif
1182 must_suffix = Qnil;
1183 /* Don't insist on adding a suffix
1184 if the argument includes a directory name. */
1185 else if (! NILP (Ffile_name_directory (file)))
1186 must_suffix = Qnil;
1189 if (!NILP (nosuffix))
1190 suffixes = Qnil;
1191 else
1193 suffixes = Fget_load_suffixes ();
1194 if (NILP (must_suffix))
1195 suffixes = CALLN (Fappend, suffixes, Vload_file_rep_suffixes);
1198 fd = openp (Vload_path, file, suffixes, &found, Qnil, load_prefer_newer);
1201 if (fd == -1)
1203 if (NILP (noerror))
1204 report_file_error ("Cannot open load file", file);
1205 return Qnil;
1208 /* Tell startup.el whether or not we found the user's init file. */
1209 if (EQ (Qt, Vuser_init_file))
1210 Vuser_init_file = found;
1212 /* If FD is -2, that means openp found a magic file. */
1213 if (fd == -2)
1215 if (NILP (Fequal (found, file)))
1216 /* If FOUND is a different file name from FILE,
1217 find its handler even if we have already inhibited
1218 the `load' operation on FILE. */
1219 handler = Ffind_file_name_handler (found, Qt);
1220 else
1221 handler = Ffind_file_name_handler (found, Qload);
1222 if (! NILP (handler))
1223 return call5 (handler, Qload, found, noerror, nomessage, Qt);
1224 #ifdef DOS_NT
1225 /* Tramp has to deal with semi-broken packages that prepend
1226 drive letters to remote files. For that reason, Tramp
1227 catches file operations that test for file existence, which
1228 makes openp think X:/foo.elc files are remote. However,
1229 Tramp does not catch `load' operations for such files, so we
1230 end up with a nil as the `load' handler above. If we would
1231 continue with fd = -2, we will behave wrongly, and in
1232 particular try reading a .elc file in the "rt" mode instead
1233 of "rb". See bug #9311 for the results. To work around
1234 this, we try to open the file locally, and go with that if it
1235 succeeds. */
1236 fd = emacs_open (SSDATA (ENCODE_FILE (found)), O_RDONLY, 0);
1237 if (fd == -1)
1238 fd = -2;
1239 #endif
1242 if (0 <= fd)
1244 fd_index = SPECPDL_INDEX ();
1245 record_unwind_protect_int (close_file_unwind, fd);
1248 #ifdef HAVE_MODULES
1249 if (suffix_p (found, MODULES_SUFFIX))
1250 return unbind_to (count, Fmodule_load (found));
1251 #endif
1253 /* Check if we're stuck in a recursive load cycle.
1255 2000-09-21: It's not possible to just check for the file loaded
1256 being a member of Vloads_in_progress. This fails because of the
1257 way the byte compiler currently works; `provide's are not
1258 evaluated, see font-lock.el/jit-lock.el as an example. This
1259 leads to a certain amount of ``normal'' recursion.
1261 Also, just loading a file recursively is not always an error in
1262 the general case; the second load may do something different. */
1264 int load_count = 0;
1265 Lisp_Object tem;
1266 for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
1267 if (!NILP (Fequal (found, XCAR (tem))) && (++load_count > 3))
1268 signal_error ("Recursive load", Fcons (found, Vloads_in_progress));
1269 record_unwind_protect (record_load_unwind, Vloads_in_progress);
1270 Vloads_in_progress = Fcons (found, Vloads_in_progress);
1273 /* All loads are by default dynamic, unless the file itself specifies
1274 otherwise using a file-variable in the first line. This is bound here
1275 so that it takes effect whether or not we use
1276 Vload_source_file_function. */
1277 specbind (Qlexical_binding, Qnil);
1279 /* Get the name for load-history. */
1280 hist_file_name = (! NILP (Vpurify_flag)
1281 ? concat2 (Ffile_name_directory (file),
1282 Ffile_name_nondirectory (found))
1283 : found) ;
1285 version = -1;
1287 /* Check for the presence of old-style quotes and warn about them. */
1288 specbind (Qlread_old_style_backquotes, Qnil);
1289 record_unwind_protect (load_warn_old_style_backquotes, file);
1291 /* Check for the presence of unescaped character literals and warn
1292 about them. */
1293 specbind (Qlread_unescaped_character_literals, Qnil);
1294 record_unwind_protect (load_warn_unescaped_character_literals, file);
1296 int is_elc;
1297 if ((is_elc = suffix_p (found, ".elc")) != 0
1298 /* version = 1 means the file is empty, in which case we can
1299 treat it as not byte-compiled. */
1300 || (fd >= 0 && (version = safe_to_load_version (fd)) > 1))
1301 /* Load .elc files directly, but not when they are
1302 remote and have no handler! */
1304 if (fd != -2)
1306 struct stat s1, s2;
1307 int result;
1309 if (version < 0
1310 && ! (version = safe_to_load_version (fd)))
1312 safe_p = 0;
1313 if (!load_dangerous_libraries)
1314 error ("File `%s' was not compiled in Emacs", SDATA (found));
1315 else if (!NILP (nomessage) && !force_load_messages)
1316 message_with_string ("File `%s' not compiled in Emacs", found, 1);
1319 compiled = 1;
1321 efound = ENCODE_FILE (found);
1322 fmode = "r" FOPEN_BINARY;
1324 /* openp already checked for newness, no point doing it again.
1325 FIXME would be nice to get a message when openp
1326 ignores suffix order due to load_prefer_newer. */
1327 if (!load_prefer_newer && is_elc)
1329 result = stat (SSDATA (efound), &s1);
1330 if (result == 0)
1332 SSET (efound, SBYTES (efound) - 1, 0);
1333 result = stat (SSDATA (efound), &s2);
1334 SSET (efound, SBYTES (efound) - 1, 'c');
1337 if (result == 0
1338 && timespec_cmp (get_stat_mtime (&s1), get_stat_mtime (&s2)) < 0)
1340 /* Make the progress messages mention that source is newer. */
1341 newer = 1;
1343 /* If we won't print another message, mention this anyway. */
1344 if (!NILP (nomessage) && !force_load_messages)
1346 Lisp_Object msg_file;
1347 msg_file = Fsubstring (found, make_number (0), make_number (-1));
1348 message_with_string ("Source file `%s' newer than byte-compiled file",
1349 msg_file, 1);
1352 } /* !load_prefer_newer */
1355 else
1357 /* We are loading a source file (*.el). */
1358 if (!NILP (Vload_source_file_function))
1360 Lisp_Object val;
1362 if (fd >= 0)
1364 emacs_close (fd);
1365 clear_unwind_protect (fd_index);
1367 val = call4 (Vload_source_file_function, found, hist_file_name,
1368 NILP (noerror) ? Qnil : Qt,
1369 (NILP (nomessage) || force_load_messages) ? Qnil : Qt);
1370 return unbind_to (count, val);
1374 if (fd < 0)
1376 /* We somehow got here with fd == -2, meaning the file is deemed
1377 to be remote. Don't even try to reopen the file locally;
1378 just force a failure. */
1379 stream = NULL;
1380 errno = EINVAL;
1382 else
1384 #ifdef WINDOWSNT
1385 emacs_close (fd);
1386 clear_unwind_protect (fd_index);
1387 efound = ENCODE_FILE (found);
1388 stream = emacs_fopen (SSDATA (efound), fmode);
1389 #else
1390 stream = fdopen (fd, fmode);
1391 #endif
1393 if (! stream)
1394 report_file_error ("Opening stdio stream", file);
1395 set_unwind_protect_ptr (fd_index, close_infile_unwind, stream);
1397 if (! NILP (Vpurify_flag))
1398 Vpreloaded_file_list = Fcons (Fpurecopy (file), Vpreloaded_file_list);
1400 if (NILP (nomessage) || force_load_messages)
1402 if (!safe_p)
1403 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
1404 file, 1);
1405 else if (!compiled)
1406 message_with_string ("Loading %s (source)...", file, 1);
1407 else if (newer)
1408 message_with_string ("Loading %s (compiled; note, source file is newer)...",
1409 file, 1);
1410 else /* The typical case; compiled file newer than source file. */
1411 message_with_string ("Loading %s...", file, 1);
1414 specbind (Qload_file_name, found);
1415 specbind (Qinhibit_file_name_operation, Qnil);
1416 specbind (Qload_in_progress, Qt);
1418 struct infile input;
1419 input.stream = stream;
1420 input.lookahead = 0;
1421 infile = &input;
1423 if (lisp_file_lexically_bound_p (Qget_file_char))
1424 Fset (Qlexical_binding, Qt);
1426 if (! version || version >= 22)
1427 readevalloop (Qget_file_char, &input, hist_file_name,
1428 0, Qnil, Qnil, Qnil, Qnil);
1429 else
1431 /* We can't handle a file which was compiled with
1432 byte-compile-dynamic by older version of Emacs. */
1433 specbind (Qload_force_doc_strings, Qt);
1434 readevalloop (Qget_emacs_mule_file_char, &input, hist_file_name,
1435 0, Qnil, Qnil, Qnil, Qnil);
1437 unbind_to (count, Qnil);
1439 /* Run any eval-after-load forms for this file. */
1440 if (!NILP (Ffboundp (Qdo_after_load_evaluation)))
1441 call1 (Qdo_after_load_evaluation, hist_file_name) ;
1443 xfree (saved_doc_string);
1444 saved_doc_string = 0;
1445 saved_doc_string_size = 0;
1447 xfree (prev_saved_doc_string);
1448 prev_saved_doc_string = 0;
1449 prev_saved_doc_string_size = 0;
1451 if (!noninteractive && (NILP (nomessage) || force_load_messages))
1453 if (!safe_p)
1454 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
1455 file, 1);
1456 else if (!compiled)
1457 message_with_string ("Loading %s (source)...done", file, 1);
1458 else if (newer)
1459 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
1460 file, 1);
1461 else /* The typical case; compiled file newer than source file. */
1462 message_with_string ("Loading %s...done", file, 1);
1465 return Qt;
1468 static bool
1469 complete_filename_p (Lisp_Object pathname)
1471 const unsigned char *s = SDATA (pathname);
1472 return (IS_DIRECTORY_SEP (s[0])
1473 || (SCHARS (pathname) > 2
1474 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])));
1477 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
1478 doc: /* Search for FILENAME through PATH.
1479 Returns the file's name in absolute form, or nil if not found.
1480 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1481 file name when searching.
1482 If non-nil, PREDICATE is used instead of `file-readable-p'.
1483 PREDICATE can also be an integer to pass to the faccessat(2) function,
1484 in which case file-name-handlers are ignored.
1485 This function will normally skip directories, so if you want it to find
1486 directories, make sure the PREDICATE function returns `dir-ok' for them. */)
1487 (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate)
1489 Lisp_Object file;
1490 int fd = openp (path, filename, suffixes, &file, predicate, false);
1491 if (NILP (predicate) && fd >= 0)
1492 emacs_close (fd);
1493 return file;
1496 /* Search for a file whose name is STR, looking in directories
1497 in the Lisp list PATH, and trying suffixes from SUFFIX.
1498 On success, return a file descriptor (or 1 or -2 as described below).
1499 On failure, return -1 and set errno.
1501 SUFFIXES is a list of strings containing possible suffixes.
1502 The empty suffix is automatically added if the list is empty.
1504 PREDICATE t means the files are binary.
1505 PREDICATE non-nil and non-t means don't open the files,
1506 just look for one that satisfies the predicate. In this case,
1507 return -2 on success. The predicate can be a lisp function or
1508 an integer to pass to `access' (in which case file-name-handlers
1509 are ignored).
1511 If STOREPTR is nonzero, it points to a slot where the name of
1512 the file actually found should be stored as a Lisp string.
1513 nil is stored there on failure.
1515 If the file we find is remote, return -2
1516 but store the found remote file name in *STOREPTR.
1518 If NEWER is true, try all SUFFIXes and return the result for the
1519 newest file that exists. Does not apply to remote files,
1520 or if a non-nil and non-t PREDICATE is specified. */
1523 openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
1524 Lisp_Object *storeptr, Lisp_Object predicate, bool newer)
1526 ptrdiff_t fn_size = 100;
1527 char buf[100];
1528 char *fn = buf;
1529 bool absolute;
1530 ptrdiff_t want_length;
1531 Lisp_Object filename;
1532 Lisp_Object string, tail, encoded_fn, save_string;
1533 ptrdiff_t max_suffix_len = 0;
1534 int last_errno = ENOENT;
1535 int save_fd = -1;
1536 USE_SAFE_ALLOCA;
1538 /* The last-modified time of the newest matching file found.
1539 Initialize it to something less than all valid timestamps. */
1540 struct timespec save_mtime = make_timespec (TYPE_MINIMUM (time_t), -1);
1542 CHECK_STRING (str);
1544 for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
1546 CHECK_STRING_CAR (tail);
1547 max_suffix_len = max (max_suffix_len,
1548 SBYTES (XCAR (tail)));
1551 string = filename = encoded_fn = save_string = Qnil;
1553 if (storeptr)
1554 *storeptr = Qnil;
1556 absolute = complete_filename_p (str);
1558 for (; CONSP (path); path = XCDR (path))
1560 ptrdiff_t baselen, prefixlen;
1562 filename = Fexpand_file_name (str, XCAR (path));
1563 if (!complete_filename_p (filename))
1564 /* If there are non-absolute elts in PATH (eg "."). */
1565 /* Of course, this could conceivably lose if luser sets
1566 default-directory to be something non-absolute... */
1568 filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
1569 if (!complete_filename_p (filename))
1570 /* Give up on this path element! */
1571 continue;
1574 /* Calculate maximum length of any filename made from
1575 this path element/specified file name and any possible suffix. */
1576 want_length = max_suffix_len + SBYTES (filename);
1577 if (fn_size <= want_length)
1579 fn_size = 100 + want_length;
1580 fn = SAFE_ALLOCA (fn_size);
1583 /* Copy FILENAME's data to FN but remove starting /: if any. */
1584 prefixlen = ((SCHARS (filename) > 2
1585 && SREF (filename, 0) == '/'
1586 && SREF (filename, 1) == ':')
1587 ? 2 : 0);
1588 baselen = SBYTES (filename) - prefixlen;
1589 memcpy (fn, SDATA (filename) + prefixlen, baselen);
1591 /* Loop over suffixes. */
1592 for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes;
1593 CONSP (tail); tail = XCDR (tail))
1595 Lisp_Object suffix = XCAR (tail);
1596 ptrdiff_t fnlen, lsuffix = SBYTES (suffix);
1597 Lisp_Object handler;
1599 /* Make complete filename by appending SUFFIX. */
1600 memcpy (fn + baselen, SDATA (suffix), lsuffix + 1);
1601 fnlen = baselen + lsuffix;
1603 /* Check that the file exists and is not a directory. */
1604 /* We used to only check for handlers on non-absolute file names:
1605 if (absolute)
1606 handler = Qnil;
1607 else
1608 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1609 It's not clear why that was the case and it breaks things like
1610 (load "/bar.el") where the file is actually "/bar.el.gz". */
1611 /* make_string has its own ideas on when to return a unibyte
1612 string and when a multibyte string, but we know better.
1613 We must have a unibyte string when dumping, since
1614 file-name encoding is shaky at best at that time, and in
1615 particular default-file-name-coding-system is reset
1616 several times during loadup. We therefore don't want to
1617 encode the file before passing it to file I/O library
1618 functions. */
1619 if (!STRING_MULTIBYTE (filename) && !STRING_MULTIBYTE (suffix))
1620 string = make_unibyte_string (fn, fnlen);
1621 else
1622 string = make_string (fn, fnlen);
1623 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1624 if ((!NILP (handler) || (!NILP (predicate) && !EQ (predicate, Qt)))
1625 && !NATNUMP (predicate))
1627 bool exists;
1628 if (NILP (predicate) || EQ (predicate, Qt))
1629 exists = !NILP (Ffile_readable_p (string));
1630 else
1632 Lisp_Object tmp = call1 (predicate, string);
1633 if (NILP (tmp))
1634 exists = false;
1635 else if (EQ (tmp, Qdir_ok)
1636 || NILP (Ffile_directory_p (string)))
1637 exists = true;
1638 else
1640 exists = false;
1641 last_errno = EISDIR;
1645 if (exists)
1647 /* We succeeded; return this descriptor and filename. */
1648 if (storeptr)
1649 *storeptr = string;
1650 SAFE_FREE ();
1651 return -2;
1654 else
1656 int fd;
1657 const char *pfn;
1658 struct stat st;
1660 encoded_fn = ENCODE_FILE (string);
1661 pfn = SSDATA (encoded_fn);
1663 /* Check that we can access or open it. */
1664 if (NATNUMP (predicate))
1666 fd = -1;
1667 if (INT_MAX < XFASTINT (predicate))
1668 last_errno = EINVAL;
1669 else if (faccessat (AT_FDCWD, pfn, XFASTINT (predicate),
1670 AT_EACCESS)
1671 == 0)
1673 if (file_directory_p (pfn))
1674 last_errno = EISDIR;
1675 else
1676 fd = 1;
1679 else
1681 fd = emacs_open (pfn, O_RDONLY, 0);
1682 if (fd < 0)
1684 if (errno != ENOENT)
1685 last_errno = errno;
1687 else
1689 int err = (fstat (fd, &st) != 0 ? errno
1690 : S_ISDIR (st.st_mode) ? EISDIR : 0);
1691 if (err)
1693 last_errno = err;
1694 emacs_close (fd);
1695 fd = -1;
1700 if (fd >= 0)
1702 if (newer && !NATNUMP (predicate))
1704 struct timespec mtime = get_stat_mtime (&st);
1706 if (timespec_cmp (mtime, save_mtime) <= 0)
1707 emacs_close (fd);
1708 else
1710 if (0 <= save_fd)
1711 emacs_close (save_fd);
1712 save_fd = fd;
1713 save_mtime = mtime;
1714 save_string = string;
1717 else
1719 /* We succeeded; return this descriptor and filename. */
1720 if (storeptr)
1721 *storeptr = string;
1722 SAFE_FREE ();
1723 return fd;
1727 /* No more suffixes. Return the newest. */
1728 if (0 <= save_fd && ! CONSP (XCDR (tail)))
1730 if (storeptr)
1731 *storeptr = save_string;
1732 SAFE_FREE ();
1733 return save_fd;
1737 if (absolute)
1738 break;
1741 SAFE_FREE ();
1742 errno = last_errno;
1743 return -1;
1747 /* Merge the list we've accumulated of globals from the current input source
1748 into the load_history variable. The details depend on whether
1749 the source has an associated file name or not.
1751 FILENAME is the file name that we are loading from.
1753 ENTIRE is true if loading that entire file, false if evaluating
1754 part of it. */
1756 static void
1757 build_load_history (Lisp_Object filename, bool entire)
1759 Lisp_Object tail, prev, newelt;
1760 Lisp_Object tem, tem2;
1761 bool foundit = 0;
1763 tail = Vload_history;
1764 prev = Qnil;
1766 while (CONSP (tail))
1768 tem = XCAR (tail);
1770 /* Find the feature's previous assoc list... */
1771 if (!NILP (Fequal (filename, Fcar (tem))))
1773 foundit = 1;
1775 /* If we're loading the entire file, remove old data. */
1776 if (entire)
1778 if (NILP (prev))
1779 Vload_history = XCDR (tail);
1780 else
1781 Fsetcdr (prev, XCDR (tail));
1784 /* Otherwise, cons on new symbols that are not already members. */
1785 else
1787 tem2 = Vcurrent_load_list;
1789 while (CONSP (tem2))
1791 newelt = XCAR (tem2);
1793 if (NILP (Fmember (newelt, tem)))
1794 Fsetcar (tail, Fcons (XCAR (tem),
1795 Fcons (newelt, XCDR (tem))));
1797 tem2 = XCDR (tem2);
1798 maybe_quit ();
1802 else
1803 prev = tail;
1804 tail = XCDR (tail);
1805 maybe_quit ();
1808 /* If we're loading an entire file, cons the new assoc onto the
1809 front of load-history, the most-recently-loaded position. Also
1810 do this if we didn't find an existing member for the file. */
1811 if (entire || !foundit)
1812 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1813 Vload_history);
1816 static void
1817 readevalloop_1 (int old)
1819 load_convert_to_unibyte = old;
1822 /* Signal an `end-of-file' error, if possible with file name
1823 information. */
1825 static _Noreturn void
1826 end_of_file_error (void)
1828 if (STRINGP (Vload_file_name))
1829 xsignal1 (Qend_of_file, Vload_file_name);
1831 xsignal0 (Qend_of_file);
1834 static Lisp_Object
1835 readevalloop_eager_expand_eval (Lisp_Object val, Lisp_Object macroexpand)
1837 /* If we macroexpand the toplevel form non-recursively and it ends
1838 up being a `progn' (or if it was a progn to start), treat each
1839 form in the progn as a top-level form. This way, if one form in
1840 the progn defines a macro, that macro is in effect when we expand
1841 the remaining forms. See similar code in bytecomp.el. */
1842 val = call2 (macroexpand, val, Qnil);
1843 if (EQ (CAR_SAFE (val), Qprogn))
1845 Lisp_Object subforms = XCDR (val);
1847 for (val = Qnil; CONSP (subforms); subforms = XCDR (subforms))
1848 val = readevalloop_eager_expand_eval (XCAR (subforms),
1849 macroexpand);
1851 else
1852 val = eval_sub (call2 (macroexpand, val, Qt));
1853 return val;
1856 /* UNIBYTE specifies how to set load_convert_to_unibyte
1857 for this invocation.
1858 READFUN, if non-nil, is used instead of `read'.
1860 START, END specify region to read in current buffer (from eval-region).
1861 If the input is not from a buffer, they must be nil. */
1863 static void
1864 readevalloop (Lisp_Object readcharfun,
1865 struct infile *infile0,
1866 Lisp_Object sourcename,
1867 bool printflag,
1868 Lisp_Object unibyte, Lisp_Object readfun,
1869 Lisp_Object start, Lisp_Object end)
1871 int c;
1872 Lisp_Object val;
1873 ptrdiff_t count = SPECPDL_INDEX ();
1874 struct buffer *b = 0;
1875 bool continue_reading_p;
1876 Lisp_Object lex_bound;
1877 /* True if reading an entire buffer. */
1878 bool whole_buffer = 0;
1879 /* True on the first time around. */
1880 bool first_sexp = 1;
1881 Lisp_Object macroexpand = intern ("internal-macroexpand-for-load");
1883 if (NILP (Ffboundp (macroexpand))
1884 /* Don't macroexpand in .elc files, since it should have been done
1885 already. We actually don't know whether we're in a .elc file or not,
1886 so we use circumstantial evidence: .el files normally go through
1887 Vload_source_file_function -> load-with-code-conversion
1888 -> eval-buffer. */
1889 || EQ (readcharfun, Qget_file_char)
1890 || EQ (readcharfun, Qget_emacs_mule_file_char))
1891 macroexpand = Qnil;
1893 if (MARKERP (readcharfun))
1895 if (NILP (start))
1896 start = readcharfun;
1899 if (BUFFERP (readcharfun))
1900 b = XBUFFER (readcharfun);
1901 else if (MARKERP (readcharfun))
1902 b = XMARKER (readcharfun)->buffer;
1904 /* We assume START is nil when input is not from a buffer. */
1905 if (! NILP (start) && !b)
1906 emacs_abort ();
1908 specbind (Qstandard_input, readcharfun);
1909 specbind (Qcurrent_load_list, Qnil);
1910 record_unwind_protect_int (readevalloop_1, load_convert_to_unibyte);
1911 load_convert_to_unibyte = !NILP (unibyte);
1913 /* If lexical binding is active (either because it was specified in
1914 the file's header, or via a buffer-local variable), create an empty
1915 lexical environment, otherwise, turn off lexical binding. */
1916 lex_bound = find_symbol_value (Qlexical_binding);
1917 specbind (Qinternal_interpreter_environment,
1918 (NILP (lex_bound) || EQ (lex_bound, Qunbound)
1919 ? Qnil : list1 (Qt)));
1921 /* Try to ensure sourcename is a truename, except whilst preloading. */
1922 if (NILP (Vpurify_flag)
1923 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename))
1924 && !NILP (Ffboundp (Qfile_truename)))
1925 sourcename = call1 (Qfile_truename, sourcename) ;
1927 LOADHIST_ATTACH (sourcename);
1929 continue_reading_p = 1;
1930 while (continue_reading_p)
1932 ptrdiff_t count1 = SPECPDL_INDEX ();
1934 if (b != 0 && !BUFFER_LIVE_P (b))
1935 error ("Reading from killed buffer");
1937 if (!NILP (start))
1939 /* Switch to the buffer we are reading from. */
1940 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1941 set_buffer_internal (b);
1943 /* Save point in it. */
1944 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1945 /* Save ZV in it. */
1946 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1947 /* Those get unbound after we read one expression. */
1949 /* Set point and ZV around stuff to be read. */
1950 Fgoto_char (start);
1951 if (!NILP (end))
1952 Fnarrow_to_region (make_number (BEGV), end);
1954 /* Just for cleanliness, convert END to a marker
1955 if it is an integer. */
1956 if (INTEGERP (end))
1957 end = Fpoint_max_marker ();
1960 /* On the first cycle, we can easily test here
1961 whether we are reading the whole buffer. */
1962 if (b && first_sexp)
1963 whole_buffer = (BUF_PT (b) == BUF_BEG (b) && BUF_ZV (b) == BUF_Z (b));
1965 infile = infile0;
1966 read_next:
1967 c = READCHAR;
1968 if (c == ';')
1970 while ((c = READCHAR) != '\n' && c != -1);
1971 goto read_next;
1973 if (c < 0)
1975 unbind_to (count1, Qnil);
1976 break;
1979 /* Ignore whitespace here, so we can detect eof. */
1980 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'
1981 || c == NO_BREAK_SPACE)
1982 goto read_next;
1984 if (! HASH_TABLE_P (read_objects_map)
1985 || XHASH_TABLE (read_objects_map)->count)
1986 read_objects_map
1987 = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE,
1988 DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD,
1989 Qnil, false);
1990 if (! HASH_TABLE_P (read_objects_completed)
1991 || XHASH_TABLE (read_objects_completed)->count)
1992 read_objects_completed
1993 = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE,
1994 DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD,
1995 Qnil, false);
1996 if (!NILP (Vpurify_flag) && c == '(')
1998 val = read_list (0, readcharfun);
2000 else
2002 UNREAD (c);
2003 if (!NILP (readfun))
2005 val = call1 (readfun, readcharfun);
2007 /* If READCHARFUN has set point to ZV, we should
2008 stop reading, even if the form read sets point
2009 to a different value when evaluated. */
2010 if (BUFFERP (readcharfun))
2012 struct buffer *buf = XBUFFER (readcharfun);
2013 if (BUF_PT (buf) == BUF_ZV (buf))
2014 continue_reading_p = 0;
2017 else if (! NILP (Vload_read_function))
2018 val = call1 (Vload_read_function, readcharfun);
2019 else
2020 val = read_internal_start (readcharfun, Qnil, Qnil);
2022 /* Empty hashes can be reused; otherwise, reset on next call. */
2023 if (HASH_TABLE_P (read_objects_map)
2024 && XHASH_TABLE (read_objects_map)->count > 0)
2025 read_objects_map = Qnil;
2026 if (HASH_TABLE_P (read_objects_completed)
2027 && XHASH_TABLE (read_objects_completed)->count > 0)
2028 read_objects_completed = Qnil;
2030 if (!NILP (start) && continue_reading_p)
2031 start = Fpoint_marker ();
2033 /* Restore saved point and BEGV. */
2034 unbind_to (count1, Qnil);
2036 /* Now eval what we just read. */
2037 if (!NILP (macroexpand))
2038 val = readevalloop_eager_expand_eval (val, macroexpand);
2039 else
2040 val = eval_sub (val);
2042 if (printflag)
2044 Vvalues = Fcons (val, Vvalues);
2045 if (EQ (Vstandard_output, Qt))
2046 Fprin1 (val, Qnil);
2047 else
2048 Fprint (val, Qnil);
2051 first_sexp = 0;
2054 build_load_history (sourcename,
2055 infile0 || whole_buffer);
2057 unbind_to (count, Qnil);
2060 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
2061 doc: /* Execute the accessible portion of current buffer as Lisp code.
2062 You can use \\[narrow-to-region] to limit the part of buffer to be evaluated.
2063 When called from a Lisp program (i.e., not interactively), this
2064 function accepts up to five optional arguments:
2065 BUFFER is the buffer to evaluate (nil means use current buffer),
2066 or a name of a buffer (a string).
2067 PRINTFLAG controls printing of output by any output functions in the
2068 evaluated code, such as `print', `princ', and `prin1':
2069 a value of nil means discard it; anything else is the stream to print to.
2070 See Info node `(elisp)Output Streams' for details on streams.
2071 FILENAME specifies the file name to use for `load-history'.
2072 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
2073 invocation.
2074 DO-ALLOW-PRINT, if non-nil, specifies that output functions in the
2075 evaluated code should work normally even if PRINTFLAG is nil, in
2076 which case the output is displayed in the echo area.
2078 This function preserves the position of point. */)
2079 (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print)
2081 ptrdiff_t count = SPECPDL_INDEX ();
2082 Lisp_Object tem, buf;
2084 if (NILP (buffer))
2085 buf = Fcurrent_buffer ();
2086 else
2087 buf = Fget_buffer (buffer);
2088 if (NILP (buf))
2089 error ("No such buffer");
2091 if (NILP (printflag) && NILP (do_allow_print))
2092 tem = Qsymbolp;
2093 else
2094 tem = printflag;
2096 if (NILP (filename))
2097 filename = BVAR (XBUFFER (buf), filename);
2099 specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
2100 specbind (Qstandard_output, tem);
2101 record_unwind_protect (save_excursion_restore, save_excursion_save ());
2102 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
2103 specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ? Qt : Qnil);
2104 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
2105 readevalloop (buf, 0, filename,
2106 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
2107 unbind_to (count, Qnil);
2109 return Qnil;
2112 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
2113 doc: /* Execute the region as Lisp code.
2114 When called from programs, expects two arguments,
2115 giving starting and ending indices in the current buffer
2116 of the text to be executed.
2117 Programs can pass third argument PRINTFLAG which controls output:
2118 a value of nil means discard it; anything else is stream for printing it.
2119 See Info node `(elisp)Output Streams' for details on streams.
2120 Also the fourth argument READ-FUNCTION, if non-nil, is used
2121 instead of `read' to read each expression. It gets one argument
2122 which is the input stream for reading characters.
2124 This function does not move point. */)
2125 (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function)
2127 /* FIXME: Do the eval-sexp-add-defvars dance! */
2128 ptrdiff_t count = SPECPDL_INDEX ();
2129 Lisp_Object tem, cbuf;
2131 cbuf = Fcurrent_buffer ();
2133 if (NILP (printflag))
2134 tem = Qsymbolp;
2135 else
2136 tem = printflag;
2137 specbind (Qstandard_output, tem);
2138 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list));
2140 /* `readevalloop' calls functions which check the type of start and end. */
2141 readevalloop (cbuf, 0, BVAR (XBUFFER (cbuf), filename),
2142 !NILP (printflag), Qnil, read_function,
2143 start, end);
2145 return unbind_to (count, Qnil);
2149 DEFUN ("read", Fread, Sread, 0, 1, 0,
2150 doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
2151 If STREAM is nil, use the value of `standard-input' (which see).
2152 STREAM or the value of `standard-input' may be:
2153 a buffer (read from point and advance it)
2154 a marker (read from where it points and advance it)
2155 a function (call it with no arguments for each character,
2156 call it with a char as argument to push a char back)
2157 a string (takes text from string, starting at the beginning)
2158 t (read text line using minibuffer and use it, or read from
2159 standard input in batch mode). */)
2160 (Lisp_Object stream)
2162 if (NILP (stream))
2163 stream = Vstandard_input;
2164 if (EQ (stream, Qt))
2165 stream = Qread_char;
2166 if (EQ (stream, Qread_char))
2167 /* FIXME: ?! When is this used !? */
2168 return call1 (intern ("read-minibuffer"),
2169 build_string ("Lisp expression: "));
2171 return read_internal_start (stream, Qnil, Qnil);
2174 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
2175 doc: /* Read one Lisp expression which is represented as text by STRING.
2176 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
2177 FINAL-STRING-INDEX is an integer giving the position of the next
2178 remaining character in STRING. START and END optionally delimit
2179 a substring of STRING from which to read; they default to 0 and
2180 \(length STRING) respectively. Negative values are counted from
2181 the end of STRING. */)
2182 (Lisp_Object string, Lisp_Object start, Lisp_Object end)
2184 Lisp_Object ret;
2185 CHECK_STRING (string);
2186 /* `read_internal_start' sets `read_from_string_index'. */
2187 ret = read_internal_start (string, start, end);
2188 return Fcons (ret, make_number (read_from_string_index));
2191 /* Function to set up the global context we need in toplevel read
2192 calls. START and END only used when STREAM is a string. */
2193 static Lisp_Object
2194 read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
2196 Lisp_Object retval;
2198 readchar_count = 0;
2199 new_backquote_flag = 0;
2200 /* We can get called from readevalloop which may have set these
2201 already. */
2202 if (! HASH_TABLE_P (read_objects_map)
2203 || XHASH_TABLE (read_objects_map)->count)
2204 read_objects_map
2205 = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE, DEFAULT_REHASH_SIZE,
2206 DEFAULT_REHASH_THRESHOLD, Qnil, false);
2207 if (! HASH_TABLE_P (read_objects_completed)
2208 || XHASH_TABLE (read_objects_completed)->count)
2209 read_objects_completed
2210 = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE, DEFAULT_REHASH_SIZE,
2211 DEFAULT_REHASH_THRESHOLD, Qnil, false);
2212 if (EQ (Vread_with_symbol_positions, Qt)
2213 || EQ (Vread_with_symbol_positions, stream))
2214 Vread_symbol_positions_list = Qnil;
2216 if (STRINGP (stream)
2217 || ((CONSP (stream) && STRINGP (XCAR (stream)))))
2219 ptrdiff_t startval, endval;
2220 Lisp_Object string;
2222 if (STRINGP (stream))
2223 string = stream;
2224 else
2225 string = XCAR (stream);
2227 validate_subarray (string, start, end, SCHARS (string),
2228 &startval, &endval);
2230 read_from_string_index = startval;
2231 read_from_string_index_byte = string_char_to_byte (string, startval);
2232 read_from_string_limit = endval;
2235 retval = read0 (stream);
2236 if (EQ (Vread_with_symbol_positions, Qt)
2237 || EQ (Vread_with_symbol_positions, stream))
2238 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list);
2239 /* Empty hashes can be reused; otherwise, reset on next call. */
2240 if (HASH_TABLE_P (read_objects_map)
2241 && XHASH_TABLE (read_objects_map)->count > 0)
2242 read_objects_map = Qnil;
2243 if (HASH_TABLE_P (read_objects_completed)
2244 && XHASH_TABLE (read_objects_completed)->count > 0)
2245 read_objects_completed = Qnil;
2246 return retval;
2250 /* Signal Qinvalid_read_syntax error.
2251 S is error string of length N (if > 0) */
2253 static _Noreturn void
2254 invalid_syntax (const char *s)
2256 xsignal1 (Qinvalid_read_syntax, build_string (s));
2260 /* Use this for recursive reads, in contexts where internal tokens
2261 are not allowed. */
2263 static Lisp_Object
2264 read0 (Lisp_Object readcharfun)
2266 register Lisp_Object val;
2267 int c;
2269 val = read1 (readcharfun, &c, 0);
2270 if (!c)
2271 return val;
2273 xsignal1 (Qinvalid_read_syntax,
2274 Fmake_string (make_number (1), make_number (c)));
2277 /* Grow a read buffer BUF that contains OFFSET useful bytes of data,
2278 by at least MAX_MULTIBYTE_LENGTH bytes. Update *BUF_ADDR and
2279 *BUF_SIZE accordingly; 0 <= OFFSET <= *BUF_SIZE. If *BUF_ADDR is
2280 initially null, BUF is on the stack: copy its data to the new heap
2281 buffer. Otherwise, BUF must equal *BUF_ADDR and can simply be
2282 reallocated. Either way, remember the heap allocation (which is at
2283 pdl slot COUNT) so that it can be freed when unwinding the stack.*/
2285 static char *
2286 grow_read_buffer (char *buf, ptrdiff_t offset,
2287 char **buf_addr, ptrdiff_t *buf_size, ptrdiff_t count)
2289 char *p = xpalloc (*buf_addr, buf_size, MAX_MULTIBYTE_LENGTH, -1, 1);
2290 if (!*buf_addr)
2292 memcpy (p, buf, offset);
2293 record_unwind_protect_ptr (xfree, p);
2295 else
2296 set_unwind_protect_ptr (count, xfree, p);
2297 *buf_addr = p;
2298 return p;
2301 /* Return the scalar value that has the Unicode character name NAME.
2302 Raise 'invalid-read-syntax' if there is no such character. */
2303 static int
2304 character_name_to_code (char const *name, ptrdiff_t name_len)
2306 /* For "U+XXXX", pass the leading '+' to string_to_number to reject
2307 monstrosities like "U+-0000". */
2308 Lisp_Object code
2309 = (name[0] == 'U' && name[1] == '+'
2310 ? string_to_number (name + 1, 16, false)
2311 : call2 (Qchar_from_name, make_unibyte_string (name, name_len), Qt));
2313 if (! RANGED_INTEGERP (0, code, MAX_UNICODE_CHAR)
2314 || char_surrogate_p (XINT (code)))
2316 AUTO_STRING (format, "\\N{%s}");
2317 AUTO_STRING_WITH_LEN (namestr, name, name_len);
2318 xsignal1 (Qinvalid_read_syntax, CALLN (Fformat, format, namestr));
2321 return XINT (code);
2324 /* Bound on the length of a Unicode character name. As of
2325 Unicode 9.0.0 the maximum is 83, so this should be safe. */
2326 enum { UNICODE_CHARACTER_NAME_LENGTH_BOUND = 200 };
2328 /* Read a \-escape sequence, assuming we already read the `\'.
2329 If the escape sequence forces unibyte, return eight-bit char. */
2331 static int
2332 read_escape (Lisp_Object readcharfun, bool stringp)
2334 int c = READCHAR;
2335 /* \u allows up to four hex digits, \U up to eight. Default to the
2336 behavior for \u, and change this value in the case that \U is seen. */
2337 int unicode_hex_count = 4;
2339 switch (c)
2341 case -1:
2342 end_of_file_error ();
2344 case 'a':
2345 return '\007';
2346 case 'b':
2347 return '\b';
2348 case 'd':
2349 return 0177;
2350 case 'e':
2351 return 033;
2352 case 'f':
2353 return '\f';
2354 case 'n':
2355 return '\n';
2356 case 'r':
2357 return '\r';
2358 case 't':
2359 return '\t';
2360 case 'v':
2361 return '\v';
2362 case '\n':
2363 return -1;
2364 case ' ':
2365 if (stringp)
2366 return -1;
2367 return ' ';
2369 case 'M':
2370 c = READCHAR;
2371 if (c != '-')
2372 error ("Invalid escape character syntax");
2373 c = READCHAR;
2374 if (c == '\\')
2375 c = read_escape (readcharfun, 0);
2376 return c | meta_modifier;
2378 case 'S':
2379 c = READCHAR;
2380 if (c != '-')
2381 error ("Invalid escape character syntax");
2382 c = READCHAR;
2383 if (c == '\\')
2384 c = read_escape (readcharfun, 0);
2385 return c | shift_modifier;
2387 case 'H':
2388 c = READCHAR;
2389 if (c != '-')
2390 error ("Invalid escape character syntax");
2391 c = READCHAR;
2392 if (c == '\\')
2393 c = read_escape (readcharfun, 0);
2394 return c | hyper_modifier;
2396 case 'A':
2397 c = READCHAR;
2398 if (c != '-')
2399 error ("Invalid escape character syntax");
2400 c = READCHAR;
2401 if (c == '\\')
2402 c = read_escape (readcharfun, 0);
2403 return c | alt_modifier;
2405 case 's':
2406 c = READCHAR;
2407 if (stringp || c != '-')
2409 UNREAD (c);
2410 return ' ';
2412 c = READCHAR;
2413 if (c == '\\')
2414 c = read_escape (readcharfun, 0);
2415 return c | super_modifier;
2417 case 'C':
2418 c = READCHAR;
2419 if (c != '-')
2420 error ("Invalid escape character syntax");
2421 FALLTHROUGH;
2422 case '^':
2423 c = READCHAR;
2424 if (c == '\\')
2425 c = read_escape (readcharfun, 0);
2426 if ((c & ~CHAR_MODIFIER_MASK) == '?')
2427 return 0177 | (c & CHAR_MODIFIER_MASK);
2428 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
2429 return c | ctrl_modifier;
2430 /* ASCII control chars are made from letters (both cases),
2431 as well as the non-letters within 0100...0137. */
2432 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
2433 return (c & (037 | ~0177));
2434 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
2435 return (c & (037 | ~0177));
2436 else
2437 return c | ctrl_modifier;
2439 case '0':
2440 case '1':
2441 case '2':
2442 case '3':
2443 case '4':
2444 case '5':
2445 case '6':
2446 case '7':
2447 /* An octal escape, as in ANSI C. */
2449 register int i = c - '0';
2450 register int count = 0;
2451 while (++count < 3)
2453 if ((c = READCHAR) >= '0' && c <= '7')
2455 i *= 8;
2456 i += c - '0';
2458 else
2460 UNREAD (c);
2461 break;
2465 if (i >= 0x80 && i < 0x100)
2466 i = BYTE8_TO_CHAR (i);
2467 return i;
2470 case 'x':
2471 /* A hex escape, as in ANSI C. */
2473 unsigned int i = 0;
2474 int count = 0;
2475 while (1)
2477 c = READCHAR;
2478 int digit = char_hexdigit (c);
2479 if (digit < 0)
2481 UNREAD (c);
2482 break;
2484 i = (i << 4) + digit;
2485 /* Allow hex escapes as large as ?\xfffffff, because some
2486 packages use them to denote characters with modifiers. */
2487 if ((CHAR_META | (CHAR_META - 1)) < i)
2488 error ("Hex character out of range: \\x%x...", i);
2489 count += count < 3;
2492 if (count < 3 && i >= 0x80)
2493 return BYTE8_TO_CHAR (i);
2494 return i;
2497 case 'U':
2498 /* Post-Unicode-2.0: Up to eight hex chars. */
2499 unicode_hex_count = 8;
2500 FALLTHROUGH;
2501 case 'u':
2503 /* A Unicode escape. We only permit them in strings and characters,
2504 not arbitrarily in the source code, as in some other languages. */
2506 unsigned int i = 0;
2507 int count = 0;
2509 while (++count <= unicode_hex_count)
2511 c = READCHAR;
2512 /* `isdigit' and `isalpha' may be locale-specific, which we don't
2513 want. */
2514 int digit = char_hexdigit (c);
2515 if (digit < 0)
2516 error ("Non-hex digit used for Unicode escape");
2517 i = (i << 4) + digit;
2519 if (i > 0x10FFFF)
2520 error ("Non-Unicode character: 0x%x", i);
2521 return i;
2524 case 'N':
2525 /* Named character. */
2527 c = READCHAR;
2528 if (c != '{')
2529 invalid_syntax ("Expected opening brace after \\N");
2530 char name[UNICODE_CHARACTER_NAME_LENGTH_BOUND + 1];
2531 bool whitespace = false;
2532 ptrdiff_t length = 0;
2533 while (true)
2535 c = READCHAR;
2536 if (c < 0)
2537 end_of_file_error ();
2538 if (c == '}')
2539 break;
2540 if (! (0 < c && c < 0x80))
2542 AUTO_STRING (format,
2543 "Invalid character U+%04X in character name");
2544 xsignal1 (Qinvalid_read_syntax,
2545 CALLN (Fformat, format, make_natnum (c)));
2547 /* Treat multiple adjacent whitespace characters as a
2548 single space character. This makes it easier to use
2549 character names in e.g. multi-line strings. */
2550 if (c_isspace (c))
2552 if (whitespace)
2553 continue;
2554 c = ' ';
2555 whitespace = true;
2557 else
2558 whitespace = false;
2559 name[length++] = c;
2560 if (length >= sizeof name)
2561 invalid_syntax ("Character name too long");
2563 if (length == 0)
2564 invalid_syntax ("Empty character name");
2565 name[length] = '\0';
2567 /* character_name_to_code can invoke read1, recursively.
2568 This is why read1's buffer is not static. */
2569 return character_name_to_code (name, length);
2572 default:
2573 return c;
2577 /* Return the digit that CHARACTER stands for in the given BASE.
2578 Return -1 if CHARACTER is out of range for BASE,
2579 and -2 if CHARACTER is not valid for any supported BASE. */
2580 static int
2581 digit_to_number (int character, int base)
2583 int digit;
2585 if ('0' <= character && character <= '9')
2586 digit = character - '0';
2587 else if ('a' <= character && character <= 'z')
2588 digit = character - 'a' + 10;
2589 else if ('A' <= character && character <= 'Z')
2590 digit = character - 'A' + 10;
2591 else
2592 return -2;
2594 return digit < base ? digit : -1;
2597 /* Read an integer in radix RADIX using READCHARFUN to read
2598 characters. RADIX must be in the interval [2..36]; if it isn't, a
2599 read error is signaled . Value is the integer read. Signals an
2600 error if encountering invalid read syntax or if RADIX is out of
2601 range. */
2603 static Lisp_Object
2604 read_integer (Lisp_Object readcharfun, EMACS_INT radix)
2606 /* Room for sign, leading 0, other digits, trailing null byte.
2607 Also, room for invalid syntax diagnostic. */
2608 char buf[max (1 + 1 + UINTMAX_WIDTH + 1,
2609 sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT))];
2611 int valid = -1; /* 1 if valid, 0 if not, -1 if incomplete. */
2613 if (radix < 2 || radix > 36)
2614 valid = 0;
2615 else
2617 char *p = buf;
2618 int c, digit;
2620 c = READCHAR;
2621 if (c == '-' || c == '+')
2623 *p++ = c;
2624 c = READCHAR;
2627 if (c == '0')
2629 *p++ = c;
2630 valid = 1;
2632 /* Ignore redundant leading zeros, so the buffer doesn't
2633 fill up with them. */
2635 c = READCHAR;
2636 while (c == '0');
2639 while ((digit = digit_to_number (c, radix)) >= -1)
2641 if (digit == -1)
2642 valid = 0;
2643 if (valid < 0)
2644 valid = 1;
2646 if (p < buf + sizeof buf - 1)
2647 *p++ = c;
2648 else
2649 valid = 0;
2651 c = READCHAR;
2654 UNREAD (c);
2655 *p = '\0';
2658 if (valid != 1)
2660 sprintf (buf, "integer, radix %"pI"d", radix);
2661 invalid_syntax (buf);
2664 return string_to_number (buf, radix, 0);
2668 /* If the next token is ')' or ']' or '.', we store that character
2669 in *PCH and the return value is not interesting. Else, we store
2670 zero in *PCH and we read and return one lisp object.
2672 FIRST_IN_LIST is true if this is the first element of a list. */
2674 static Lisp_Object
2675 read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
2677 int c;
2678 bool uninterned_symbol = false;
2679 bool multibyte;
2680 char stackbuf[MAX_ALLOCA];
2681 current_thread->stack_top = stackbuf;
2683 *pch = 0;
2685 retry:
2687 c = READCHAR_REPORT_MULTIBYTE (&multibyte);
2688 if (c < 0)
2689 end_of_file_error ();
2691 switch (c)
2693 case '(':
2694 return read_list (0, readcharfun);
2696 case '[':
2697 return read_vector (readcharfun, 0);
2699 case ')':
2700 case ']':
2702 *pch = c;
2703 return Qnil;
2706 case '#':
2707 c = READCHAR;
2708 if (c == 's')
2710 c = READCHAR;
2711 if (c == '(')
2713 /* Accept extended format for hash tables (extensible to
2714 other types), e.g.
2715 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2716 Lisp_Object tmp = read_list (0, readcharfun);
2717 Lisp_Object head = CAR_SAFE (tmp);
2718 Lisp_Object data = Qnil;
2719 Lisp_Object val = Qnil;
2720 /* The size is 2 * number of allowed keywords to
2721 make-hash-table. */
2722 Lisp_Object params[12];
2723 Lisp_Object ht;
2724 Lisp_Object key = Qnil;
2725 int param_count = 0;
2727 if (!EQ (head, Qhash_table))
2729 ptrdiff_t size = XINT (Flength (tmp));
2730 Lisp_Object record = Fmake_record (CAR_SAFE (tmp),
2731 make_number (size - 1),
2732 Qnil);
2733 for (int i = 1; i < size; i++)
2735 tmp = Fcdr (tmp);
2736 ASET (record, i, Fcar (tmp));
2738 return record;
2741 tmp = CDR_SAFE (tmp);
2743 /* This is repetitive but fast and simple. */
2744 params[param_count] = QCsize;
2745 params[param_count + 1] = Fplist_get (tmp, Qsize);
2746 if (!NILP (params[param_count + 1]))
2747 param_count += 2;
2749 params[param_count] = QCtest;
2750 params[param_count + 1] = Fplist_get (tmp, Qtest);
2751 if (!NILP (params[param_count + 1]))
2752 param_count += 2;
2754 params[param_count] = QCweakness;
2755 params[param_count + 1] = Fplist_get (tmp, Qweakness);
2756 if (!NILP (params[param_count + 1]))
2757 param_count += 2;
2759 params[param_count] = QCrehash_size;
2760 params[param_count + 1] = Fplist_get (tmp, Qrehash_size);
2761 if (!NILP (params[param_count + 1]))
2762 param_count += 2;
2764 params[param_count] = QCrehash_threshold;
2765 params[param_count + 1] = Fplist_get (tmp, Qrehash_threshold);
2766 if (!NILP (params[param_count + 1]))
2767 param_count += 2;
2769 params[param_count] = QCpurecopy;
2770 params[param_count + 1] = Fplist_get (tmp, Qpurecopy);
2771 if (!NILP (params[param_count + 1]))
2772 param_count += 2;
2774 /* This is the hash table data. */
2775 data = Fplist_get (tmp, Qdata);
2777 /* Now use params to make a new hash table and fill it. */
2778 ht = Fmake_hash_table (param_count, params);
2780 while (CONSP (data))
2782 key = XCAR (data);
2783 data = XCDR (data);
2784 if (!CONSP (data))
2785 error ("Odd number of elements in hash table data");
2786 val = XCAR (data);
2787 data = XCDR (data);
2788 Fputhash (key, val, ht);
2791 return ht;
2793 UNREAD (c);
2794 invalid_syntax ("#");
2796 if (c == '^')
2798 c = READCHAR;
2799 if (c == '[')
2801 Lisp_Object tmp;
2802 tmp = read_vector (readcharfun, 0);
2803 if (ASIZE (tmp) < CHAR_TABLE_STANDARD_SLOTS)
2804 error ("Invalid size char-table");
2805 XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE);
2806 return tmp;
2808 else if (c == '^')
2810 c = READCHAR;
2811 if (c == '[')
2813 /* Sub char-table can't be read as a regular
2814 vector because of a two C integer fields. */
2815 Lisp_Object tbl, tmp = read_list (1, readcharfun);
2816 ptrdiff_t size = XINT (Flength (tmp));
2817 int i, depth, min_char;
2818 struct Lisp_Cons *cell;
2820 if (size == 0)
2821 error ("Zero-sized sub char-table");
2823 if (! RANGED_INTEGERP (1, XCAR (tmp), 3))
2824 error ("Invalid depth in sub char-table");
2825 depth = XINT (XCAR (tmp));
2826 if (chartab_size[depth] != size - 2)
2827 error ("Invalid size in sub char-table");
2828 cell = XCONS (tmp), tmp = XCDR (tmp), size--;
2829 free_cons (cell);
2831 if (! RANGED_INTEGERP (0, XCAR (tmp), MAX_CHAR))
2832 error ("Invalid minimum character in sub-char-table");
2833 min_char = XINT (XCAR (tmp));
2834 cell = XCONS (tmp), tmp = XCDR (tmp), size--;
2835 free_cons (cell);
2837 tbl = make_uninit_sub_char_table (depth, min_char);
2838 for (i = 0; i < size; i++)
2840 XSUB_CHAR_TABLE (tbl)->contents[i] = XCAR (tmp);
2841 cell = XCONS (tmp), tmp = XCDR (tmp);
2842 free_cons (cell);
2844 return tbl;
2846 invalid_syntax ("#^^");
2848 invalid_syntax ("#^");
2850 if (c == '&')
2852 Lisp_Object length;
2853 length = read1 (readcharfun, pch, first_in_list);
2854 c = READCHAR;
2855 if (c == '"')
2857 Lisp_Object tmp, val;
2858 EMACS_INT size_in_chars = bool_vector_bytes (XFASTINT (length));
2859 unsigned char *data;
2861 UNREAD (c);
2862 tmp = read1 (readcharfun, pch, first_in_list);
2863 if (STRING_MULTIBYTE (tmp)
2864 || (size_in_chars != SCHARS (tmp)
2865 /* We used to print 1 char too many
2866 when the number of bits was a multiple of 8.
2867 Accept such input in case it came from an old
2868 version. */
2869 && ! (XFASTINT (length)
2870 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
2871 invalid_syntax ("#&...");
2873 val = make_uninit_bool_vector (XFASTINT (length));
2874 data = bool_vector_uchar_data (val);
2875 memcpy (data, SDATA (tmp), size_in_chars);
2876 /* Clear the extraneous bits in the last byte. */
2877 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
2878 data[size_in_chars - 1]
2879 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2880 return val;
2882 invalid_syntax ("#&...");
2884 if (c == '[')
2886 /* Accept compiled functions at read-time so that we don't have to
2887 build them using function calls. */
2888 Lisp_Object tmp;
2889 struct Lisp_Vector *vec;
2890 tmp = read_vector (readcharfun, 1);
2891 vec = XVECTOR (tmp);
2892 if (vec->header.size == 0)
2893 invalid_syntax ("Empty byte-code object");
2894 make_byte_code (vec);
2895 return tmp;
2897 if (c == '(')
2899 Lisp_Object tmp;
2900 int ch;
2902 /* Read the string itself. */
2903 tmp = read1 (readcharfun, &ch, 0);
2904 if (ch != 0 || !STRINGP (tmp))
2905 invalid_syntax ("#");
2906 /* Read the intervals and their properties. */
2907 while (1)
2909 Lisp_Object beg, end, plist;
2911 beg = read1 (readcharfun, &ch, 0);
2912 end = plist = Qnil;
2913 if (ch == ')')
2914 break;
2915 if (ch == 0)
2916 end = read1 (readcharfun, &ch, 0);
2917 if (ch == 0)
2918 plist = read1 (readcharfun, &ch, 0);
2919 if (ch)
2920 invalid_syntax ("Invalid string property list");
2921 Fset_text_properties (beg, end, plist, tmp);
2924 return tmp;
2927 /* #@NUMBER is used to skip NUMBER following bytes.
2928 That's used in .elc files to skip over doc strings
2929 and function definitions. */
2930 if (c == '@')
2932 enum { extra = 100 };
2933 ptrdiff_t i, nskip = 0, digits = 0;
2935 /* Read a decimal integer. */
2936 while ((c = READCHAR) >= 0
2937 && c >= '0' && c <= '9')
2939 if ((STRING_BYTES_BOUND - extra) / 10 <= nskip)
2940 string_overflow ();
2941 digits++;
2942 nskip *= 10;
2943 nskip += c - '0';
2944 if (digits == 2 && nskip == 0)
2945 { /* We've just seen #@00, which means "skip to end". */
2946 skip_dyn_eof (readcharfun);
2947 return Qnil;
2950 if (nskip > 0)
2951 /* We can't use UNREAD here, because in the code below we side-step
2952 READCHAR. Instead, assume the first char after #@NNN occupies
2953 a single byte, which is the case normally since it's just
2954 a space. */
2955 nskip--;
2956 else
2957 UNREAD (c);
2959 if (load_force_doc_strings
2960 && (FROM_FILE_P (readcharfun)))
2962 /* If we are supposed to force doc strings into core right now,
2963 record the last string that we skipped,
2964 and record where in the file it comes from. */
2966 /* But first exchange saved_doc_string
2967 with prev_saved_doc_string, so we save two strings. */
2969 char *temp = saved_doc_string;
2970 ptrdiff_t temp_size = saved_doc_string_size;
2971 file_offset temp_pos = saved_doc_string_position;
2972 ptrdiff_t temp_len = saved_doc_string_length;
2974 saved_doc_string = prev_saved_doc_string;
2975 saved_doc_string_size = prev_saved_doc_string_size;
2976 saved_doc_string_position = prev_saved_doc_string_position;
2977 saved_doc_string_length = prev_saved_doc_string_length;
2979 prev_saved_doc_string = temp;
2980 prev_saved_doc_string_size = temp_size;
2981 prev_saved_doc_string_position = temp_pos;
2982 prev_saved_doc_string_length = temp_len;
2985 if (saved_doc_string_size == 0)
2987 saved_doc_string = xmalloc (nskip + extra);
2988 saved_doc_string_size = nskip + extra;
2990 if (nskip > saved_doc_string_size)
2992 saved_doc_string = xrealloc (saved_doc_string, nskip + extra);
2993 saved_doc_string_size = nskip + extra;
2996 FILE *instream = infile->stream;
2997 saved_doc_string_position = (file_tell (instream)
2998 - infile->lookahead);
3000 /* Copy that many bytes into saved_doc_string. */
3001 i = 0;
3002 for (int n = min (nskip, infile->lookahead); 0 < n; n--)
3003 saved_doc_string[i++]
3004 = c = infile->buf[--infile->lookahead];
3005 block_input ();
3006 for (; i < nskip && 0 <= c; i++)
3007 saved_doc_string[i] = c = getc_unlocked (instream);
3008 unblock_input ();
3010 saved_doc_string_length = i;
3012 else
3013 /* Skip that many bytes. */
3014 skip_dyn_bytes (readcharfun, nskip);
3016 goto retry;
3018 if (c == '!')
3020 /* #! appears at the beginning of an executable file.
3021 Skip the first line. */
3022 while (c != '\n' && c >= 0)
3023 c = READCHAR;
3024 goto retry;
3026 if (c == '$')
3027 return Vload_file_name;
3028 if (c == '\'')
3029 return list2 (Qfunction, read0 (readcharfun));
3030 /* #:foo is the uninterned symbol named foo. */
3031 if (c == ':')
3033 uninterned_symbol = true;
3034 c = READCHAR;
3035 if (!(c > 040
3036 && c != NO_BREAK_SPACE
3037 && (c >= 0200
3038 || strchr ("\"';()[]#`,", c) == NULL)))
3040 /* No symbol character follows, this is the empty
3041 symbol. */
3042 UNREAD (c);
3043 return Fmake_symbol (empty_unibyte_string);
3045 goto read_symbol;
3047 /* ## is the empty symbol. */
3048 if (c == '#')
3049 return Fintern (empty_unibyte_string, Qnil);
3050 /* Reader forms that can reuse previously read objects. */
3051 if (c >= '0' && c <= '9')
3053 EMACS_INT n = 0;
3054 Lisp_Object tem;
3055 bool overflow = false;
3057 /* Read a non-negative integer. */
3058 while (c >= '0' && c <= '9')
3060 overflow |= INT_MULTIPLY_WRAPV (n, 10, &n);
3061 overflow |= INT_ADD_WRAPV (n, c - '0', &n);
3062 c = READCHAR;
3065 if (!overflow && n <= MOST_POSITIVE_FIXNUM)
3067 if (c == 'r' || c == 'R')
3068 return read_integer (readcharfun, n);
3070 if (! NILP (Vread_circle))
3072 /* #n=object returns object, but associates it with
3073 n for #n#. */
3074 if (c == '=')
3076 /* Make a placeholder for #n# to use temporarily. */
3077 /* Note: We used to use AUTO_CONS to allocate
3078 placeholder, but that is a bad idea, since it
3079 will place a stack-allocated cons cell into
3080 the list in read_objects_map, which is a
3081 staticpro'd global variable, and thus each of
3082 its elements is marked during each GC. A
3083 stack-allocated object will become garbled
3084 when its stack slot goes out of scope, and
3085 some other function reuses it for entirely
3086 different purposes, which will cause crashes
3087 in GC. */
3088 Lisp_Object placeholder = Fcons (Qnil, Qnil);
3089 struct Lisp_Hash_Table *h
3090 = XHASH_TABLE (read_objects_map);
3091 EMACS_UINT hash;
3092 Lisp_Object number = make_number (n);
3094 ptrdiff_t i = hash_lookup (h, number, &hash);
3095 if (i >= 0)
3096 /* Not normal, but input could be malformed. */
3097 set_hash_value_slot (h, i, placeholder);
3098 else
3099 hash_put (h, number, placeholder, hash);
3101 /* Read the object itself. */
3102 tem = read0 (readcharfun);
3104 /* If it can be recursive, remember it for
3105 future substitutions. */
3106 if (! SYMBOLP (tem)
3107 && ! NUMBERP (tem)
3108 && ! (STRINGP (tem) && !string_intervals (tem)))
3110 struct Lisp_Hash_Table *h2
3111 = XHASH_TABLE (read_objects_completed);
3112 i = hash_lookup (h2, tem, &hash);
3113 eassert (i < 0);
3114 hash_put (h2, tem, Qnil, hash);
3117 /* Now put it everywhere the placeholder was... */
3118 if (CONSP (tem))
3120 Fsetcar (placeholder, XCAR (tem));
3121 Fsetcdr (placeholder, XCDR (tem));
3122 return placeholder;
3124 else
3126 Flread__substitute_object_in_subtree
3127 (tem, placeholder, read_objects_completed);
3129 /* ...and #n# will use the real value from now on. */
3130 i = hash_lookup (h, number, &hash);
3131 eassert (i >= 0);
3132 set_hash_value_slot (h, i, tem);
3134 return tem;
3138 /* #n# returns a previously read object. */
3139 if (c == '#')
3141 struct Lisp_Hash_Table *h
3142 = XHASH_TABLE (read_objects_map);
3143 ptrdiff_t i = hash_lookup (h, make_number (n), NULL);
3144 if (i >= 0)
3145 return HASH_VALUE (h, i);
3149 /* Fall through to error message. */
3151 else if (c == 'x' || c == 'X')
3152 return read_integer (readcharfun, 16);
3153 else if (c == 'o' || c == 'O')
3154 return read_integer (readcharfun, 8);
3155 else if (c == 'b' || c == 'B')
3156 return read_integer (readcharfun, 2);
3158 UNREAD (c);
3159 invalid_syntax ("#");
3161 case ';':
3162 while ((c = READCHAR) >= 0 && c != '\n');
3163 goto retry;
3165 case '\'':
3166 return list2 (Qquote, read0 (readcharfun));
3168 case '`':
3170 int next_char = READCHAR;
3171 UNREAD (next_char);
3172 /* Transition from old-style to new-style:
3173 If we see "(`" it used to mean old-style, which usually works
3174 fine because ` should almost never appear in such a position
3175 for new-style. But occasionally we need "(`" to mean new
3176 style, so we try to distinguish the two by the fact that we
3177 can either write "( `foo" or "(` foo", where the first
3178 intends to use new-style whereas the second intends to use
3179 old-style. For Emacs-25, we should completely remove this
3180 first_in_list exception (old-style can still be obtained via
3181 "(\`" anyway). */
3182 if (!new_backquote_flag && first_in_list && next_char == ' ')
3184 Vlread_old_style_backquotes = Qt;
3185 goto default_label;
3187 else
3189 Lisp_Object value;
3190 bool saved_new_backquote_flag = new_backquote_flag;
3192 new_backquote_flag = 1;
3193 value = read0 (readcharfun);
3194 new_backquote_flag = saved_new_backquote_flag;
3196 return list2 (Qbackquote, value);
3199 case ',':
3201 int next_char = READCHAR;
3202 UNREAD (next_char);
3203 /* Transition from old-style to new-style:
3204 It used to be impossible to have a new-style , other than within
3205 a new-style `. This is sufficient when ` and , are used in the
3206 normal way, but ` and , can also appear in args to macros that
3207 will not interpret them in the usual way, in which case , may be
3208 used without any ` anywhere near.
3209 So we now use the same heuristic as for backquote: old-style
3210 unquotes are only recognized when first on a list, and when
3211 followed by a space.
3212 Because it's more difficult to peek 2 chars ahead, a new-style
3213 ,@ can still not be used outside of a `, unless it's in the middle
3214 of a list. */
3215 if (new_backquote_flag
3216 || !first_in_list
3217 || (next_char != ' ' && next_char != '@'))
3219 Lisp_Object comma_type = Qnil;
3220 Lisp_Object value;
3221 int ch = READCHAR;
3223 if (ch == '@')
3224 comma_type = Qcomma_at;
3225 else if (ch == '.')
3226 comma_type = Qcomma_dot;
3227 else
3229 if (ch >= 0) UNREAD (ch);
3230 comma_type = Qcomma;
3233 value = read0 (readcharfun);
3234 return list2 (comma_type, value);
3236 else
3238 Vlread_old_style_backquotes = Qt;
3239 goto default_label;
3242 case '?':
3244 int modifiers;
3245 int next_char;
3246 bool ok;
3248 c = READCHAR;
3249 if (c < 0)
3250 end_of_file_error ();
3252 /* Accept `single space' syntax like (list ? x) where the
3253 whitespace character is SPC or TAB.
3254 Other literal whitespace like NL, CR, and FF are not accepted,
3255 as there are well-established escape sequences for these. */
3256 if (c == ' ' || c == '\t')
3257 return make_number (c);
3259 if (c == '(' || c == ')' || c == '[' || c == ']'
3260 || c == '"' || c == ';')
3262 CHECK_LIST (Vlread_unescaped_character_literals);
3263 Lisp_Object char_obj = make_natnum (c);
3264 if (NILP (Fmemq (char_obj, Vlread_unescaped_character_literals)))
3265 Vlread_unescaped_character_literals =
3266 Fcons (char_obj, Vlread_unescaped_character_literals);
3269 if (c == '\\')
3270 c = read_escape (readcharfun, 0);
3271 modifiers = c & CHAR_MODIFIER_MASK;
3272 c &= ~CHAR_MODIFIER_MASK;
3273 if (CHAR_BYTE8_P (c))
3274 c = CHAR_TO_BYTE8 (c);
3275 c |= modifiers;
3277 next_char = READCHAR;
3278 ok = (next_char <= 040
3279 || (next_char < 0200
3280 && strchr ("\"';()[]#?`,.", next_char) != NULL));
3281 UNREAD (next_char);
3282 if (ok)
3283 return make_number (c);
3285 invalid_syntax ("?");
3288 case '"':
3290 ptrdiff_t count = SPECPDL_INDEX ();
3291 char *read_buffer = stackbuf;
3292 ptrdiff_t read_buffer_size = sizeof stackbuf;
3293 char *heapbuf = NULL;
3294 char *p = read_buffer;
3295 char *end = read_buffer + read_buffer_size;
3296 int ch;
3297 /* True if we saw an escape sequence specifying
3298 a multibyte character. */
3299 bool force_multibyte = false;
3300 /* True if we saw an escape sequence specifying
3301 a single-byte character. */
3302 bool force_singlebyte = false;
3303 bool cancel = false;
3304 ptrdiff_t nchars = 0;
3306 while ((ch = READCHAR) >= 0
3307 && ch != '\"')
3309 if (end - p < MAX_MULTIBYTE_LENGTH)
3311 ptrdiff_t offset = p - read_buffer;
3312 read_buffer = grow_read_buffer (read_buffer, offset,
3313 &heapbuf, &read_buffer_size,
3314 count);
3315 p = read_buffer + offset;
3316 end = read_buffer + read_buffer_size;
3319 if (ch == '\\')
3321 int modifiers;
3323 ch = read_escape (readcharfun, 1);
3325 /* CH is -1 if \ newline or \ space has just been seen. */
3326 if (ch == -1)
3328 if (p == read_buffer)
3329 cancel = true;
3330 continue;
3333 modifiers = ch & CHAR_MODIFIER_MASK;
3334 ch = ch & ~CHAR_MODIFIER_MASK;
3336 if (CHAR_BYTE8_P (ch))
3337 force_singlebyte = true;
3338 else if (! ASCII_CHAR_P (ch))
3339 force_multibyte = true;
3340 else /* I.e. ASCII_CHAR_P (ch). */
3342 /* Allow `\C- ' and `\C-?'. */
3343 if (modifiers == CHAR_CTL)
3345 if (ch == ' ')
3346 ch = 0, modifiers = 0;
3347 else if (ch == '?')
3348 ch = 127, modifiers = 0;
3350 if (modifiers & CHAR_SHIFT)
3352 /* Shift modifier is valid only with [A-Za-z]. */
3353 if (ch >= 'A' && ch <= 'Z')
3354 modifiers &= ~CHAR_SHIFT;
3355 else if (ch >= 'a' && ch <= 'z')
3356 ch -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
3359 if (modifiers & CHAR_META)
3361 /* Move the meta bit to the right place for a
3362 string. */
3363 modifiers &= ~CHAR_META;
3364 ch = BYTE8_TO_CHAR (ch | 0x80);
3365 force_singlebyte = true;
3369 /* Any modifiers remaining are invalid. */
3370 if (modifiers)
3371 error ("Invalid modifier in string");
3372 p += CHAR_STRING (ch, (unsigned char *) p);
3374 else
3376 p += CHAR_STRING (ch, (unsigned char *) p);
3377 if (CHAR_BYTE8_P (ch))
3378 force_singlebyte = true;
3379 else if (! ASCII_CHAR_P (ch))
3380 force_multibyte = true;
3382 nchars++;
3385 if (ch < 0)
3386 end_of_file_error ();
3388 /* If purifying, and string starts with \ newline,
3389 return zero instead. This is for doc strings
3390 that we are really going to find in etc/DOC.nn.nn. */
3391 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
3392 return unbind_to (count, make_number (0));
3394 if (! force_multibyte && force_singlebyte)
3396 /* READ_BUFFER contains raw 8-bit bytes and no multibyte
3397 forms. Convert it to unibyte. */
3398 nchars = str_as_unibyte ((unsigned char *) read_buffer,
3399 p - read_buffer);
3400 p = read_buffer + nchars;
3403 Lisp_Object result
3404 = make_specified_string (read_buffer, nchars, p - read_buffer,
3405 (force_multibyte
3406 || (p - read_buffer != nchars)));
3407 return unbind_to (count, result);
3410 case '.':
3412 int next_char = READCHAR;
3413 UNREAD (next_char);
3415 if (next_char <= 040
3416 || (next_char < 0200
3417 && strchr ("\"';([#?`,", next_char) != NULL))
3419 *pch = c;
3420 return Qnil;
3423 /* The atom-reading loop below will now loop at least once,
3424 assuring that we will not try to UNREAD two characters in a
3425 row. */
3426 FALLTHROUGH;
3427 default:
3428 default_label:
3429 if (c <= 040) goto retry;
3430 if (c == NO_BREAK_SPACE)
3431 goto retry;
3433 read_symbol:
3435 ptrdiff_t count = SPECPDL_INDEX ();
3436 char *read_buffer = stackbuf;
3437 ptrdiff_t read_buffer_size = sizeof stackbuf;
3438 char *heapbuf = NULL;
3439 char *p = read_buffer;
3440 char *end = read_buffer + read_buffer_size;
3441 bool quoted = false;
3442 EMACS_INT start_position = readchar_count - 1;
3446 if (end - p < MAX_MULTIBYTE_LENGTH + 1)
3448 ptrdiff_t offset = p - read_buffer;
3449 read_buffer = grow_read_buffer (read_buffer, offset,
3450 &heapbuf, &read_buffer_size,
3451 count);
3452 p = read_buffer + offset;
3453 end = read_buffer + read_buffer_size;
3456 if (c == '\\')
3458 c = READCHAR;
3459 if (c == -1)
3460 end_of_file_error ();
3461 quoted = true;
3464 if (multibyte)
3465 p += CHAR_STRING (c, (unsigned char *) p);
3466 else
3467 *p++ = c;
3468 c = READCHAR;
3470 while (c > 040
3471 && c != NO_BREAK_SPACE
3472 && (c >= 0200
3473 || strchr ("\"';()[]#`,", c) == NULL));
3475 *p = 0;
3476 UNREAD (c);
3478 if (!quoted && !uninterned_symbol)
3480 Lisp_Object result = string_to_number (read_buffer, 10, 0);
3481 if (! NILP (result))
3482 return unbind_to (count, result);
3485 Lisp_Object result;
3486 ptrdiff_t nbytes = p - read_buffer;
3487 ptrdiff_t nchars
3488 = (multibyte
3489 ? multibyte_chars_in_text ((unsigned char *) read_buffer,
3490 nbytes)
3491 : nbytes);
3493 if (uninterned_symbol)
3495 Lisp_Object name
3496 = ((! NILP (Vpurify_flag)
3497 ? make_pure_string : make_specified_string)
3498 (read_buffer, nchars, nbytes, multibyte));
3499 result = Fmake_symbol (name);
3501 else
3503 /* Don't create the string object for the name unless
3504 we're going to retain it in a new symbol.
3506 Like intern_1 but supports multibyte names. */
3507 Lisp_Object obarray = check_obarray (Vobarray);
3508 Lisp_Object tem = oblookup (obarray, read_buffer,
3509 nchars, nbytes);
3511 if (SYMBOLP (tem))
3512 result = tem;
3513 else
3515 Lisp_Object name
3516 = make_specified_string (read_buffer, nchars, nbytes,
3517 multibyte);
3518 result = intern_driver (name, obarray, tem);
3522 if (EQ (Vread_with_symbol_positions, Qt)
3523 || EQ (Vread_with_symbol_positions, readcharfun))
3524 Vread_symbol_positions_list
3525 = Fcons (Fcons (result, make_number (start_position)),
3526 Vread_symbol_positions_list);
3527 return unbind_to (count, result);
3533 DEFUN ("lread--substitute-object-in-subtree",
3534 Flread__substitute_object_in_subtree,
3535 Slread__substitute_object_in_subtree, 3, 3, 0,
3536 doc: /* In OBJECT, replace every occurrence of PLACEHOLDER with OBJECT.
3537 COMPLETED is a hash table of objects that might be circular, or is t
3538 if any object might be circular. */)
3539 (Lisp_Object object, Lisp_Object placeholder, Lisp_Object completed)
3541 struct subst subst = { object, placeholder, completed, Qnil };
3542 Lisp_Object check_object = substitute_object_recurse (&subst, object);
3544 /* The returned object here is expected to always eq the
3545 original. */
3546 if (!EQ (check_object, object))
3547 error ("Unexpected mutation error in reader");
3548 return Qnil;
3551 static Lisp_Object
3552 substitute_object_recurse (struct subst *subst, Lisp_Object subtree)
3554 /* If we find the placeholder, return the target object. */
3555 if (EQ (subst->placeholder, subtree))
3556 return subst->object;
3558 /* For common object types that can't contain other objects, don't
3559 bother looking them up; we're done. */
3560 if (SYMBOLP (subtree)
3561 || (STRINGP (subtree) && !string_intervals (subtree))
3562 || NUMBERP (subtree))
3563 return subtree;
3565 /* If we've been to this node before, don't explore it again. */
3566 if (!EQ (Qnil, Fmemq (subtree, subst->seen)))
3567 return subtree;
3569 /* If this node can be the entry point to a cycle, remember that
3570 we've seen it. It can only be such an entry point if it was made
3571 by #n=, which means that we can find it as a value in
3572 COMPLETED. */
3573 if (EQ (subst->completed, Qt)
3574 || hash_lookup (XHASH_TABLE (subst->completed), subtree, NULL) >= 0)
3575 subst->seen = Fcons (subtree, subst->seen);
3577 /* Recurse according to subtree's type.
3578 Every branch must return a Lisp_Object. */
3579 switch (XTYPE (subtree))
3581 case Lisp_Vectorlike:
3583 ptrdiff_t i = 0, length = 0;
3584 if (BOOL_VECTOR_P (subtree))
3585 return subtree; /* No sub-objects anyway. */
3586 else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
3587 || COMPILEDP (subtree) || HASH_TABLE_P (subtree)
3588 || RECORDP (subtree))
3589 length = PVSIZE (subtree);
3590 else if (VECTORP (subtree))
3591 length = ASIZE (subtree);
3592 else
3593 /* An unknown pseudovector may contain non-Lisp fields, so we
3594 can't just blindly traverse all its fields. We used to call
3595 `Flength' which signaled `sequencep', so I just preserved this
3596 behavior. */
3597 wrong_type_argument (Qsequencep, subtree);
3599 if (SUB_CHAR_TABLE_P (subtree))
3600 i = 2;
3601 for ( ; i < length; i++)
3602 ASET (subtree, i,
3603 substitute_object_recurse (subst, AREF (subtree, i)));
3604 return subtree;
3607 case Lisp_Cons:
3608 XSETCAR (subtree, substitute_object_recurse (subst, XCAR (subtree)));
3609 XSETCDR (subtree, substitute_object_recurse (subst, XCDR (subtree)));
3610 return subtree;
3612 case Lisp_String:
3614 /* Check for text properties in each interval.
3615 substitute_in_interval contains part of the logic. */
3617 INTERVAL root_interval = string_intervals (subtree);
3618 traverse_intervals_noorder (root_interval,
3619 substitute_in_interval, subst);
3620 return subtree;
3623 /* Other types don't recurse any further. */
3624 default:
3625 return subtree;
3629 /* Helper function for substitute_object_recurse. */
3630 static void
3631 substitute_in_interval (INTERVAL interval, void *arg)
3633 set_interval_plist (interval,
3634 substitute_object_recurse (arg, interval->plist));
3638 /* Convert STRING to a number, assuming base BASE. Return a fixnum if
3639 STRING has integer syntax and fits in a fixnum, else return the
3640 nearest float if STRING has either floating point or integer syntax
3641 and BASE is 10, else return nil. If IGNORE_TRAILING, consider just
3642 the longest prefix of STRING that has valid floating point syntax.
3643 Signal an overflow if BASE is not 10 and the number has integer
3644 syntax but does not fit. */
3646 Lisp_Object
3647 string_to_number (char const *string, int base, bool ignore_trailing)
3649 char const *cp = string;
3650 bool float_syntax = 0;
3651 double value = 0;
3653 /* Negate the value ourselves. This treats 0, NaNs, and infinity properly on
3654 IEEE floating point hosts, and works around a formerly-common bug where
3655 atof ("-0.0") drops the sign. */
3656 bool negative = *cp == '-';
3658 bool signedp = negative || *cp == '+';
3659 cp += signedp;
3661 enum { INTOVERFLOW = 1, LEAD_INT = 2, DOT_CHAR = 4, TRAIL_INT = 8,
3662 E_EXP = 16 };
3663 int state = 0;
3664 int leading_digit = digit_to_number (*cp, base);
3665 uintmax_t n = leading_digit;
3666 if (leading_digit >= 0)
3668 state |= LEAD_INT;
3669 for (int digit; 0 <= (digit = digit_to_number (*++cp, base)); )
3671 if (INT_MULTIPLY_OVERFLOW (n, base))
3672 state |= INTOVERFLOW;
3673 n *= base;
3674 if (INT_ADD_OVERFLOW (n, digit))
3675 state |= INTOVERFLOW;
3676 n += digit;
3679 if (*cp == '.')
3681 state |= DOT_CHAR;
3682 cp++;
3685 if (base == 10)
3687 if ('0' <= *cp && *cp <= '9')
3689 state |= TRAIL_INT;
3691 cp++;
3692 while ('0' <= *cp && *cp <= '9');
3694 if (*cp == 'e' || *cp == 'E')
3696 char const *ecp = cp;
3697 cp++;
3698 if (*cp == '+' || *cp == '-')
3699 cp++;
3700 if ('0' <= *cp && *cp <= '9')
3702 state |= E_EXP;
3704 cp++;
3705 while ('0' <= *cp && *cp <= '9');
3707 else if (cp[-1] == '+'
3708 && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
3710 state |= E_EXP;
3711 cp += 3;
3712 value = INFINITY;
3714 else if (cp[-1] == '+'
3715 && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
3717 state |= E_EXP;
3718 cp += 3;
3719 /* NAN is a "positive" NaN on all known Emacs hosts. */
3720 value = NAN;
3722 else
3723 cp = ecp;
3726 float_syntax = ((state & (DOT_CHAR|TRAIL_INT)) == (DOT_CHAR|TRAIL_INT)
3727 || (state & ~INTOVERFLOW) == (LEAD_INT|E_EXP));
3730 /* Return nil if the number uses invalid syntax. If IGNORE_TRAILING, accept
3731 any prefix that matches. Otherwise, the entire string must match. */
3732 if (! (ignore_trailing
3733 ? ((state & LEAD_INT) != 0 || float_syntax)
3734 : (!*cp && ((state & ~(INTOVERFLOW | DOT_CHAR)) == LEAD_INT
3735 || float_syntax))))
3736 return Qnil;
3738 /* If the number uses integer and not float syntax, and is in C-language
3739 range, use its value, preferably as a fixnum. */
3740 if (leading_digit >= 0 && ! float_syntax)
3742 if (state & INTOVERFLOW)
3744 /* Unfortunately there's no simple and accurate way to convert
3745 non-base-10 numbers that are out of C-language range. */
3746 if (base != 10)
3747 xsignal1 (Qoverflow_error, build_string (string));
3749 else if (n <= (negative ? -MOST_NEGATIVE_FIXNUM : MOST_POSITIVE_FIXNUM))
3751 EMACS_INT signed_n = n;
3752 return make_number (negative ? -signed_n : signed_n);
3754 else
3755 value = n;
3758 /* Either the number uses float syntax, or it does not fit into a fixnum.
3759 Convert it from string to floating point, unless the value is already
3760 known because it is an infinity, a NAN, or its absolute value fits in
3761 uintmax_t. */
3762 if (! value)
3763 value = atof (string + signedp);
3765 return make_float (negative ? -value : value);
3769 static Lisp_Object
3770 read_vector (Lisp_Object readcharfun, bool bytecodeflag)
3772 ptrdiff_t i, size;
3773 Lisp_Object *ptr;
3774 Lisp_Object tem, item, vector;
3775 struct Lisp_Cons *otem;
3776 Lisp_Object len;
3778 tem = read_list (1, readcharfun);
3779 len = Flength (tem);
3780 vector = Fmake_vector (len, Qnil);
3782 size = ASIZE (vector);
3783 ptr = XVECTOR (vector)->contents;
3784 for (i = 0; i < size; i++)
3786 item = Fcar (tem);
3787 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3788 bytecode object, the docstring containing the bytecode and
3789 constants values must be treated as unibyte and passed to
3790 Fread, to get the actual bytecode string and constants vector. */
3791 if (bytecodeflag && load_force_doc_strings)
3793 if (i == COMPILED_BYTECODE)
3795 if (!STRINGP (item))
3796 error ("Invalid byte code");
3798 /* Delay handling the bytecode slot until we know whether
3799 it is lazily-loaded (we can tell by whether the
3800 constants slot is nil). */
3801 ASET (vector, COMPILED_CONSTANTS, item);
3802 item = Qnil;
3804 else if (i == COMPILED_CONSTANTS)
3806 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
3808 if (NILP (item))
3810 /* Coerce string to unibyte (like string-as-unibyte,
3811 but without generating extra garbage and
3812 guaranteeing no change in the contents). */
3813 STRING_SET_CHARS (bytestr, SBYTES (bytestr));
3814 STRING_SET_UNIBYTE (bytestr);
3816 item = Fread (Fcons (bytestr, readcharfun));
3817 if (!CONSP (item))
3818 error ("Invalid byte code");
3820 otem = XCONS (item);
3821 bytestr = XCAR (item);
3822 item = XCDR (item);
3823 free_cons (otem);
3826 /* Now handle the bytecode slot. */
3827 ASET (vector, COMPILED_BYTECODE, bytestr);
3829 else if (i == COMPILED_DOC_STRING
3830 && STRINGP (item)
3831 && ! STRING_MULTIBYTE (item))
3833 if (EQ (readcharfun, Qget_emacs_mule_file_char))
3834 item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil);
3835 else
3836 item = Fstring_as_multibyte (item);
3839 ASET (vector, i, item);
3840 otem = XCONS (tem);
3841 tem = Fcdr (tem);
3842 free_cons (otem);
3844 return vector;
3847 /* FLAG means check for ']' to terminate rather than ')' and '.'. */
3849 static Lisp_Object
3850 read_list (bool flag, Lisp_Object readcharfun)
3852 Lisp_Object val, tail;
3853 Lisp_Object elt, tem;
3854 /* 0 is the normal case.
3855 1 means this list is a doc reference; replace it with the number 0.
3856 2 means this list is a doc reference; replace it with the doc string. */
3857 int doc_reference = 0;
3859 /* Initialize this to 1 if we are reading a list. */
3860 bool first_in_list = flag <= 0;
3862 val = Qnil;
3863 tail = Qnil;
3865 while (1)
3867 int ch;
3868 elt = read1 (readcharfun, &ch, first_in_list);
3870 first_in_list = 0;
3872 /* While building, if the list starts with #$, treat it specially. */
3873 if (EQ (elt, Vload_file_name)
3874 && ! NILP (elt)
3875 && !NILP (Vpurify_flag))
3877 if (NILP (Vdoc_file_name))
3878 /* We have not yet called Snarf-documentation, so assume
3879 this file is described in the DOC file
3880 and Snarf-documentation will fill in the right value later.
3881 For now, replace the whole list with 0. */
3882 doc_reference = 1;
3883 else
3884 /* We have already called Snarf-documentation, so make a relative
3885 file name for this file, so it can be found properly
3886 in the installed Lisp directory.
3887 We don't use Fexpand_file_name because that would make
3888 the directory absolute now. */
3890 AUTO_STRING (dot_dot_lisp, "../lisp/");
3891 elt = concat2 (dot_dot_lisp, Ffile_name_nondirectory (elt));
3894 else if (EQ (elt, Vload_file_name)
3895 && ! NILP (elt)
3896 && load_force_doc_strings)
3897 doc_reference = 2;
3899 if (ch)
3901 if (flag > 0)
3903 if (ch == ']')
3904 return val;
3905 invalid_syntax (") or . in a vector");
3907 if (ch == ')')
3908 return val;
3909 if (ch == '.')
3911 if (!NILP (tail))
3912 XSETCDR (tail, read0 (readcharfun));
3913 else
3914 val = read0 (readcharfun);
3915 read1 (readcharfun, &ch, 0);
3917 if (ch == ')')
3919 if (doc_reference == 1)
3920 return make_number (0);
3921 if (doc_reference == 2 && INTEGERP (XCDR (val)))
3923 char *saved = NULL;
3924 file_offset saved_position;
3925 /* Get a doc string from the file we are loading.
3926 If it's in saved_doc_string, get it from there.
3928 Here, we don't know if the string is a
3929 bytecode string or a doc string. As a
3930 bytecode string must be unibyte, we always
3931 return a unibyte string. If it is actually a
3932 doc string, caller must make it
3933 multibyte. */
3935 /* Position is negative for user variables. */
3936 EMACS_INT pos = eabs (XINT (XCDR (val)));
3937 if (pos >= saved_doc_string_position
3938 && pos < (saved_doc_string_position
3939 + saved_doc_string_length))
3941 saved = saved_doc_string;
3942 saved_position = saved_doc_string_position;
3944 /* Look in prev_saved_doc_string the same way. */
3945 else if (pos >= prev_saved_doc_string_position
3946 && pos < (prev_saved_doc_string_position
3947 + prev_saved_doc_string_length))
3949 saved = prev_saved_doc_string;
3950 saved_position = prev_saved_doc_string_position;
3952 if (saved)
3954 ptrdiff_t start = pos - saved_position;
3955 ptrdiff_t from, to;
3957 /* Process quoting with ^A,
3958 and find the end of the string,
3959 which is marked with ^_ (037). */
3960 for (from = start, to = start;
3961 saved[from] != 037;)
3963 int c = saved[from++];
3964 if (c == 1)
3966 c = saved[from++];
3967 saved[to++] = (c == 1 ? c
3968 : c == '0' ? 0
3969 : c == '_' ? 037
3970 : c);
3972 else
3973 saved[to++] = c;
3976 return make_unibyte_string (saved + start,
3977 to - start);
3979 else
3980 return get_doc_string (val, 1, 0);
3983 return val;
3985 invalid_syntax (". in wrong context");
3987 invalid_syntax ("] in a list");
3989 tem = list1 (elt);
3990 if (!NILP (tail))
3991 XSETCDR (tail, tem);
3992 else
3993 val = tem;
3994 tail = tem;
3998 static Lisp_Object initial_obarray;
4000 /* `oblookup' stores the bucket number here, for the sake of Funintern. */
4002 static size_t oblookup_last_bucket_number;
4004 /* Get an error if OBARRAY is not an obarray.
4005 If it is one, return it. */
4007 Lisp_Object
4008 check_obarray (Lisp_Object obarray)
4010 /* We don't want to signal a wrong-type-argument error when we are
4011 shutting down due to a fatal error, and we don't want to hit
4012 assertions in VECTORP and ASIZE if the fatal error was during GC. */
4013 if (!fatal_error_in_progress
4014 && (!VECTORP (obarray) || ASIZE (obarray) == 0))
4016 /* If Vobarray is now invalid, force it to be valid. */
4017 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
4018 wrong_type_argument (Qvectorp, obarray);
4020 return obarray;
4023 /* Intern symbol SYM in OBARRAY using bucket INDEX. */
4025 static Lisp_Object
4026 intern_sym (Lisp_Object sym, Lisp_Object obarray, Lisp_Object index)
4028 Lisp_Object *ptr;
4030 XSYMBOL (sym)->u.s.interned = (EQ (obarray, initial_obarray)
4031 ? SYMBOL_INTERNED_IN_INITIAL_OBARRAY
4032 : SYMBOL_INTERNED);
4034 if (SREF (SYMBOL_NAME (sym), 0) == ':' && EQ (obarray, initial_obarray))
4036 make_symbol_constant (sym);
4037 XSYMBOL (sym)->u.s.redirect = SYMBOL_PLAINVAL;
4038 SET_SYMBOL_VAL (XSYMBOL (sym), sym);
4041 ptr = aref_addr (obarray, XINT (index));
4042 set_symbol_next (sym, SYMBOLP (*ptr) ? XSYMBOL (*ptr) : NULL);
4043 *ptr = sym;
4044 return sym;
4047 /* Intern a symbol with name STRING in OBARRAY using bucket INDEX. */
4049 Lisp_Object
4050 intern_driver (Lisp_Object string, Lisp_Object obarray, Lisp_Object index)
4052 return intern_sym (Fmake_symbol (string), obarray, index);
4055 /* Intern the C string STR: return a symbol with that name,
4056 interned in the current obarray. */
4058 Lisp_Object
4059 intern_1 (const char *str, ptrdiff_t len)
4061 Lisp_Object obarray = check_obarray (Vobarray);
4062 Lisp_Object tem = oblookup (obarray, str, len, len);
4064 return (SYMBOLP (tem) ? tem
4065 /* The above `oblookup' was done on the basis of nchars==nbytes, so
4066 the string has to be unibyte. */
4067 : intern_driver (make_unibyte_string (str, len),
4068 obarray, tem));
4071 Lisp_Object
4072 intern_c_string_1 (const char *str, ptrdiff_t len)
4074 Lisp_Object obarray = check_obarray (Vobarray);
4075 Lisp_Object tem = oblookup (obarray, str, len, len);
4077 if (!SYMBOLP (tem))
4079 /* Creating a non-pure string from a string literal not implemented yet.
4080 We could just use make_string here and live with the extra copy. */
4081 eassert (!NILP (Vpurify_flag));
4082 tem = intern_driver (make_pure_c_string (str, len), obarray, tem);
4084 return tem;
4087 static void
4088 define_symbol (Lisp_Object sym, char const *str)
4090 ptrdiff_t len = strlen (str);
4091 Lisp_Object string = make_pure_c_string (str, len);
4092 init_symbol (sym, string);
4094 /* Qunbound is uninterned, so that it's not confused with any symbol
4095 'unbound' created by a Lisp program. */
4096 if (! EQ (sym, Qunbound))
4098 Lisp_Object bucket = oblookup (initial_obarray, str, len, len);
4099 eassert (INTEGERP (bucket));
4100 intern_sym (sym, initial_obarray, bucket);
4104 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
4105 doc: /* Return the canonical symbol whose name is STRING.
4106 If there is none, one is created by this function and returned.
4107 A second optional argument specifies the obarray to use;
4108 it defaults to the value of `obarray'. */)
4109 (Lisp_Object string, Lisp_Object obarray)
4111 Lisp_Object tem;
4113 obarray = check_obarray (NILP (obarray) ? Vobarray : obarray);
4114 CHECK_STRING (string);
4116 tem = oblookup (obarray, SSDATA (string), SCHARS (string), SBYTES (string));
4117 if (!SYMBOLP (tem))
4118 tem = intern_driver (NILP (Vpurify_flag) ? string : Fpurecopy (string),
4119 obarray, tem);
4120 return tem;
4123 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
4124 doc: /* Return the canonical symbol named NAME, or nil if none exists.
4125 NAME may be a string or a symbol. If it is a symbol, that exact
4126 symbol is searched for.
4127 A second optional argument specifies the obarray to use;
4128 it defaults to the value of `obarray'. */)
4129 (Lisp_Object name, Lisp_Object obarray)
4131 register Lisp_Object tem, string;
4133 if (NILP (obarray)) obarray = Vobarray;
4134 obarray = check_obarray (obarray);
4136 if (!SYMBOLP (name))
4138 CHECK_STRING (name);
4139 string = name;
4141 else
4142 string = SYMBOL_NAME (name);
4144 tem = oblookup (obarray, SSDATA (string), SCHARS (string), SBYTES (string));
4145 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
4146 return Qnil;
4147 else
4148 return tem;
4151 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
4152 doc: /* Delete the symbol named NAME, if any, from OBARRAY.
4153 The value is t if a symbol was found and deleted, nil otherwise.
4154 NAME may be a string or a symbol. If it is a symbol, that symbol
4155 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
4156 OBARRAY, if nil, defaults to the value of the variable `obarray'.
4157 usage: (unintern NAME OBARRAY) */)
4158 (Lisp_Object name, Lisp_Object obarray)
4160 register Lisp_Object string, tem;
4161 size_t hash;
4163 if (NILP (obarray)) obarray = Vobarray;
4164 obarray = check_obarray (obarray);
4166 if (SYMBOLP (name))
4167 string = SYMBOL_NAME (name);
4168 else
4170 CHECK_STRING (name);
4171 string = name;
4174 tem = oblookup (obarray, SSDATA (string),
4175 SCHARS (string),
4176 SBYTES (string));
4177 if (INTEGERP (tem))
4178 return Qnil;
4179 /* If arg was a symbol, don't delete anything but that symbol itself. */
4180 if (SYMBOLP (name) && !EQ (name, tem))
4181 return Qnil;
4183 /* There are plenty of other symbols which will screw up the Emacs
4184 session if we unintern them, as well as even more ways to use
4185 `setq' or `fset' or whatnot to make the Emacs session
4186 unusable. Let's not go down this silly road. --Stef */
4187 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
4188 error ("Attempt to unintern t or nil"); */
4190 XSYMBOL (tem)->u.s.interned = SYMBOL_UNINTERNED;
4192 hash = oblookup_last_bucket_number;
4194 if (EQ (AREF (obarray, hash), tem))
4196 if (XSYMBOL (tem)->u.s.next)
4198 Lisp_Object sym;
4199 XSETSYMBOL (sym, XSYMBOL (tem)->u.s.next);
4200 ASET (obarray, hash, sym);
4202 else
4203 ASET (obarray, hash, make_number (0));
4205 else
4207 Lisp_Object tail, following;
4209 for (tail = AREF (obarray, hash);
4210 XSYMBOL (tail)->u.s.next;
4211 tail = following)
4213 XSETSYMBOL (following, XSYMBOL (tail)->u.s.next);
4214 if (EQ (following, tem))
4216 set_symbol_next (tail, XSYMBOL (following)->u.s.next);
4217 break;
4222 return Qt;
4225 /* Return the symbol in OBARRAY whose names matches the string
4226 of SIZE characters (SIZE_BYTE bytes) at PTR.
4227 If there is no such symbol, return the integer bucket number of
4228 where the symbol would be if it were present.
4230 Also store the bucket number in oblookup_last_bucket_number. */
4232 Lisp_Object
4233 oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff_t size_byte)
4235 size_t hash;
4236 size_t obsize;
4237 register Lisp_Object tail;
4238 Lisp_Object bucket, tem;
4240 obarray = check_obarray (obarray);
4241 /* This is sometimes needed in the middle of GC. */
4242 obsize = gc_asize (obarray);
4243 hash = hash_string (ptr, size_byte) % obsize;
4244 bucket = AREF (obarray, hash);
4245 oblookup_last_bucket_number = hash;
4246 if (EQ (bucket, make_number (0)))
4248 else if (!SYMBOLP (bucket))
4249 error ("Bad data in guts of obarray"); /* Like CADR error message. */
4250 else
4251 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->u.s.next))
4253 if (SBYTES (SYMBOL_NAME (tail)) == size_byte
4254 && SCHARS (SYMBOL_NAME (tail)) == size
4255 && !memcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
4256 return tail;
4257 else if (XSYMBOL (tail)->u.s.next == 0)
4258 break;
4260 XSETINT (tem, hash);
4261 return tem;
4264 void
4265 map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg)
4267 ptrdiff_t i;
4268 register Lisp_Object tail;
4269 CHECK_VECTOR (obarray);
4270 for (i = ASIZE (obarray) - 1; i >= 0; i--)
4272 tail = AREF (obarray, i);
4273 if (SYMBOLP (tail))
4274 while (1)
4276 (*fn) (tail, arg);
4277 if (XSYMBOL (tail)->u.s.next == 0)
4278 break;
4279 XSETSYMBOL (tail, XSYMBOL (tail)->u.s.next);
4284 static void
4285 mapatoms_1 (Lisp_Object sym, Lisp_Object function)
4287 call1 (function, sym);
4290 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
4291 doc: /* Call FUNCTION on every symbol in OBARRAY.
4292 OBARRAY defaults to the value of `obarray'. */)
4293 (Lisp_Object function, Lisp_Object obarray)
4295 if (NILP (obarray)) obarray = Vobarray;
4296 obarray = check_obarray (obarray);
4298 map_obarray (obarray, mapatoms_1, function);
4299 return Qnil;
4302 #define OBARRAY_SIZE 15121
4304 void
4305 init_obarray (void)
4307 Vobarray = Fmake_vector (make_number (OBARRAY_SIZE), make_number (0));
4308 initial_obarray = Vobarray;
4309 staticpro (&initial_obarray);
4311 for (int i = 0; i < ARRAYELTS (lispsym); i++)
4312 define_symbol (builtin_lisp_symbol (i), defsym_name[i]);
4314 DEFSYM (Qunbound, "unbound");
4316 DEFSYM (Qnil, "nil");
4317 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil);
4318 make_symbol_constant (Qnil);
4319 XSYMBOL (Qnil)->u.s.declared_special = true;
4321 DEFSYM (Qt, "t");
4322 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt);
4323 make_symbol_constant (Qt);
4324 XSYMBOL (Qt)->u.s.declared_special = true;
4326 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
4327 Vpurify_flag = Qt;
4329 DEFSYM (Qvariable_documentation, "variable-documentation");
4332 void
4333 defsubr (struct Lisp_Subr *sname)
4335 Lisp_Object sym, tem;
4336 sym = intern_c_string (sname->symbol_name);
4337 XSETPVECTYPE (sname, PVEC_SUBR);
4338 XSETSUBR (tem, sname);
4339 set_symbol_function (sym, tem);
4342 #ifdef NOTDEF /* Use fset in subr.el now! */
4343 void
4344 defalias (struct Lisp_Subr *sname, char *string)
4346 Lisp_Object sym;
4347 sym = intern (string);
4348 XSETSUBR (XSYMBOL (sym)->u.s.function, sname);
4350 #endif /* NOTDEF */
4352 /* Define an "integer variable"; a symbol whose value is forwarded to a
4353 C variable of type EMACS_INT. Sample call (with "xx" to fool make-docfile):
4354 DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
4355 void
4356 defvar_int (struct Lisp_Intfwd *i_fwd,
4357 const char *namestring, EMACS_INT *address)
4359 Lisp_Object sym;
4360 sym = intern_c_string (namestring);
4361 i_fwd->type = Lisp_Fwd_Int;
4362 i_fwd->intvar = address;
4363 XSYMBOL (sym)->u.s.declared_special = true;
4364 XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED;
4365 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)i_fwd);
4368 /* Similar but define a variable whose value is t if address contains 1,
4369 nil if address contains 0. */
4370 void
4371 defvar_bool (struct Lisp_Boolfwd *b_fwd,
4372 const char *namestring, bool *address)
4374 Lisp_Object sym;
4375 sym = intern_c_string (namestring);
4376 b_fwd->type = Lisp_Fwd_Bool;
4377 b_fwd->boolvar = address;
4378 XSYMBOL (sym)->u.s.declared_special = true;
4379 XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED;
4380 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)b_fwd);
4381 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
4384 /* Similar but define a variable whose value is the Lisp Object stored
4385 at address. Two versions: with and without gc-marking of the C
4386 variable. The nopro version is used when that variable will be
4387 gc-marked for some other reason, since marking the same slot twice
4388 can cause trouble with strings. */
4389 void
4390 defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd,
4391 const char *namestring, Lisp_Object *address)
4393 Lisp_Object sym;
4394 sym = intern_c_string (namestring);
4395 o_fwd->type = Lisp_Fwd_Obj;
4396 o_fwd->objvar = address;
4397 XSYMBOL (sym)->u.s.declared_special = true;
4398 XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED;
4399 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)o_fwd);
4402 void
4403 defvar_lisp (struct Lisp_Objfwd *o_fwd,
4404 const char *namestring, Lisp_Object *address)
4406 defvar_lisp_nopro (o_fwd, namestring, address);
4407 staticpro (address);
4410 /* Similar but define a variable whose value is the Lisp Object stored
4411 at a particular offset in the current kboard object. */
4413 void
4414 defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd,
4415 const char *namestring, int offset)
4417 Lisp_Object sym;
4418 sym = intern_c_string (namestring);
4419 ko_fwd->type = Lisp_Fwd_Kboard_Obj;
4420 ko_fwd->offset = offset;
4421 XSYMBOL (sym)->u.s.declared_special = true;
4422 XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED;
4423 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd);
4426 /* Check that the elements of lpath exist. */
4428 static void
4429 load_path_check (Lisp_Object lpath)
4431 Lisp_Object path_tail;
4433 /* The only elements that might not exist are those from
4434 PATH_LOADSEARCH, EMACSLOADPATH. Anything else is only added if
4435 it exists. */
4436 for (path_tail = lpath; !NILP (path_tail); path_tail = XCDR (path_tail))
4438 Lisp_Object dirfile;
4439 dirfile = Fcar (path_tail);
4440 if (STRINGP (dirfile))
4442 dirfile = Fdirectory_file_name (dirfile);
4443 if (! file_accessible_directory_p (dirfile))
4444 dir_warning ("Lisp directory", XCAR (path_tail));
4449 /* Return the default load-path, to be used if EMACSLOADPATH is unset.
4450 This does not include the standard site-lisp directories
4451 under the installation prefix (i.e., PATH_SITELOADSEARCH),
4452 but it does (unless no_site_lisp is set) include site-lisp
4453 directories in the source/build directories if those exist and we
4454 are running uninstalled.
4456 Uses the following logic:
4457 If CANNOT_DUMP:
4458 If Vinstallation_directory is not nil (ie, running uninstalled),
4459 use PATH_DUMPLOADSEARCH (ie, build path). Else use PATH_LOADSEARCH.
4460 The remainder is what happens when dumping works:
4461 If purify-flag (ie dumping) just use PATH_DUMPLOADSEARCH.
4462 Otherwise use PATH_LOADSEARCH.
4464 If !initialized, then just return PATH_DUMPLOADSEARCH.
4465 If initialized:
4466 If Vinstallation_directory is not nil (ie, running uninstalled):
4467 If installation-dir/lisp exists and not already a member,
4468 we must be running uninstalled. Reset the load-path
4469 to just installation-dir/lisp. (The default PATH_LOADSEARCH
4470 refers to the eventual installation directories. Since we
4471 are not yet installed, we should not use them, even if they exist.)
4472 If installation-dir/lisp does not exist, just add
4473 PATH_DUMPLOADSEARCH at the end instead.
4474 Add installation-dir/site-lisp (if !no_site_lisp, and exists
4475 and not already a member) at the front.
4476 If installation-dir != source-dir (ie running an uninstalled,
4477 out-of-tree build) AND install-dir/src/Makefile exists BUT
4478 install-dir/src/Makefile.in does NOT exist (this is a sanity
4479 check), then repeat the above steps for source-dir/lisp, site-lisp. */
4481 static Lisp_Object
4482 load_path_default (void)
4484 Lisp_Object lpath = Qnil;
4485 const char *normal;
4487 #ifdef CANNOT_DUMP
4488 #ifdef HAVE_NS
4489 const char *loadpath = ns_load_path ();
4490 #endif
4492 normal = PATH_LOADSEARCH;
4493 if (!NILP (Vinstallation_directory)) normal = PATH_DUMPLOADSEARCH;
4495 #ifdef HAVE_NS
4496 lpath = decode_env_path (0, loadpath ? loadpath : normal, 0);
4497 #else
4498 lpath = decode_env_path (0, normal, 0);
4499 #endif
4501 #else /* !CANNOT_DUMP */
4503 normal = NILP (Vpurify_flag) ? PATH_LOADSEARCH : PATH_DUMPLOADSEARCH;
4505 if (initialized)
4507 #ifdef HAVE_NS
4508 const char *loadpath = ns_load_path ();
4509 lpath = decode_env_path (0, loadpath ? loadpath : normal, 0);
4510 #else
4511 lpath = decode_env_path (0, normal, 0);
4512 #endif
4513 if (!NILP (Vinstallation_directory))
4515 Lisp_Object tem, tem1;
4517 /* Add to the path the lisp subdir of the installation
4518 dir, if it is accessible. Note: in out-of-tree builds,
4519 this directory is empty save for Makefile. */
4520 tem = Fexpand_file_name (build_string ("lisp"),
4521 Vinstallation_directory);
4522 tem1 = Ffile_accessible_directory_p (tem);
4523 if (!NILP (tem1))
4525 if (NILP (Fmember (tem, lpath)))
4527 /* We are running uninstalled. The default load-path
4528 points to the eventual installed lisp directories.
4529 We should not use those now, even if they exist,
4530 so start over from a clean slate. */
4531 lpath = list1 (tem);
4534 else
4535 /* That dir doesn't exist, so add the build-time
4536 Lisp dirs instead. */
4538 Lisp_Object dump_path =
4539 decode_env_path (0, PATH_DUMPLOADSEARCH, 0);
4540 lpath = nconc2 (lpath, dump_path);
4543 /* Add site-lisp under the installation dir, if it exists. */
4544 if (!no_site_lisp)
4546 tem = Fexpand_file_name (build_string ("site-lisp"),
4547 Vinstallation_directory);
4548 tem1 = Ffile_accessible_directory_p (tem);
4549 if (!NILP (tem1))
4551 if (NILP (Fmember (tem, lpath)))
4552 lpath = Fcons (tem, lpath);
4556 /* If Emacs was not built in the source directory,
4557 and it is run from where it was built, add to load-path
4558 the lisp and site-lisp dirs under that directory. */
4560 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
4562 Lisp_Object tem2;
4564 tem = Fexpand_file_name (build_string ("src/Makefile"),
4565 Vinstallation_directory);
4566 tem1 = Ffile_exists_p (tem);
4568 /* Don't be fooled if they moved the entire source tree
4569 AFTER dumping Emacs. If the build directory is indeed
4570 different from the source dir, src/Makefile.in and
4571 src/Makefile will not be found together. */
4572 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
4573 Vinstallation_directory);
4574 tem2 = Ffile_exists_p (tem);
4575 if (!NILP (tem1) && NILP (tem2))
4577 tem = Fexpand_file_name (build_string ("lisp"),
4578 Vsource_directory);
4580 if (NILP (Fmember (tem, lpath)))
4581 lpath = Fcons (tem, lpath);
4583 if (!no_site_lisp)
4585 tem = Fexpand_file_name (build_string ("site-lisp"),
4586 Vsource_directory);
4587 tem1 = Ffile_accessible_directory_p (tem);
4588 if (!NILP (tem1))
4590 if (NILP (Fmember (tem, lpath)))
4591 lpath = Fcons (tem, lpath);
4595 } /* Vinstallation_directory != Vsource_directory */
4597 } /* if Vinstallation_directory */
4599 else /* !initialized */
4601 /* NORMAL refers to PATH_DUMPLOADSEARCH, ie the lisp dir in the
4602 source directory. We used to add ../lisp (ie the lisp dir in
4603 the build directory) at the front here, but that should not
4604 be necessary, since in out of tree builds lisp/ is empty, save
4605 for Makefile. */
4606 lpath = decode_env_path (0, normal, 0);
4608 #endif /* !CANNOT_DUMP */
4610 return lpath;
4613 void
4614 init_lread (void)
4616 if (NILP (Vpurify_flag) && !NILP (Ffboundp (Qfile_truename)))
4617 Vsource_directory = call1 (Qfile_truename, Vsource_directory);
4619 /* First, set Vload_path. */
4621 /* Ignore EMACSLOADPATH when dumping. */
4622 #ifdef CANNOT_DUMP
4623 bool use_loadpath = true;
4624 #else
4625 bool use_loadpath = NILP (Vpurify_flag);
4626 #endif
4628 if (use_loadpath && egetenv ("EMACSLOADPATH"))
4630 Vload_path = decode_env_path ("EMACSLOADPATH", 0, 1);
4632 /* Check (non-nil) user-supplied elements. */
4633 load_path_check (Vload_path);
4635 /* If no nils in the environment variable, use as-is.
4636 Otherwise, replace any nils with the default. */
4637 if (! NILP (Fmemq (Qnil, Vload_path)))
4639 Lisp_Object elem, elpath = Vload_path;
4640 Lisp_Object default_lpath = load_path_default ();
4642 /* Check defaults, before adding site-lisp. */
4643 load_path_check (default_lpath);
4645 /* Add the site-lisp directories to the front of the default. */
4646 if (!no_site_lisp && PATH_SITELOADSEARCH[0] != '\0')
4648 Lisp_Object sitelisp;
4649 sitelisp = decode_env_path (0, PATH_SITELOADSEARCH, 0);
4650 if (! NILP (sitelisp))
4651 default_lpath = nconc2 (sitelisp, default_lpath);
4654 Vload_path = Qnil;
4656 /* Replace nils from EMACSLOADPATH by default. */
4657 while (CONSP (elpath))
4659 elem = XCAR (elpath);
4660 elpath = XCDR (elpath);
4661 Vload_path = CALLN (Fappend, Vload_path,
4662 NILP (elem) ? default_lpath : list1 (elem));
4664 } /* Fmemq (Qnil, Vload_path) */
4666 else
4668 Vload_path = load_path_default ();
4670 /* Check before adding site-lisp directories.
4671 The install should have created them, but they are not
4672 required, so no need to warn if they are absent.
4673 Or we might be running before installation. */
4674 load_path_check (Vload_path);
4676 /* Add the site-lisp directories at the front. */
4677 if (initialized && !no_site_lisp && PATH_SITELOADSEARCH[0] != '\0')
4679 Lisp_Object sitelisp;
4680 sitelisp = decode_env_path (0, PATH_SITELOADSEARCH, 0);
4681 if (! NILP (sitelisp)) Vload_path = nconc2 (sitelisp, Vload_path);
4685 Vvalues = Qnil;
4687 load_in_progress = 0;
4688 Vload_file_name = Qnil;
4689 Vstandard_input = Qt;
4690 Vloads_in_progress = Qnil;
4693 /* Print a warning that directory intended for use USE and with name
4694 DIRNAME cannot be accessed. On entry, errno should correspond to
4695 the access failure. Print the warning on stderr and put it in
4696 *Messages*. */
4698 void
4699 dir_warning (char const *use, Lisp_Object dirname)
4701 static char const format[] = "Warning: %s '%s': %s\n";
4702 char *diagnostic = emacs_strerror (errno);
4703 fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)), diagnostic);
4705 /* Don't log the warning before we've initialized!! */
4706 if (initialized)
4708 ptrdiff_t diaglen = strlen (diagnostic);
4709 AUTO_STRING_WITH_LEN (diag, diagnostic, diaglen);
4710 if (! NILP (Vlocale_coding_system))
4712 Lisp_Object s
4713 = code_convert_string_norecord (diag, Vlocale_coding_system, false);
4714 diagnostic = SSDATA (s);
4715 diaglen = SBYTES (s);
4717 USE_SAFE_ALLOCA;
4718 char *buffer = SAFE_ALLOCA (sizeof format - 3 * (sizeof "%s" - 1)
4719 + strlen (use) + SBYTES (dirname) + diaglen);
4720 ptrdiff_t message_len = esprintf (buffer, format, use, SSDATA (dirname),
4721 diagnostic);
4722 message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname));
4723 SAFE_FREE ();
4727 void
4728 syms_of_lread (void)
4730 defsubr (&Sread);
4731 defsubr (&Sread_from_string);
4732 defsubr (&Slread__substitute_object_in_subtree);
4733 defsubr (&Sintern);
4734 defsubr (&Sintern_soft);
4735 defsubr (&Sunintern);
4736 defsubr (&Sget_load_suffixes);
4737 defsubr (&Sload);
4738 defsubr (&Seval_buffer);
4739 defsubr (&Seval_region);
4740 defsubr (&Sread_char);
4741 defsubr (&Sread_char_exclusive);
4742 defsubr (&Sread_event);
4743 defsubr (&Sget_file_char);
4744 defsubr (&Smapatoms);
4745 defsubr (&Slocate_file_internal);
4747 DEFVAR_LISP ("obarray", Vobarray,
4748 doc: /* Symbol table for use by `intern' and `read'.
4749 It is a vector whose length ought to be prime for best results.
4750 The vector's contents don't make sense if examined from Lisp programs;
4751 to find all the symbols in an obarray, use `mapatoms'. */);
4753 DEFVAR_LISP ("values", Vvalues,
4754 doc: /* List of values of all expressions which were read, evaluated and printed.
4755 Order is reverse chronological. */);
4756 XSYMBOL (intern ("values"))->u.s.declared_special = false;
4758 DEFVAR_LISP ("standard-input", Vstandard_input,
4759 doc: /* Stream for read to get input from.
4760 See documentation of `read' for possible values. */);
4761 Vstandard_input = Qt;
4763 DEFVAR_LISP ("read-with-symbol-positions", Vread_with_symbol_positions,
4764 doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4766 If this variable is a buffer, then only forms read from that buffer
4767 will be added to `read-symbol-positions-list'.
4768 If this variable is t, then all read forms will be added.
4769 The effect of all other values other than nil are not currently
4770 defined, although they may be in the future.
4772 The positions are relative to the last call to `read' or
4773 `read-from-string'. It is probably a bad idea to set this variable at
4774 the toplevel; bind it instead. */);
4775 Vread_with_symbol_positions = Qnil;
4777 DEFVAR_LISP ("read-symbol-positions-list", Vread_symbol_positions_list,
4778 doc: /* A list mapping read symbols to their positions.
4779 This variable is modified during calls to `read' or
4780 `read-from-string', but only when `read-with-symbol-positions' is
4781 non-nil.
4783 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4784 CHAR-POSITION is an integer giving the offset of that occurrence of the
4785 symbol from the position where `read' or `read-from-string' started.
4787 Note that a symbol will appear multiple times in this list, if it was
4788 read multiple times. The list is in the same order as the symbols
4789 were read in. */);
4790 Vread_symbol_positions_list = Qnil;
4792 DEFVAR_LISP ("read-circle", Vread_circle,
4793 doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4794 Vread_circle = Qt;
4796 DEFVAR_LISP ("load-path", Vload_path,
4797 doc: /* List of directories to search for files to load.
4798 Each element is a string (directory file name) or nil (meaning
4799 `default-directory').
4800 This list is consulted by the `require' function.
4801 Initialized during startup as described in Info node `(elisp)Library Search'.
4802 Use `directory-file-name' when adding items to this path. However, Lisp
4803 programs that process this list should tolerate directories both with
4804 and without trailing slashes. */);
4806 DEFVAR_LISP ("load-suffixes", Vload_suffixes,
4807 doc: /* List of suffixes for Emacs Lisp files and dynamic modules.
4808 This list includes suffixes for both compiled and source Emacs Lisp files.
4809 This list should not include the empty string.
4810 `load' and related functions try to append these suffixes, in order,
4811 to the specified file name if a suffix is allowed or required. */);
4812 #ifdef HAVE_MODULES
4813 Vload_suffixes = list3 (build_pure_c_string (".elc"),
4814 build_pure_c_string (".el"),
4815 build_pure_c_string (MODULES_SUFFIX));
4816 #else
4817 Vload_suffixes = list2 (build_pure_c_string (".elc"),
4818 build_pure_c_string (".el"));
4819 #endif
4820 DEFVAR_LISP ("module-file-suffix", Vmodule_file_suffix,
4821 doc: /* Suffix of loadable module file, or nil if modules are not supported. */);
4822 #ifdef HAVE_MODULES
4823 Vmodule_file_suffix = build_pure_c_string (MODULES_SUFFIX);
4824 #else
4825 Vmodule_file_suffix = Qnil;
4826 #endif
4827 DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes,
4828 doc: /* List of suffixes that indicate representations of \
4829 the same file.
4830 This list should normally start with the empty string.
4832 Enabling Auto Compression mode appends the suffixes in
4833 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4834 mode removes them again. `load' and related functions use this list to
4835 determine whether they should look for compressed versions of a file
4836 and, if so, which suffixes they should try to append to the file name
4837 in order to do so. However, if you want to customize which suffixes
4838 the loading functions recognize as compression suffixes, you should
4839 customize `jka-compr-load-suffixes' rather than the present variable. */);
4840 Vload_file_rep_suffixes = list1 (empty_unibyte_string);
4842 DEFVAR_BOOL ("load-in-progress", load_in_progress,
4843 doc: /* Non-nil if inside of `load'. */);
4844 DEFSYM (Qload_in_progress, "load-in-progress");
4846 DEFVAR_LISP ("after-load-alist", Vafter_load_alist,
4847 doc: /* An alist of functions to be evalled when particular files are loaded.
4848 Each element looks like (REGEXP-OR-FEATURE FUNCS...).
4850 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4851 a symbol (a feature name).
4853 When `load' is run and the file-name argument matches an element's
4854 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4855 REGEXP-OR-FEATURE, the FUNCS in the element are called.
4857 An error in FORMS does not undo the load, but does prevent execution of
4858 the rest of the FORMS. */);
4859 Vafter_load_alist = Qnil;
4861 DEFVAR_LISP ("load-history", Vload_history,
4862 doc: /* Alist mapping loaded file names to symbols and features.
4863 Each alist element should be a list (FILE-NAME ENTRIES...), where
4864 FILE-NAME is the name of a file that has been loaded into Emacs.
4865 The file name is absolute and true (i.e. it doesn't contain symlinks).
4866 As an exception, one of the alist elements may have FILE-NAME nil,
4867 for symbols and features not associated with any file.
4869 The remaining ENTRIES in the alist element describe the functions and
4870 variables defined in that file, the features provided, and the
4871 features required. Each entry has the form `(provide . FEATURE)',
4872 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4873 `(defface . SYMBOL)', `(define-type . SYMBOL)',
4874 `(cl-defmethod METHOD SPECIALIZERS)', or `(t . SYMBOL)'.
4875 Entries like `(t . SYMBOL)' may precede a `(defun . FUNCTION)' entry,
4876 and means that SYMBOL was an autoload before this file redefined it
4877 as a function. In addition, entries may also be single symbols,
4878 which means that symbol was defined by `defvar' or `defconst'.
4880 During preloading, the file name recorded is relative to the main Lisp
4881 directory. These file names are converted to absolute at startup. */);
4882 Vload_history = Qnil;
4884 DEFVAR_LISP ("load-file-name", Vload_file_name,
4885 doc: /* Full name of file being loaded by `load'. */);
4886 Vload_file_name = Qnil;
4888 DEFVAR_LISP ("user-init-file", Vuser_init_file,
4889 doc: /* File name, including directory, of user's initialization file.
4890 If the file loaded had extension `.elc', and the corresponding source file
4891 exists, this variable contains the name of source file, suitable for use
4892 by functions like `custom-save-all' which edit the init file.
4893 While Emacs loads and evaluates the init file, value is the real name
4894 of the file, regardless of whether or not it has the `.elc' extension. */);
4895 Vuser_init_file = Qnil;
4897 DEFVAR_LISP ("current-load-list", Vcurrent_load_list,
4898 doc: /* Used for internal purposes by `load'. */);
4899 Vcurrent_load_list = Qnil;
4901 DEFVAR_LISP ("load-read-function", Vload_read_function,
4902 doc: /* Function used by `load' and `eval-region' for reading expressions.
4903 Called with a single argument (the stream from which to read).
4904 The default is to use the function `read'. */);
4905 DEFSYM (Qread, "read");
4906 Vload_read_function = Qread;
4908 DEFVAR_LISP ("load-source-file-function", Vload_source_file_function,
4909 doc: /* Function called in `load' to load an Emacs Lisp source file.
4910 The value should be a function for doing code conversion before
4911 reading a source file. It can also be nil, in which case loading is
4912 done without any code conversion.
4914 If the value is a function, it is called with four arguments,
4915 FULLNAME, FILE, NOERROR, NOMESSAGE. FULLNAME is the absolute name of
4916 the file to load, FILE is the non-absolute name (for messages etc.),
4917 and NOERROR and NOMESSAGE are the corresponding arguments passed to
4918 `load'. The function should return t if the file was loaded. */);
4919 Vload_source_file_function = Qnil;
4921 DEFVAR_BOOL ("load-force-doc-strings", load_force_doc_strings,
4922 doc: /* Non-nil means `load' should force-load all dynamic doc strings.
4923 This is useful when the file being loaded is a temporary copy. */);
4924 load_force_doc_strings = 0;
4926 DEFVAR_BOOL ("load-convert-to-unibyte", load_convert_to_unibyte,
4927 doc: /* Non-nil means `read' converts strings to unibyte whenever possible.
4928 This is normally bound by `load' and `eval-buffer' to control `read',
4929 and is not meant for users to change. */);
4930 load_convert_to_unibyte = 0;
4932 DEFVAR_LISP ("source-directory", Vsource_directory,
4933 doc: /* Directory in which Emacs sources were found when Emacs was built.
4934 You cannot count on them to still be there! */);
4935 Vsource_directory
4936 = Fexpand_file_name (build_string ("../"),
4937 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH, 0)));
4939 DEFVAR_LISP ("preloaded-file-list", Vpreloaded_file_list,
4940 doc: /* List of files that were preloaded (when dumping Emacs). */);
4941 Vpreloaded_file_list = Qnil;
4943 DEFVAR_LISP ("byte-boolean-vars", Vbyte_boolean_vars,
4944 doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4945 Vbyte_boolean_vars = Qnil;
4947 DEFVAR_BOOL ("load-dangerous-libraries", load_dangerous_libraries,
4948 doc: /* Non-nil means load dangerous compiled Lisp files.
4949 Some versions of XEmacs use different byte codes than Emacs. These
4950 incompatible byte codes can make Emacs crash when it tries to execute
4951 them. */);
4952 load_dangerous_libraries = 0;
4954 DEFVAR_BOOL ("force-load-messages", force_load_messages,
4955 doc: /* Non-nil means force printing messages when loading Lisp files.
4956 This overrides the value of the NOMESSAGE argument to `load'. */);
4957 force_load_messages = 0;
4959 DEFVAR_LISP ("bytecomp-version-regexp", Vbytecomp_version_regexp,
4960 doc: /* Regular expression matching safe to load compiled Lisp files.
4961 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4962 from the file, and matches them against this regular expression.
4963 When the regular expression matches, the file is considered to be safe
4964 to load. See also `load-dangerous-libraries'. */);
4965 Vbytecomp_version_regexp
4966 = build_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4968 DEFSYM (Qlexical_binding, "lexical-binding");
4969 DEFVAR_LISP ("lexical-binding", Vlexical_binding,
4970 doc: /* Whether to use lexical binding when evaluating code.
4971 Non-nil means that the code in the current buffer should be evaluated
4972 with lexical binding.
4973 This variable is automatically set from the file variables of an
4974 interpreted Lisp file read using `load'. Unlike other file local
4975 variables, this must be set in the first line of a file. */);
4976 Vlexical_binding = Qnil;
4977 Fmake_variable_buffer_local (Qlexical_binding);
4979 DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list,
4980 doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4981 Veval_buffer_list = Qnil;
4983 DEFVAR_LISP ("lread--old-style-backquotes", Vlread_old_style_backquotes,
4984 doc: /* Set to non-nil when `read' encounters an old-style backquote.
4985 For internal use only. */);
4986 Vlread_old_style_backquotes = Qnil;
4987 DEFSYM (Qlread_old_style_backquotes, "lread--old-style-backquotes");
4989 DEFVAR_LISP ("lread--unescaped-character-literals",
4990 Vlread_unescaped_character_literals,
4991 doc: /* List of deprecated unescaped character literals encountered by `read'.
4992 For internal use only. */);
4993 Vlread_unescaped_character_literals = Qnil;
4994 DEFSYM (Qlread_unescaped_character_literals,
4995 "lread--unescaped-character-literals");
4997 DEFSYM (Qlss, "<");
4998 DEFSYM (Qchar, "char");
4999 DEFSYM (Qformat, "format");
5001 DEFVAR_BOOL ("load-prefer-newer", load_prefer_newer,
5002 doc: /* Non-nil means `load' prefers the newest version of a file.
5003 This applies when a filename suffix is not explicitly specified and
5004 `load' is trying various possible suffixes (see `load-suffixes' and
5005 `load-file-rep-suffixes'). Normally, it stops at the first file
5006 that exists unless you explicitly specify one or the other. If this
5007 option is non-nil, it checks all suffixes and uses whichever file is
5008 newest.
5009 Note that if you customize this, obviously it will not affect files
5010 that are loaded before your customizations are read! */);
5011 load_prefer_newer = 0;
5013 /* Vsource_directory was initialized in init_lread. */
5015 DEFSYM (Qcurrent_load_list, "current-load-list");
5016 DEFSYM (Qstandard_input, "standard-input");
5017 DEFSYM (Qread_char, "read-char");
5018 DEFSYM (Qget_file_char, "get-file-char");
5020 /* Used instead of Qget_file_char while loading *.elc files compiled
5021 by Emacs 21 or older. */
5022 DEFSYM (Qget_emacs_mule_file_char, "get-emacs-mule-file-char");
5024 DEFSYM (Qload_force_doc_strings, "load-force-doc-strings");
5026 DEFSYM (Qbackquote, "`");
5027 DEFSYM (Qcomma, ",");
5028 DEFSYM (Qcomma_at, ",@");
5029 DEFSYM (Qcomma_dot, ",.");
5031 DEFSYM (Qinhibit_file_name_operation, "inhibit-file-name-operation");
5032 DEFSYM (Qascii_character, "ascii-character");
5033 DEFSYM (Qfunction, "function");
5034 DEFSYM (Qload, "load");
5035 DEFSYM (Qload_file_name, "load-file-name");
5036 DEFSYM (Qeval_buffer_list, "eval-buffer-list");
5037 DEFSYM (Qfile_truename, "file-truename");
5038 DEFSYM (Qdir_ok, "dir-ok");
5039 DEFSYM (Qdo_after_load_evaluation, "do-after-load-evaluation");
5041 staticpro (&read_objects_map);
5042 read_objects_map = Qnil;
5043 staticpro (&read_objects_completed);
5044 read_objects_completed = Qnil;
5046 Vloads_in_progress = Qnil;
5047 staticpro (&Vloads_in_progress);
5049 DEFSYM (Qhash_table, "hash-table");
5050 DEFSYM (Qdata, "data");
5051 DEFSYM (Qtest, "test");
5052 DEFSYM (Qsize, "size");
5053 DEFSYM (Qpurecopy, "purecopy");
5054 DEFSYM (Qweakness, "weakness");
5055 DEFSYM (Qrehash_size, "rehash-size");
5056 DEFSYM (Qrehash_threshold, "rehash-threshold");
5058 DEFSYM (Qchar_from_name, "char-from-name");