Use display_hourglass_p, start_hourglass, cancel_hourglass instead of
[bpt/emacs.git] / src / lread.c
CommitLineData
078e7b4a 1/* Lisp parsing and input streams.
df6c90d8 2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 99, 2000, 2001
33046fc9 3 Free Software Foundation, Inc.
078e7b4a
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
46947372 9the Free Software Foundation; either version 2, or (at your option)
078e7b4a
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
078e7b4a
JB
21
22
98280b76 23#include <config.h>
078e7b4a
JB
24#include <stdio.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <sys/file.h>
2c1b5dbe 28#include <errno.h>
078e7b4a 29#include "lisp.h"
95384e1e 30#include "intervals.h"
078e7b4a 31#include "buffer.h"
fe0e03f3 32#include "charset.h"
57bda87a 33#include <epaths.h>
078e7b4a 34#include "commands.h"
e37c0805 35#include "keyboard.h"
7bd279cd 36#include "termhooks.h"
078e7b4a
JB
37
38#ifdef lint
39#include <sys/inode.h>
40#endif /* lint */
41
79051982
RS
42#ifdef MSDOS
43#if __DJGPP__ < 2
44#include <unistd.h> /* to get X_OK */
45#endif
46#include "msdos.h"
47#endif
48
c1a2f60a
AS
49#ifdef HAVE_UNISTD_H
50#include <unistd.h>
51#endif
52
078e7b4a
JB
53#ifndef X_OK
54#define X_OK 01
55#endif
56
078e7b4a 57#include <math.h>
078e7b4a 58
c011e9a5
RS
59#ifdef HAVE_SETLOCALE
60#include <locale.h>
61#endif /* HAVE_SETLOCALE */
62
f7d279f0
RS
63#ifndef O_RDONLY
64#define O_RDONLY 0
65#endif
66
79cf851c 67#ifdef HAVE_FSEEKO
68c45bf0
PE
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
74
03695ace 75#ifndef USE_CRT_DLL
2c1b5dbe 76extern int errno;
03695ace 77#endif
2c1b5dbe 78
8a1f1537 79Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
078e7b4a 80Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
20ea2964 81Lisp_Object Qascii_character, Qload, Qload_file_name;
2b6cae0c 82Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
74549846 83Lisp_Object Qinhibit_file_name_operation;
7bd279cd
RS
84
85extern Lisp_Object Qevent_symbol_element_mask;
74549846 86extern Lisp_Object Qfile_exists_p;
078e7b4a
JB
87
88/* non-zero if inside `load' */
89int load_in_progress;
90
1521a8fa
RS
91/* Directory in which the sources were found. */
92Lisp_Object Vsource_directory;
93
078e7b4a
JB
94/* Search path for files to be loaded. */
95Lisp_Object Vload_path;
96
4116ab9f
KH
97/* File name of user's init file. */
98Lisp_Object Vuser_init_file;
99
ae321d28
RS
100/* This is the user-visible association list that maps features to
101 lists of defs in their load files. */
102Lisp_Object Vload_history;
103
20ea2964 104/* This is used to build the load history. */
ae321d28
RS
105Lisp_Object Vcurrent_load_list;
106
4b104c41
RS
107/* List of files that were preloaded. */
108Lisp_Object Vpreloaded_file_list;
109
20ea2964
RS
110/* Name of file actually being read by `load'. */
111Lisp_Object Vload_file_name;
112
84a15045
RS
113/* Function to use for reading, in `load' and friends. */
114Lisp_Object Vload_read_function;
115
4ad679f9
EN
116/* The association list of objects read with the #n=object form.
117 Each member of the list has the form (n . object), and is used to
118 look up the object for the corresponding #n# construct.
119 It must be set to nil before all top-level calls to read0. */
120Lisp_Object read_objects;
121
b2a30870
RS
122/* Nonzero means load should forcibly load all dynamic doc strings. */
123static int load_force_doc_strings;
124
94e554db
RS
125/* Nonzero means read should convert strings to unibyte. */
126static int load_convert_to_unibyte;
127
fe0e03f3
KH
128/* Function to use for loading an Emacs lisp source file (not
129 compiled) instead of readevalloop. */
130Lisp_Object Vload_source_file_function;
131
1ffcc3b1
DL
132/* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
133Lisp_Object Vbyte_boolean_vars;
134
d2c6be7f
RS
135/* List of descriptors now open for Fload. */
136static Lisp_Object load_descriptor_list;
137
b2a30870 138/* File for get_file_char to read from. Use by load. */
078e7b4a
JB
139static FILE *instream;
140
141/* When nonzero, read conses in pure space */
142static int read_pure;
143
b2a30870 144/* For use within read-from-string (this reader is non-reentrant!!) */
078e7b4a 145static int read_from_string_index;
bed23cb2 146static int read_from_string_index_byte;
078e7b4a 147static int read_from_string_limit;
17634846 148
6f7f43d5
RS
149/* Number of bytes left to read in the buffer character
150 that `readchar' has already advanced over. */
151static int readchar_backlog;
152
c15cfd1f 153/* This contains the last string skipped with #@. */
b2a30870
RS
154static char *saved_doc_string;
155/* Length of buffer allocated in saved_doc_string. */
156static int saved_doc_string_size;
157/* Length of actual data in saved_doc_string. */
158static int saved_doc_string_length;
159/* This is the file position that string came from. */
68c45bf0 160static file_offset saved_doc_string_position;
b2a30870 161
c15cfd1f
RS
162/* This contains the previous string skipped with #@.
163 We copy it from saved_doc_string when a new string
164 is put in saved_doc_string. */
165static char *prev_saved_doc_string;
166/* Length of buffer allocated in prev_saved_doc_string. */
167static int prev_saved_doc_string_size;
168/* Length of actual data in prev_saved_doc_string. */
169static int prev_saved_doc_string_length;
170/* This is the file position that string came from. */
68c45bf0 171static file_offset prev_saved_doc_string_position;
c15cfd1f 172
17634846
RS
173/* Nonzero means inside a new-style backquote
174 with no surrounding parentheses.
175 Fread initializes this to zero, so we need not specbind it
176 or worry about what happens to it when there is an error. */
177static int new_backquote_flag;
7ee3bd7b
GM
178
179/* A list of file names for files being loaded in Fload. Used to
180 check for recursive loads. */
181
182static Lisp_Object Vloads_in_progress;
183
550a625e
GM
184/* Limit of the depth of recursive loads. */
185
186Lisp_Object Vrecursive_load_depth_limit;
187
188/* Non-zero means load dangerous compiled Lisp files. */
189
190int load_dangerous_libraries;
191
192/* A regular expression used to detect files compiled with Emacs. */
193
194static Lisp_Object Vbytecomp_version_regexp;
195
196static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
197 Lisp_Object (*) (), int,
198 Lisp_Object, Lisp_Object));
199static Lisp_Object load_unwind P_ ((Lisp_Object));
200static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
201
078e7b4a
JB
202\f
203/* Handle unreading and rereading of characters.
204 Write READCHAR to read a character,
fe0e03f3
KH
205 UNREAD(c) to unread c to be read again.
206
207 These macros actually read/unread a byte code, multibyte characters
208 are not handled here. The caller should manage them if necessary.
209 */
078e7b4a
JB
210
211#define READCHAR readchar (readcharfun)
212#define UNREAD(c) unreadchar (readcharfun, c)
213
214static int
215readchar (readcharfun)
216 Lisp_Object readcharfun;
217{
218 Lisp_Object tem;
95384e1e 219 register int c;
078e7b4a 220
cfff016d 221 if (BUFFERP (readcharfun))
078e7b4a 222 {
bed23cb2 223 register struct buffer *inbuffer = XBUFFER (readcharfun);
078e7b4a 224
bed23cb2
RS
225 int pt_byte = BUF_PT_BYTE (inbuffer);
226 int orig_pt_byte = pt_byte;
6f7f43d5 227
00a9a935
RS
228 if (readchar_backlog > 0)
229 /* We get the address of the byte just passed,
230 which is the last byte of the character.
231 The other bytes in this character are consecutive with it,
232 because the gap can't be in the middle of a character. */
233 return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1)
234 - --readchar_backlog);
235
bed23cb2
RS
236 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
237 return -1;
078e7b4a 238
00a9a935
RS
239 readchar_backlog = -1;
240
bed23cb2
RS
241 if (! NILP (inbuffer->enable_multibyte_characters))
242 {
00a9a935 243 /* Fetch the character code from the buffer. */
bed23cb2
RS
244 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
245 BUF_INC_POS (inbuffer, pt_byte);
246 c = STRING_CHAR (p, pt_byte - orig_pt_byte);
247 }
248 else
249 {
250 c = BUF_FETCH_BYTE (inbuffer, pt_byte);
251 pt_byte++;
6f7f43d5 252 }
bed23cb2 253 SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
6f7f43d5 254
bed23cb2 255 return c;
078e7b4a 256 }
cfff016d 257 if (MARKERP (readcharfun))
078e7b4a 258 {
bed23cb2 259 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
078e7b4a 260
bed23cb2
RS
261 int bytepos = marker_byte_position (readcharfun);
262 int orig_bytepos = bytepos;
6f7f43d5 263
00a9a935
RS
264 if (readchar_backlog > 0)
265 /* We get the address of the byte just passed,
266 which is the last byte of the character.
267 The other bytes in this character are consecutive with it,
268 because the gap can't be in the middle of a character. */
269 return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1)
270 - --readchar_backlog);
271
bed23cb2
RS
272 if (bytepos >= BUF_ZV_BYTE (inbuffer))
273 return -1;
6f7f43d5 274
00a9a935
RS
275 readchar_backlog = -1;
276
bed23cb2
RS
277 if (! NILP (inbuffer->enable_multibyte_characters))
278 {
00a9a935 279 /* Fetch the character code from the buffer. */
bed23cb2
RS
280 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
281 BUF_INC_POS (inbuffer, bytepos);
282 c = STRING_CHAR (p, bytepos - orig_bytepos);
283 }
284 else
285 {
286 c = BUF_FETCH_BYTE (inbuffer, bytepos);
287 bytepos++;
6f7f43d5
RS
288 }
289
bed23cb2
RS
290 XMARKER (readcharfun)->bytepos = bytepos;
291 XMARKER (readcharfun)->charpos++;
292
293 return c;
078e7b4a 294 }
ad0153e4
RS
295
296 if (EQ (readcharfun, Qlambda))
297 return read_bytecode_char (0);
298
078e7b4a 299 if (EQ (readcharfun, Qget_file_char))
2c1b5dbe
KH
300 {
301 c = getc (instream);
302#ifdef EINTR
303 /* Interrupted reads have been observed while reading over the network */
304 while (c == EOF && ferror (instream) && errno == EINTR)
305 {
306 clearerr (instream);
307 c = getc (instream);
308 }
309#endif
310 return c;
311 }
078e7b4a 312
cfff016d 313 if (STRINGP (readcharfun))
078e7b4a 314 {
bed23cb2 315 if (read_from_string_index >= read_from_string_limit)
078e7b4a 316 c = -1;
f0354c03 317 else
bed23cb2
RS
318 FETCH_STRING_CHAR_ADVANCE (c, readcharfun,
319 read_from_string_index,
320 read_from_string_index_byte);
6f7f43d5 321
078e7b4a
JB
322 return c;
323 }
324
325 tem = call0 (readcharfun);
326
265a9e55 327 if (NILP (tem))
078e7b4a
JB
328 return -1;
329 return XINT (tem);
330}
331
332/* Unread the character C in the way appropriate for the stream READCHARFUN.
333 If the stream is a user function, call it with the char as argument. */
334
335static void
336unreadchar (readcharfun, c)
337 Lisp_Object readcharfun;
338 int c;
339{
92fddec9
KH
340 if (c == -1)
341 /* Don't back up the pointer if we're unreading the end-of-input mark,
342 since readchar didn't advance it when we read it. */
343 ;
cfff016d 344 else if (BUFFERP (readcharfun))
d7760ca9 345 {
bed23cb2
RS
346 struct buffer *b = XBUFFER (readcharfun);
347 int bytepos = BUF_PT_BYTE (b);
d7760ca9 348
00a9a935
RS
349 if (readchar_backlog >= 0)
350 readchar_backlog++;
bed23cb2 351 else
00a9a935
RS
352 {
353 BUF_PT (b)--;
354 if (! NILP (b->enable_multibyte_characters))
355 BUF_DEC_POS (b, bytepos);
356 else
357 bytepos--;
d7760ca9 358
00a9a935
RS
359 BUF_PT_BYTE (b) = bytepos;
360 }
d7760ca9 361 }
cfff016d 362 else if (MARKERP (readcharfun))
d7760ca9 363 {
bed23cb2
RS
364 struct buffer *b = XMARKER (readcharfun)->buffer;
365 int bytepos = XMARKER (readcharfun)->bytepos;
d7760ca9 366
00a9a935
RS
367 if (readchar_backlog >= 0)
368 readchar_backlog++;
bed23cb2 369 else
00a9a935
RS
370 {
371 XMARKER (readcharfun)->charpos--;
372 if (! NILP (b->enable_multibyte_characters))
373 BUF_DEC_POS (b, bytepos);
374 else
375 bytepos--;
d7760ca9 376
00a9a935
RS
377 XMARKER (readcharfun)->bytepos = bytepos;
378 }
d7760ca9 379 }
cfff016d 380 else if (STRINGP (readcharfun))
bed23cb2
RS
381 {
382 read_from_string_index--;
383 read_from_string_index_byte
384 = string_char_to_byte (readcharfun, read_from_string_index);
385 }
ad0153e4
RS
386 else if (EQ (readcharfun, Qlambda))
387 read_bytecode_char (1);
078e7b4a
JB
388 else if (EQ (readcharfun, Qget_file_char))
389 ungetc (c, instream);
390 else
391 call1 (readcharfun, make_number (c));
392}
393
394static Lisp_Object read0 (), read1 (), read_list (), read_vector ();
6f7f43d5 395static int read_multibyte ();
9e062b6c
RS
396static Lisp_Object substitute_object_recurse ();
397static void substitute_object_in_subtree (), substitute_in_interval ();
398
078e7b4a 399\f
bed23cb2 400/* Get a character from the tty. */
078e7b4a 401
3d9b22be
JB
402extern Lisp_Object read_char ();
403
f42be754
JB
404/* Read input events until we get one that's acceptable for our purposes.
405
406 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
407 until we get a character we like, and then stuffed into
408 unread_switch_frame.
409
410 If ASCII_REQUIRED is non-zero, we check function key events to see
411 if the unmodified version of the symbol has a Qascii_character
412 property, and use that character, if present.
413
414 If ERROR_NONASCII is non-zero, we signal an error if the input we
415 get isn't an ASCII character with modifiers. If it's zero but
416 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
bb49a192
RS
417 character.
418
419 If INPUT_METHOD is nonzero, we invoke the current input method
420 if the character warrants that. */
cc39bc38 421
f42be754 422Lisp_Object
bb49a192
RS
423read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
424 input_method)
425 int no_switch_frame, ascii_required, error_nonascii, input_method;
f42be754 426{
153a17b7
KH
427 register Lisp_Object val, delayed_switch_frame;
428
5dbf89bc 429#ifdef HAVE_WINDOW_SYSTEM
df6c90d8
GM
430 if (display_hourglass_p)
431 cancel_hourglass ();
5dbf89bc
GM
432#endif
433
153a17b7 434 delayed_switch_frame = Qnil;
f42be754
JB
435
436 /* Read until we get an acceptable event. */
437 retry:
bb49a192
RS
438 val = read_char (0, 0, 0,
439 (input_method ? Qnil : Qt),
440 0);
f42be754 441
cfff016d 442 if (BUFFERP (val))
6c82d689
KH
443 goto retry;
444
f42be754 445 /* switch-frame events are put off until after the next ASCII
8e6208c5 446 character. This is better than signaling an error just because
f42be754
JB
447 the last characters were typed to a separate minibuffer frame,
448 for example. Eventually, some code which can deal with
449 switch-frame events will read it and process it. */
450 if (no_switch_frame
451 && EVENT_HAS_PARAMETERS (val)
452 && EQ (EVENT_HEAD (val), Qswitch_frame))
453 {
454 delayed_switch_frame = val;
455 goto retry;
456 }
457
458 if (ascii_required)
459 {
460 /* Convert certain symbols to their ASCII equivalents. */
cfff016d 461 if (SYMBOLP (val))
f42be754 462 {
95384e1e 463 Lisp_Object tem, tem1;
f42be754
JB
464 tem = Fget (val, Qevent_symbol_element_mask);
465 if (!NILP (tem))
466 {
467 tem1 = Fget (Fcar (tem), Qascii_character);
468 /* Merge this symbol's modifier bits
469 with the ASCII equivalent of its basic code. */
470 if (!NILP (tem1))
baf69866 471 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
f42be754
JB
472 }
473 }
474
475 /* If we don't have a character now, deal with it appropriately. */
cfff016d 476 if (!INTEGERP (val))
f42be754
JB
477 {
478 if (error_nonascii)
479 {
1ec84625 480 Vunread_command_events = Fcons (val, Qnil);
f42be754
JB
481 error ("Non-character input-event");
482 }
483 else
484 goto retry;
485 }
486 }
487
488 if (! NILP (delayed_switch_frame))
489 unread_switch_frame = delayed_switch_frame;
490
5dbf89bc 491#ifdef HAVE_WINDOW_SYSTEM
df6c90d8
GM
492 if (display_hourglass_p)
493 start_hourglass ();
5dbf89bc 494#endif
f42be754 495 return val;
f42be754
JB
496}
497
bb49a192 498DEFUN ("read-char", Fread_char, Sread_char, 0, 2, 0,
078e7b4a 499 "Read a character from the command input (keyboard or macro).\n\
e51e47f7
JB
500It is returned as a number.\n\
501If the user generates an event which is not a character (i.e. a mouse\n\
e37c0805
JB
502click or function key event), `read-char' signals an error. As an\n\
503exception, switch-frame events are put off until non-ASCII events can\n\
504be read.\n\
505If you want to read non-character events, or ignore them, call\n\
bb49a192
RS
506`read-event' or `read-char-exclusive' instead.\n\
507\n\
508If the optional argument PROMPT is non-nil, display that as a prompt.\n\
fc351d2f
KH
509If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
510input method is turned on in the current buffer, that input method\n\
511is used for reading a character.")
512 (prompt, inherit_input_method)
513 Lisp_Object prompt, inherit_input_method;
078e7b4a 514{
bb49a192
RS
515 if (! NILP (prompt))
516 message_with_string ("%s", prompt, 0);
fc351d2f 517 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method));
078e7b4a
JB
518}
519
bb49a192
RS
520DEFUN ("read-event", Fread_event, Sread_event, 0, 2, 0,
521 "Read an event object from the input stream.\n\
522If the optional argument PROMPT is non-nil, display that as a prompt.\n\
fc351d2f
KH
523If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
524input method is turned on in the current buffer, that input method\n\
525is used for reading a character.")
526 (prompt, inherit_input_method)
527 Lisp_Object prompt, inherit_input_method;
078e7b4a 528{
bb49a192
RS
529 if (! NILP (prompt))
530 message_with_string ("%s", prompt, 0);
fc351d2f 531 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method));
078e7b4a
JB
532}
533
bb49a192 534DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 2, 0,
078e7b4a 535 "Read a character from the command input (keyboard or macro).\n\
bb49a192
RS
536It is returned as a number. Non-character events are ignored.\n\
537\n\
538If the optional argument PROMPT is non-nil, display that as a prompt.\n\
fc351d2f
KH
539If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
540input method is turned on in the current buffer, that input method\n\
541is used for reading a character.")
542 (prompt, inherit_input_method)
543 Lisp_Object prompt, inherit_input_method;
078e7b4a 544{
bb49a192
RS
545 if (! NILP (prompt))
546 message_with_string ("%s", prompt, 0);
fc351d2f 547 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method));
078e7b4a 548}
078e7b4a
JB
549
550DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
551 "Don't use this yourself.")
552 ()
553{
554 register Lisp_Object val;
1805de4f 555 XSETINT (val, getc (instream));
078e7b4a
JB
556 return val;
557}
da84f340
GM
558
559
550a625e 560\f
da84f340
GM
561/* Value is non-zero if the file asswociated with file descriptor FD
562 is a compiled Lisp file that's safe to load. Only files compiled
563 with Emacs are safe to load. Files compiled with XEmacs can lead
564 to a crash in Fbyte_code because of an incompatible change in the
565 byte compiler. */
566
567static int
568safe_to_load_p (fd)
569 int fd;
570{
571 char buf[512];
572 int nbytes, i;
573 int safe_p = 1;
574
575 /* Read the first few bytes from the file, and look for a line
576 specifying the byte compiler version used. */
577 nbytes = emacs_read (fd, buf, sizeof buf - 1);
578 if (nbytes > 0)
579 {
580 buf[nbytes] = '\0';
581
582 /* Skip to the next newline, skipping over the initial `ELC'
583 with NUL bytes following it. */
584 for (i = 0; i < nbytes && buf[i] != '\n'; ++i)
585 ;
586
587 if (i < nbytes
588 && fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
589 buf + i) < 0)
590 safe_p = 0;
591 }
592
593 lseek (fd, 0, SEEK_SET);
594 return safe_p;
595}
596
597
7ee3bd7b
GM
598/* Callback for record_unwind_protect. Restore the old load list OLD,
599 after loading a file successfully. */
600
601static Lisp_Object
602record_load_unwind (old)
603 Lisp_Object old;
604{
605 return Vloads_in_progress = old;
606}
607
608
f0a50954 609DEFUN ("load", Fload, Sload, 1, 5, 0,
078e7b4a
JB
610 "Execute a file of Lisp code named FILE.\n\
611First try FILE with `.elc' appended, then try with `.el',\n\
612 then try FILE unmodified.\n\
613This function searches the directories in `load-path'.\n\
614If optional second arg NOERROR is non-nil,\n\
615 report no error if FILE doesn't exist.\n\
616Print messages at start and end of loading unless\n\
617 optional third arg NOMESSAGE is non-nil.\n\
618If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
619 suffixes `.elc' or `.el' to the specified name FILE.\n\
211f7dcd 620If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
7b88a4cf 621 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
211f7dcd 622 it ends in one of those suffixes or includes a directory name.\n\
078e7b4a 623Return t if file exists.")
f0a50954
RS
624 (file, noerror, nomessage, nosuffix, must_suffix)
625 Lisp_Object file, noerror, nomessage, nosuffix, must_suffix;
078e7b4a
JB
626{
627 register FILE *stream;
628 register int fd = -1;
629 register Lisp_Object lispstream;
078e7b4a
JB
630 int count = specpdl_ptr - specpdl;
631 Lisp_Object temp;
632 struct gcpro gcpro1;
633 Lisp_Object found;
04fc68e7
RS
634 /* 1 means we printed the ".el is newer" message. */
635 int newer = 0;
636 /* 1 means we are loading a compiled file. */
637 int compiled = 0;
c2225d00 638 Lisp_Object handler;
456c67a4 639 int safe_p = 1;
229ba775 640 char *fmode = "r";
317073d5 641#ifdef DOS_NT
229ba775 642 fmode = "rt";
317073d5 643#endif /* DOS_NT */
078e7b4a 644
0745dce9 645 CHECK_STRING (file, 0);
078e7b4a 646
c2225d00 647 /* If file name is magic, call the handler. */
0745dce9 648 handler = Ffind_file_name_handler (file, Qload);
c2225d00 649 if (!NILP (handler))
0745dce9 650 return call5 (handler, Qload, file, noerror, nomessage, nosuffix);
c2225d00 651
07a0bda3
RS
652 /* Do this after the handler to avoid
653 the need to gcpro noerror, nomessage and nosuffix.
654 (Below here, we care only whether they are nil or not.) */
0745dce9 655 file = Fsubstitute_in_file_name (file);
07a0bda3 656
078e7b4a
JB
657 /* Avoid weird lossage with null string as arg,
658 since it would try to load a directory as a Lisp file */
0745dce9 659 if (XSTRING (file)->size > 0)
078e7b4a 660 {
471aa4a0 661 int size = STRING_BYTES (XSTRING (file));
211f7dcd 662
0745dce9 663 GCPRO1 (file);
211f7dcd
RS
664
665 if (! NILP (must_suffix))
666 {
667 /* Don't insist on adding a suffix if FILE already ends with one. */
668 if (size > 3
669 && !strcmp (XSTRING (file)->data + size - 3, ".el"))
670 must_suffix = Qnil;
671 else if (size > 4
672 && !strcmp (XSTRING (file)->data + size - 4, ".elc"))
673 must_suffix = Qnil;
674 /* Don't insist on adding a suffix
675 if the argument includes a directory name. */
676 else if (! NILP (Ffile_name_directory (file)))
677 must_suffix = Qnil;
678 }
679
f0a50954
RS
680 fd = openp (Vload_path, file,
681 (!NILP (nosuffix) ? ""
9b7c9ebd
DL
682 : ! NILP (must_suffix) ? ".elc.gz:.elc:.el.gz:.el"
683 : ".elc:.elc.gz:.el.gz:.el:"),
078e7b4a 684 &found, 0);
5a6e5452 685 UNGCPRO;
078e7b4a
JB
686 }
687
96dc0f4e 688 if (fd == -1)
078e7b4a 689 {
265a9e55 690 if (NILP (noerror))
078e7b4a
JB
691 while (1)
692 Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"),
0745dce9 693 Fcons (file, Qnil)));
078e7b4a
JB
694 else
695 return Qnil;
696 }
697
ba0d1195 698 /* Tell startup.el whether or not we found the user's init file. */
4116ab9f
KH
699 if (EQ (Qt, Vuser_init_file))
700 Vuser_init_file = found;
701
96dc0f4e
MB
702 /* If FD is -2, that means openp found a magic file. */
703 if (fd == -2)
74549846 704 {
5e24a1f7
KH
705 if (NILP (Fequal (found, file)))
706 /* If FOUND is a different file name from FILE,
707 find its handler even if we have already inhibited
708 the `load' operation on FILE. */
709 handler = Ffind_file_name_handler (found, Qt);
710 else
711 handler = Ffind_file_name_handler (found, Qload);
712 if (! NILP (handler))
713 return call5 (handler, Qload, found, noerror, nomessage, Qt);
74549846
RS
714 }
715
550a625e
GM
716 /* Check if we're stuck in a recursive load cycle.
717
718 2000-09-21: It's not possible to just check for the file loaded
719 being a member of Vloads_in_progress. This fails because of the
720 way the byte compiler currently works; `provide's are not
721 evaluted, see font-lock.el/jit-lock.el as an example. This
722 leads to a certain amount of ``normal'' recursion.
723
724 Also, just loading a file recursively is not always an error in
725 the general case; the second load may do something different. */
726 if (INTEGERP (Vrecursive_load_depth_limit)
727 && XINT (Vrecursive_load_depth_limit) > 0)
728 {
729 Lisp_Object len = Flength (Vloads_in_progress);
730 if (XFASTINT (len) > XFASTINT (Vrecursive_load_depth_limit))
731 Fsignal (Qerror, Fcons (build_string ("Recursive load suspected"),
732 Fcons (found, Vloads_in_progress)));
733 record_unwind_protect (record_load_unwind, Vloads_in_progress);
734 Vloads_in_progress = Fcons (found, Vloads_in_progress);
735 }
7ee3bd7b 736
471aa4a0 737 if (!bcmp (&(XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 4]),
96dc0f4e
MB
738 ".elc", 4))
739 /* Load .elc files directly, but not when they are
740 remote and have no handler! */
078e7b4a 741 {
96dc0f4e 742 if (fd != -2)
da84f340 743 {
96dc0f4e
MB
744 struct stat s1, s2;
745 int result;
da84f340 746
96dc0f4e
MB
747 if (!safe_to_load_p (fd))
748 {
749 safe_p = 0;
750 if (!load_dangerous_libraries)
751 error ("File `%s' was not compiled in Emacs",
752 XSTRING (found)->data);
753 else if (!NILP (nomessage))
754 message_with_string ("File `%s' not compiled in Emacs", found, 1);
755 }
04fc68e7 756
96dc0f4e
MB
757 compiled = 1;
758
26fbf20b 759#ifdef DOS_NT
96dc0f4e 760 fmode = "rb";
26fbf20b 761#endif /* DOS_NT */
96dc0f4e
MB
762 stat ((char *)XSTRING (found)->data, &s1);
763 XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 0;
764 result = stat ((char *)XSTRING (found)->data, &s2);
765 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
766 {
767 /* Make the progress messages mention that source is newer. */
768 newer = 1;
04fc68e7 769
96dc0f4e
MB
770 /* If we won't print another message, mention this anyway. */
771 if (! NILP (nomessage))
772 message_with_string ("Source file `%s' newer than byte-compiled file",
773 found, 1);
774 }
775 XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 'c';
51ac6f83 776 }
078e7b4a 777 }
fe0e03f3
KH
778 else
779 {
da84f340
GM
780 load_source:
781
fe0e03f3
KH
782 /* We are loading a source file (*.el). */
783 if (!NILP (Vload_source_file_function))
784 {
7ee3bd7b 785 Lisp_Object val;
96dc0f4e
MB
786
787 if (fd >= 0)
68c45bf0 788 emacs_close (fd);
7ee3bd7b
GM
789 val = call4 (Vload_source_file_function, found, file,
790 NILP (noerror) ? Qnil : Qt,
791 NILP (nomessage) ? Qnil : Qt);
792 return unbind_to (count, val);
fe0e03f3
KH
793 }
794 }
078e7b4a 795
229ba775 796#ifdef WINDOWSNT
68c45bf0 797 emacs_close (fd);
229ba775
EZ
798 stream = fopen ((char *) XSTRING (found)->data, fmode);
799#else /* not WINDOWSNT */
800 stream = fdopen (fd, fmode);
801#endif /* not WINDOWSNT */
078e7b4a
JB
802 if (stream == 0)
803 {
68c45bf0 804 emacs_close (fd);
0745dce9 805 error ("Failure to create stdio stream for %s", XSTRING (file)->data);
078e7b4a
JB
806 }
807
4b104c41
RS
808 if (! NILP (Vpurify_flag))
809 Vpreloaded_file_list = Fcons (file, Vpreloaded_file_list);
810
04fc68e7
RS
811 if (NILP (nomessage))
812 {
da84f340
GM
813 if (!safe_p)
814 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
815 file, 1);
816 else if (!compiled)
e28552a4 817 message_with_string ("Loading %s (source)...", file, 1);
db5cae4b 818 else if (newer)
e28552a4
RS
819 message_with_string ("Loading %s (compiled; note, source file is newer)...",
820 file, 1);
db5cae4b 821 else /* The typical case; compiled file newer than source file. */
e28552a4 822 message_with_string ("Loading %s...", file, 1);
04fc68e7 823 }
078e7b4a 824
0745dce9 825 GCPRO1 (file);
838abf56 826 lispstream = Fcons (Qnil, Qnil);
c1d497be
KR
827 XSETFASTINT (XCAR (lispstream), (EMACS_UINT)stream >> 16);
828 XSETFASTINT (XCDR (lispstream), (EMACS_UINT)stream & 0xffff);
078e7b4a 829 record_unwind_protect (load_unwind, lispstream);
d2c6be7f 830 record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
20ea2964 831 specbind (Qload_file_name, found);
74549846 832 specbind (Qinhibit_file_name_operation, Qnil);
d2c6be7f
RS
833 load_descriptor_list
834 = Fcons (make_number (fileno (stream)), load_descriptor_list);
078e7b4a 835 load_in_progress++;
976350af 836 readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil);
078e7b4a
JB
837 unbind_to (count, Qnil);
838
839 /* Run any load-hooks for this file. */
0745dce9 840 temp = Fassoc (file, Vafter_load_alist);
265a9e55 841 if (!NILP (temp))
078e7b4a
JB
842 Fprogn (Fcdr (temp));
843 UNGCPRO;
844
b2a30870
RS
845 if (saved_doc_string)
846 free (saved_doc_string);
847 saved_doc_string = 0;
848 saved_doc_string_size = 0;
849
c15cfd1f 850 if (prev_saved_doc_string)
3cb65b0e 851 xfree (prev_saved_doc_string);
c15cfd1f
RS
852 prev_saved_doc_string = 0;
853 prev_saved_doc_string_size = 0;
854
265a9e55 855 if (!noninteractive && NILP (nomessage))
04fc68e7 856 {
da84f340
GM
857 if (!safe_p)
858 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
859 file, 1);
860 else if (!compiled)
e28552a4 861 message_with_string ("Loading %s (source)...done", file, 1);
db5cae4b 862 else if (newer)
e28552a4
RS
863 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
864 file, 1);
db5cae4b 865 else /* The typical case; compiled file newer than source file. */
e28552a4 866 message_with_string ("Loading %s...done", file, 1);
04fc68e7 867 }
7ee3bd7b 868
078e7b4a
JB
869 return Qt;
870}
871
872static Lisp_Object
873load_unwind (stream) /* used as unwind-protect function in load */
874 Lisp_Object stream;
875{
c1d497be
KR
876 fclose ((FILE *) (XFASTINT (XCAR (stream)) << 16
877 | XFASTINT (XCDR (stream))));
078e7b4a
JB
878 if (--load_in_progress < 0) load_in_progress = 0;
879 return Qnil;
880}
881
d2c6be7f
RS
882static Lisp_Object
883load_descriptor_unwind (oldlist)
884 Lisp_Object oldlist;
885{
886 load_descriptor_list = oldlist;
838abf56 887 return Qnil;
d2c6be7f
RS
888}
889
890/* Close all descriptors in use for Floads.
891 This is used when starting a subprocess. */
892
893void
894close_load_descs ()
895{
f3849f25 896#ifndef WINDOWSNT
d2c6be7f 897 Lisp_Object tail;
c1d497be 898 for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail))
68c45bf0 899 emacs_close (XFASTINT (XCAR (tail)));
f3849f25 900#endif
d2c6be7f 901}
078e7b4a
JB
902\f
903static int
904complete_filename_p (pathname)
905 Lisp_Object pathname;
906{
907 register unsigned char *s = XSTRING (pathname)->data;
317073d5
RS
908 return (IS_DIRECTORY_SEP (s[0])
909 || (XSTRING (pathname)->size > 2
910 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
078e7b4a
JB
911#ifdef ALTOS
912 || *s == '@'
913#endif
914#ifdef VMS
915 || index (s, ':')
916#endif /* VMS */
917 );
918}
919
920/* Search for a file whose name is STR, looking in directories
921 in the Lisp list PATH, and trying suffixes from SUFFIX.
922 SUFFIX is a string containing possible suffixes separated by colons.
923 On success, returns a file descriptor. On failure, returns -1.
924
925 EXEC_ONLY nonzero means don't open the files,
926 just look for one that is executable. In this case,
927 returns 1 on success.
928
929 If STOREPTR is nonzero, it points to a slot where the name of
930 the file actually found should be stored as a Lisp string.
74549846
RS
931 nil is stored there on failure.
932
96dc0f4e 933 If the file we find is remote, return -2
74549846
RS
934 but store the found remote file name in *STOREPTR.
935 We do not check for remote files if EXEC_ONLY is nonzero. */
078e7b4a
JB
936
937int
938openp (path, str, suffix, storeptr, exec_only)
939 Lisp_Object path, str;
940 char *suffix;
941 Lisp_Object *storeptr;
942 int exec_only;
943{
944 register int fd;
945 int fn_size = 100;
946 char buf[100];
947 register char *fn = buf;
948 int absolute = 0;
949 int want_size;
74549846 950 Lisp_Object filename;
078e7b4a 951 struct stat st;
8c0f83fe 952 struct gcpro gcpro1, gcpro2, gcpro3;
ace46dfe 953 Lisp_Object string;
078e7b4a 954
8c0f83fe
GM
955 string = filename = Qnil;
956 GCPRO3 (str, string, filename);
ace46dfe 957
078e7b4a
JB
958 if (storeptr)
959 *storeptr = Qnil;
960
961 if (complete_filename_p (str))
962 absolute = 1;
963
265a9e55 964 for (; !NILP (path); path = Fcdr (path))
078e7b4a
JB
965 {
966 char *nsuffix;
967
968 filename = Fexpand_file_name (str, Fcar (path));
969 if (!complete_filename_p (filename))
970 /* If there are non-absolute elts in PATH (eg ".") */
971 /* Of course, this could conceivably lose if luser sets
972 default-directory to be something non-absolute... */
973 {
974 filename = Fexpand_file_name (filename, current_buffer->directory);
975 if (!complete_filename_p (filename))
976 /* Give up on this path element! */
977 continue;
978 }
979
980 /* Calculate maximum size of any filename made from
981 this path element/specified file name and any possible suffix. */
471aa4a0 982 want_size = strlen (suffix) + STRING_BYTES (XSTRING (filename)) + 1;
078e7b4a
JB
983 if (fn_size < want_size)
984 fn = (char *) alloca (fn_size = 100 + want_size);
985
986 nsuffix = suffix;
987
988 /* Loop over suffixes. */
989 while (1)
990 {
991 char *esuffix = (char *) index (nsuffix, ':');
992 int lsuffix = esuffix ? esuffix - nsuffix : strlen (nsuffix);
74549846 993 Lisp_Object handler;
078e7b4a 994
c49afcd7
RS
995 /* Concatenate path element/specified name with the suffix.
996 If the directory starts with /:, remove that. */
997 if (XSTRING (filename)->size > 2
998 && XSTRING (filename)->data[0] == '/'
999 && XSTRING (filename)->data[1] == ':')
1000 {
1001 strncpy (fn, XSTRING (filename)->data + 2,
471aa4a0
KH
1002 STRING_BYTES (XSTRING (filename)) - 2);
1003 fn[STRING_BYTES (XSTRING (filename)) - 2] = 0;
c49afcd7
RS
1004 }
1005 else
1006 {
471aa4a0
KH
1007 strncpy (fn, XSTRING (filename)->data,
1008 STRING_BYTES (XSTRING (filename)));
1009 fn[STRING_BYTES (XSTRING (filename))] = 0;
c49afcd7
RS
1010 }
1011
078e7b4a
JB
1012 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1013 strncat (fn, nsuffix, lsuffix);
1014
74549846
RS
1015 /* Check that the file exists and is not a directory. */
1016 if (absolute)
1017 handler = Qnil;
1018 else
1019 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1020 if (! NILP (handler) && ! exec_only)
078e7b4a 1021 {
74549846 1022 int exists;
078e7b4a 1023
74549846
RS
1024 string = build_string (fn);
1025 exists = ! NILP (exec_only ? Ffile_executable_p (string)
1026 : Ffile_readable_p (string));
1027 if (exists
1028 && ! NILP (Ffile_directory_p (build_string (fn))))
1029 exists = 0;
1030
1031 if (exists)
078e7b4a
JB
1032 {
1033 /* We succeeded; return this descriptor and filename. */
1034 if (storeptr)
1035 *storeptr = build_string (fn);
5ef2a3c0 1036 UNGCPRO;
96dc0f4e 1037 return -2;
74549846
RS
1038 }
1039 }
1040 else
1041 {
1042 int exists = (stat (fn, &st) >= 0
1043 && (st.st_mode & S_IFMT) != S_IFDIR);
1044 if (exists)
1045 {
1046 /* Check that we can access or open it. */
1047 if (exec_only)
1048 fd = (access (fn, X_OK) == 0) ? 1 : -1;
1049 else
68c45bf0 1050 fd = emacs_open (fn, O_RDONLY, 0);
74549846
RS
1051
1052 if (fd >= 0)
1053 {
1054 /* We succeeded; return this descriptor and filename. */
1055 if (storeptr)
1056 *storeptr = build_string (fn);
1057 UNGCPRO;
1058 return fd;
1059 }
078e7b4a
JB
1060 }
1061 }
1062
1063 /* Advance to next suffix. */
1064 if (esuffix == 0)
1065 break;
1066 nsuffix += lsuffix + 1;
1067 }
5a6e5452 1068 if (absolute)
5ef2a3c0 1069 break;
078e7b4a
JB
1070 }
1071
5ef2a3c0
KH
1072 UNGCPRO;
1073 return -1;
078e7b4a
JB
1074}
1075
1076\f
ae321d28
RS
1077/* Merge the list we've accumulated of globals from the current input source
1078 into the load_history variable. The details depend on whether
1079 the source has an associated file name or not. */
1080
1081static void
1082build_load_history (stream, source)
1083 FILE *stream;
1084 Lisp_Object source;
1085{
1086 register Lisp_Object tail, prev, newelt;
1087 register Lisp_Object tem, tem2;
1088 register int foundit, loading;
1089
1090 loading = stream || !NARROWED;
1091
1092 tail = Vload_history;
1093 prev = Qnil;
1094 foundit = 0;
1095 while (!NILP (tail))
1096 {
1097 tem = Fcar (tail);
1098
1099 /* Find the feature's previous assoc list... */
1100 if (!NILP (Fequal (source, Fcar (tem))))
1101 {
1102 foundit = 1;
1103
1104 /* If we're loading, remove it. */
1105 if (loading)
1106 {
1107 if (NILP (prev))
1108 Vload_history = Fcdr (tail);
1109 else
1110 Fsetcdr (prev, Fcdr (tail));
1111 }
1112
1113 /* Otherwise, cons on new symbols that are not already members. */
1114 else
1115 {
1116 tem2 = Vcurrent_load_list;
1117
1118 while (CONSP (tem2))
1119 {
1120 newelt = Fcar (tem2);
1121
1122 if (NILP (Fmemq (newelt, tem)))
1123 Fsetcar (tail, Fcons (Fcar (tem),
1124 Fcons (newelt, Fcdr (tem))));
1125
1126 tem2 = Fcdr (tem2);
1127 QUIT;
1128 }
1129 }
1130 }
1131 else
1132 prev = tail;
1133 tail = Fcdr (tail);
1134 QUIT;
1135 }
1136
8a1f1537
RS
1137 /* If we're loading, cons the new assoc onto the front of load-history,
1138 the most-recently-loaded position. Also do this if we didn't find
1139 an existing member for the current source. */
1140 if (loading || !foundit)
1141 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1142 Vload_history);
ae321d28
RS
1143}
1144
078e7b4a 1145Lisp_Object
232ccf27
DL
1146unreadpure (junk) /* Used as unwind-protect function in readevalloop */
1147 Lisp_Object junk;
078e7b4a
JB
1148{
1149 read_pure = 0;
1150 return Qnil;
1151}
1152
94e554db
RS
1153static Lisp_Object
1154readevalloop_1 (old)
1155 Lisp_Object old;
1156{
1157 load_convert_to_unibyte = ! NILP (old);
1158 return Qnil;
1159}
1160
9c97398c
GM
1161/* Signal an `end-of-file' error, if possible with file name
1162 information. */
1163
1164static void
1165end_of_file_error ()
1166{
1167 Lisp_Object data;
1168
1169 if (STRINGP (Vload_file_name))
1170 data = Fcons (Vload_file_name, Qnil);
1171 else
1172 data = Qnil;
1173
1174 Fsignal (Qend_of_file, data);
1175}
1176
94e554db 1177/* UNIBYTE specifies how to set load_convert_to_unibyte
976350af
RS
1178 for this invocation.
1179 READFUN, if non-nil, is used instead of `read'. */
94e554db 1180
078e7b4a 1181static void
976350af 1182readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, readfun)
078e7b4a 1183 Lisp_Object readcharfun;
ae321d28
RS
1184 FILE *stream;
1185 Lisp_Object sourcename;
078e7b4a
JB
1186 Lisp_Object (*evalfun) ();
1187 int printflag;
976350af 1188 Lisp_Object unibyte, readfun;
078e7b4a
JB
1189{
1190 register int c;
1191 register Lisp_Object val;
1192 int count = specpdl_ptr - specpdl;
8a1f1537 1193 struct gcpro gcpro1;
49cf7ff4 1194 struct buffer *b = 0;
f38952fe 1195 int continue_reading_p;
49cf7ff4
RS
1196
1197 if (BUFFERP (readcharfun))
1198 b = XBUFFER (readcharfun);
1199 else if (MARKERP (readcharfun))
1200 b = XMARKER (readcharfun)->buffer;
078e7b4a
JB
1201
1202 specbind (Qstandard_input, readcharfun);
8a1f1537 1203 specbind (Qcurrent_load_list, Qnil);
94e554db
RS
1204 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
1205 load_convert_to_unibyte = !NILP (unibyte);
078e7b4a 1206
00a9a935 1207 readchar_backlog = -1;
6f7f43d5 1208
8a1f1537 1209 GCPRO1 (sourcename);
ae321d28 1210
ae321d28
RS
1211 LOADHIST_ATTACH (sourcename);
1212
f38952fe
GM
1213 continue_reading_p = 1;
1214 while (continue_reading_p)
078e7b4a 1215 {
49cf7ff4
RS
1216 if (b != 0 && NILP (b->name))
1217 error ("Reading from killed buffer");
1218
078e7b4a
JB
1219 instream = stream;
1220 c = READCHAR;
1221 if (c == ';')
1222 {
1223 while ((c = READCHAR) != '\n' && c != -1);
1224 continue;
1225 }
1226 if (c < 0) break;
6069d957
RS
1227
1228 /* Ignore whitespace here, so we can detect eof. */
1229 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
1230 continue;
078e7b4a 1231
265a9e55 1232 if (!NILP (Vpurify_flag) && c == '(')
078e7b4a 1233 {
0e326373 1234 int count1 = specpdl_ptr - specpdl;
078e7b4a
JB
1235 record_unwind_protect (unreadpure, Qnil);
1236 val = read_list (-1, readcharfun);
0e326373 1237 unbind_to (count1, Qnil);
078e7b4a
JB
1238 }
1239 else
1240 {
1241 UNREAD (c);
4ad679f9 1242 read_objects = Qnil;
f38952fe
GM
1243 if (!NILP (readfun))
1244 {
1245 val = call1 (readfun, readcharfun);
1246
1247 /* If READCHARFUN has set point to ZV, we should
1248 stop reading, even if the form read sets point
1249 to a different value when evaluated. */
1250 if (BUFFERP (readcharfun))
1251 {
1252 struct buffer *b = XBUFFER (readcharfun);
1253 if (BUF_PT (b) == BUF_ZV (b))
1254 continue_reading_p = 0;
1255 }
1256 }
976350af 1257 else if (! NILP (Vload_read_function))
84a15045 1258 val = call1 (Vload_read_function, readcharfun);
976350af
RS
1259 else
1260 val = read0 (readcharfun);
078e7b4a
JB
1261 }
1262
1263 val = (*evalfun) (val);
f38952fe 1264
078e7b4a
JB
1265 if (printflag)
1266 {
1267 Vvalues = Fcons (val, Vvalues);
1268 if (EQ (Vstandard_output, Qt))
1269 Fprin1 (val, Qnil);
1270 else
1271 Fprint (val, Qnil);
1272 }
1273 }
1274
ae321d28 1275 build_load_history (stream, sourcename);
ae321d28
RS
1276 UNGCPRO;
1277
078e7b4a
JB
1278 unbind_to (count, Qnil);
1279}
1280
1076254d 1281DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
94b304d7
RS
1282 "Execute the current buffer as Lisp code.\n\
1283Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1284BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1285PRINTFLAG controls printing of output:\n\
228d4b1c
JA
1286nil means discard it; anything else is stream for print.\n\
1287\n\
13febd85
RS
1288If the optional third argument FILENAME is non-nil,\n\
1289it specifies the file name to use for `load-history'.\n\
1076254d
RS
1290The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
1291for this invocation.\n\
1292\n\
1293The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
1294`print' and related functions should work normally even if PRINTFLAG is nil.\n\
13febd85 1295\n\
d331bcad 1296This function preserves the position of point.")
1076254d
RS
1297 (buffer, printflag, filename, unibyte, do_allow_print)
1298 Lisp_Object buffer, printflag, filename, unibyte, do_allow_print;
228d4b1c
JA
1299{
1300 int count = specpdl_ptr - specpdl;
1301 Lisp_Object tem, buf;
1302
9391b698 1303 if (NILP (buffer))
228d4b1c
JA
1304 buf = Fcurrent_buffer ();
1305 else
9391b698 1306 buf = Fget_buffer (buffer);
dfdb645c 1307 if (NILP (buf))
13febd85 1308 error ("No such buffer");
228d4b1c 1309
1076254d 1310 if (NILP (printflag) && NILP (do_allow_print))
228d4b1c
JA
1311 tem = Qsymbolp;
1312 else
1313 tem = printflag;
13febd85
RS
1314
1315 if (NILP (filename))
1316 filename = XBUFFER (buf)->filename;
1317
228d4b1c
JA
1318 specbind (Qstandard_output, tem);
1319 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1320 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
976350af 1321 readevalloop (buf, 0, filename, Feval, !NILP (printflag), unibyte, Qnil);
cb09ab7a 1322 unbind_to (count, Qnil);
228d4b1c
JA
1323
1324 return Qnil;
1325}
1326
1327#if 0
c23edb78 1328XDEFUN ("eval-current-buffer", Feval_current_buffer, Seval_current_buffer, 0, 1, "",
078e7b4a
JB
1329 "Execute the current buffer as Lisp code.\n\
1330Programs can pass argument PRINTFLAG which controls printing of output:\n\
1331nil means discard it; anything else is stream for print.\n\
1332\n\
1333If there is no error, point does not move. If there is an error,\n\
1334point remains at the end of the last character read from the buffer.")
1335 (printflag)
1336 Lisp_Object printflag;
1337{
1338 int count = specpdl_ptr - specpdl;
ae321d28
RS
1339 Lisp_Object tem, cbuf;
1340
1341 cbuf = Fcurrent_buffer ()
078e7b4a 1342
265a9e55 1343 if (NILP (printflag))
078e7b4a
JB
1344 tem = Qsymbolp;
1345 else
1346 tem = printflag;
1347 specbind (Qstandard_output, tem);
1348 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1349 SET_PT (BEGV);
94e554db 1350 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
976350af 1351 !NILP (printflag), Qnil, Qnil);
078e7b4a
JB
1352 return unbind_to (count, Qnil);
1353}
228d4b1c 1354#endif
078e7b4a 1355
976350af 1356DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
078e7b4a
JB
1357 "Execute the region as Lisp code.\n\
1358When called from programs, expects two arguments,\n\
1359giving starting and ending indices in the current buffer\n\
1360of the text to be executed.\n\
1361Programs can pass third argument PRINTFLAG which controls output:\n\
1362nil means discard it; anything else is stream for printing it.\n\
976350af
RS
1363Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1364instead of `read' to read each expression. It gets one argument\n\
1365which is the input stream for reading characters.\n\
078e7b4a 1366\n\
83f0c0c7 1367This function does not move point.")
976350af
RS
1368 (start, end, printflag, read_function)
1369 Lisp_Object start, end, printflag, read_function;
078e7b4a
JB
1370{
1371 int count = specpdl_ptr - specpdl;
ae321d28
RS
1372 Lisp_Object tem, cbuf;
1373
1374 cbuf = Fcurrent_buffer ();
078e7b4a 1375
265a9e55 1376 if (NILP (printflag))
078e7b4a
JB
1377 tem = Qsymbolp;
1378 else
1379 tem = printflag;
1380 specbind (Qstandard_output, tem);
1381
265a9e55 1382 if (NILP (printflag))
078e7b4a
JB
1383 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1384 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1385
9391b698
EN
1386 /* This both uses start and checks its type. */
1387 Fgoto_char (start);
1388 Fnarrow_to_region (make_number (BEGV), end);
94e554db 1389 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
976350af 1390 !NILP (printflag), Qnil, read_function);
078e7b4a
JB
1391
1392 return unbind_to (count, Qnil);
1393}
1394
078e7b4a
JB
1395\f
1396DEFUN ("read", Fread, Sread, 0, 1, 0,
1397 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1398If STREAM is nil, use the value of `standard-input' (which see).\n\
1399STREAM or the value of `standard-input' may be:\n\
1400 a buffer (read from point and advance it)\n\
1401 a marker (read from where it points and advance it)\n\
1402 a function (call it with no arguments for each character,\n\
1403 call it with a char as argument to push a char back)\n\
1404 a string (takes text from string, starting at the beginning)\n\
dcd46557
DL
1405 t (read text line using minibuffer and use it, or read from\n\
1406 standard input in batch mode).")
5be02dff
KH
1407 (stream)
1408 Lisp_Object stream;
078e7b4a
JB
1409{
1410 extern Lisp_Object Fread_minibuffer ();
1411
5be02dff
KH
1412 if (NILP (stream))
1413 stream = Vstandard_input;
1414 if (EQ (stream, Qt))
1415 stream = Qread_char;
078e7b4a 1416
00a9a935 1417 readchar_backlog = -1;
17634846 1418 new_backquote_flag = 0;
4ad679f9 1419 read_objects = Qnil;
17634846 1420
5be02dff 1421 if (EQ (stream, Qread_char))
078e7b4a 1422 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
078e7b4a 1423
5be02dff
KH
1424 if (STRINGP (stream))
1425 return Fcar (Fread_from_string (stream, Qnil, Qnil));
078e7b4a 1426
5be02dff 1427 return read0 (stream);
078e7b4a
JB
1428}
1429
1430DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
1431 "Read one Lisp expression which is represented as text by STRING.\n\
1432Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1433START and END optionally delimit a substring of STRING from which to read;\n\
1434 they default to 0 and (length STRING) respectively.")
1435 (string, start, end)
1436 Lisp_Object string, start, end;
1437{
1438 int startval, endval;
1439 Lisp_Object tem;
1440
1441 CHECK_STRING (string,0);
1442
265a9e55 1443 if (NILP (end))
bed23cb2 1444 endval = XSTRING (string)->size;
078e7b4a 1445 else
e28552a4
RS
1446 {
1447 CHECK_NUMBER (end, 2);
8028e0ed 1448 endval = XINT (end);
bed23cb2 1449 if (endval < 0 || endval > XSTRING (string)->size)
078e7b4a
JB
1450 args_out_of_range (string, end);
1451 }
1452
265a9e55 1453 if (NILP (start))
078e7b4a
JB
1454 startval = 0;
1455 else
e28552a4
RS
1456 {
1457 CHECK_NUMBER (start, 1);
8028e0ed 1458 startval = XINT (start);
078e7b4a
JB
1459 if (startval < 0 || startval > endval)
1460 args_out_of_range (string, start);
1461 }
1462
1463 read_from_string_index = startval;
bed23cb2 1464 read_from_string_index_byte = string_char_to_byte (string, startval);
078e7b4a
JB
1465 read_from_string_limit = endval;
1466
17634846 1467 new_backquote_flag = 0;
4ad679f9 1468 read_objects = Qnil;
17634846 1469
078e7b4a 1470 tem = read0 (string);
bed23cb2 1471 return Fcons (tem, make_number (read_from_string_index));
078e7b4a
JB
1472}
1473\f
6428369f
KH
1474/* Use this for recursive reads, in contexts where internal tokens
1475 are not allowed. */
e28552a4 1476
078e7b4a
JB
1477static Lisp_Object
1478read0 (readcharfun)
1479 Lisp_Object readcharfun;
1480{
1481 register Lisp_Object val;
e28552a4 1482 int c;
078e7b4a 1483
17634846 1484 val = read1 (readcharfun, &c, 0);
6428369f 1485 if (c)
93d75e4c
RS
1486 Fsignal (Qinvalid_read_syntax, Fcons (Fmake_string (make_number (1),
1487 make_number (c)),
e28552a4 1488 Qnil));
078e7b4a
JB
1489
1490 return val;
1491}
1492\f
1493static int read_buffer_size;
1494static char *read_buffer;
1495
fe0e03f3
KH
1496/* Read multibyte form and return it as a character. C is a first
1497 byte of multibyte form, and rest of them are read from
1498 READCHARFUN. */
6f7f43d5 1499
fe0e03f3
KH
1500static int
1501read_multibyte (c, readcharfun)
1502 register int c;
1503 Lisp_Object readcharfun;
1504{
1505 /* We need the actual character code of this multibyte
1506 characters. */
449fea39 1507 unsigned char str[MAX_MULTIBYTE_LENGTH];
fe0e03f3
KH
1508 int len = 0;
1509
1510 str[len++] = c;
1511 while ((c = READCHAR) >= 0xA0
449fea39 1512 && len < MAX_MULTIBYTE_LENGTH)
fe0e03f3
KH
1513 str[len++] = c;
1514 UNREAD (c);
1515 return STRING_CHAR (str, len);
1516}
1517
6f7f43d5
RS
1518/* Read a \-escape sequence, assuming we already read the `\'. */
1519
078e7b4a 1520static int
e7fc914b 1521read_escape (readcharfun, stringp)
078e7b4a 1522 Lisp_Object readcharfun;
e7fc914b 1523 int stringp;
078e7b4a
JB
1524{
1525 register int c = READCHAR;
1526 switch (c)
1527 {
f3849f25
RS
1528 case -1:
1529 error ("End of file");
1530
078e7b4a 1531 case 'a':
265a9e55 1532 return '\007';
078e7b4a
JB
1533 case 'b':
1534 return '\b';
f405a585
RS
1535 case 'd':
1536 return 0177;
078e7b4a
JB
1537 case 'e':
1538 return 033;
1539 case 'f':
1540 return '\f';
1541 case 'n':
1542 return '\n';
1543 case 'r':
1544 return '\r';
1545 case 't':
1546 return '\t';
1547 case 'v':
1548 return '\v';
1549 case '\n':
1550 return -1;
e28552a4 1551 case ' ':
e7fc914b
KH
1552 if (stringp)
1553 return -1;
1554 return ' ';
078e7b4a
JB
1555
1556 case 'M':
1557 c = READCHAR;
1558 if (c != '-')
1559 error ("Invalid escape character syntax");
1560 c = READCHAR;
1561 if (c == '\\')
e7fc914b 1562 c = read_escape (readcharfun, 0);
7bd279cd 1563 return c | meta_modifier;
f405a585
RS
1564
1565 case 'S':
1566 c = READCHAR;
1567 if (c != '-')
1568 error ("Invalid escape character syntax");
1569 c = READCHAR;
1570 if (c == '\\')
e7fc914b 1571 c = read_escape (readcharfun, 0);
7bd279cd
RS
1572 return c | shift_modifier;
1573
1574 case 'H':
1575 c = READCHAR;
1576 if (c != '-')
1577 error ("Invalid escape character syntax");
1578 c = READCHAR;
1579 if (c == '\\')
e7fc914b 1580 c = read_escape (readcharfun, 0);
7bd279cd
RS
1581 return c | hyper_modifier;
1582
1583 case 'A':
1584 c = READCHAR;
1585 if (c != '-')
1586 error ("Invalid escape character syntax");
1587 c = READCHAR;
1588 if (c == '\\')
e7fc914b 1589 c = read_escape (readcharfun, 0);
7bd279cd
RS
1590 return c | alt_modifier;
1591
1592 case 's':
1593 c = READCHAR;
1594 if (c != '-')
1595 error ("Invalid escape character syntax");
1596 c = READCHAR;
1597 if (c == '\\')
e7fc914b 1598 c = read_escape (readcharfun, 0);
7bd279cd 1599 return c | super_modifier;
078e7b4a
JB
1600
1601 case 'C':
1602 c = READCHAR;
1603 if (c != '-')
1604 error ("Invalid escape character syntax");
1605 case '^':
1606 c = READCHAR;
1607 if (c == '\\')
e7fc914b 1608 c = read_escape (readcharfun, 0);
164d590d
KH
1609 if ((c & ~CHAR_MODIFIER_MASK) == '?')
1610 return 0177 | (c & CHAR_MODIFIER_MASK);
1611 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
1612 return c | ctrl_modifier;
f405a585
RS
1613 /* ASCII control chars are made from letters (both cases),
1614 as well as the non-letters within 0100...0137. */
1615 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
1616 return (c & (037 | ~0177));
1617 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
1618 return (c & (037 | ~0177));
078e7b4a 1619 else
7bd279cd 1620 return c | ctrl_modifier;
078e7b4a
JB
1621
1622 case '0':
1623 case '1':
1624 case '2':
1625 case '3':
1626 case '4':
1627 case '5':
1628 case '6':
1629 case '7':
1630 /* An octal escape, as in ANSI C. */
1631 {
1632 register int i = c - '0';
1633 register int count = 0;
1634 while (++count < 3)
1635 {
1636 if ((c = READCHAR) >= '0' && c <= '7')
1637 {
1638 i *= 8;
1639 i += c - '0';
1640 }
1641 else
1642 {
1643 UNREAD (c);
1644 break;
1645 }
1646 }
1647 return i;
1648 }
1649
1650 case 'x':
1651 /* A hex escape, as in ANSI C. */
1652 {
1653 int i = 0;
1654 while (1)
1655 {
1656 c = READCHAR;
1657 if (c >= '0' && c <= '9')
1658 {
1659 i *= 16;
1660 i += c - '0';
1661 }
1662 else if ((c >= 'a' && c <= 'f')
1663 || (c >= 'A' && c <= 'F'))
1664 {
1665 i *= 16;
1666 if (c >= 'a' && c <= 'f')
1667 i += c - 'a' + 10;
1668 else
1669 i += c - 'A' + 10;
1670 }
1671 else
1672 {
1673 UNREAD (c);
1674 break;
1675 }
1676 }
1677 return i;
1678 }
1679
1680 default:
fe0e03f3
KH
1681 if (BASE_LEADING_CODE_P (c))
1682 c = read_multibyte (c, readcharfun);
078e7b4a
JB
1683 return c;
1684 }
1685}
1686
bf5d1a17
GM
1687
1688/* Read an integer in radix RADIX using READCHARFUN to read
1689 characters. RADIX must be in the interval [2..36]; if it isn't, a
1690 read error is signaled . Value is the integer read. Signals an
1691 error if encountering invalid read syntax or if RADIX is out of
1692 range. */
1693
1694static Lisp_Object
1695read_integer (readcharfun, radix)
1696 Lisp_Object readcharfun;
1697 int radix;
1698{
5e37dc22
GM
1699 int ndigits = 0, invalid_p, c, sign = 0;
1700 EMACS_INT number = 0;
bf5d1a17
GM
1701
1702 if (radix < 2 || radix > 36)
1703 invalid_p = 1;
1704 else
1705 {
1706 number = ndigits = invalid_p = 0;
1707 sign = 1;
1708
1709 c = READCHAR;
1710 if (c == '-')
1711 {
1712 c = READCHAR;
1713 sign = -1;
1714 }
1715 else if (c == '+')
1716 c = READCHAR;
1717
1718 while (c >= 0)
1719 {
1720 int digit;
1721
1722 if (c >= '0' && c <= '9')
1723 digit = c - '0';
1724 else if (c >= 'a' && c <= 'z')
1725 digit = c - 'a' + 10;
1726 else if (c >= 'A' && c <= 'Z')
1727 digit = c - 'A' + 10;
1728 else
b632fa48
GM
1729 {
1730 UNREAD (c);
1731 break;
1732 }
bf5d1a17
GM
1733
1734 if (digit < 0 || digit >= radix)
1735 invalid_p = 1;
1736
1737 number = radix * number + digit;
1738 ++ndigits;
1739 c = READCHAR;
1740 }
1741 }
1742
1743 if (ndigits == 0 || invalid_p)
1744 {
1745 char buf[50];
1746 sprintf (buf, "integer, radix %d", radix);
1747 Fsignal (Qinvalid_read_syntax, Fcons (build_string (buf), Qnil));
1748 }
1749
1750 return make_number (sign * number);
1751}
1752
1753
6428369f
KH
1754/* If the next token is ')' or ']' or '.', we store that character
1755 in *PCH and the return value is not interesting. Else, we store
17634846
RS
1756 zero in *PCH and we read and return one lisp object.
1757
1758 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1759
078e7b4a 1760static Lisp_Object
17634846 1761read1 (readcharfun, pch, first_in_list)
078e7b4a 1762 register Lisp_Object readcharfun;
e28552a4 1763 int *pch;
17634846 1764 int first_in_list;
078e7b4a
JB
1765{
1766 register int c;
4ad679f9
EN
1767 int uninterned_symbol = 0;
1768
6428369f 1769 *pch = 0;
078e7b4a
JB
1770
1771 retry:
1772
1773 c = READCHAR;
9c97398c
GM
1774 if (c < 0)
1775 end_of_file_error ();
078e7b4a
JB
1776
1777 switch (c)
1778 {
1779 case '(':
1780 return read_list (0, readcharfun);
1781
1782 case '[':
c15cfd1f 1783 return read_vector (readcharfun, 0);
078e7b4a
JB
1784
1785 case ')':
1786 case ']':
078e7b4a 1787 {
6428369f
KH
1788 *pch = c;
1789 return Qnil;
078e7b4a
JB
1790 }
1791
1792 case '#':
200f684e 1793 c = READCHAR;
c2390933
RS
1794 if (c == '^')
1795 {
1796 c = READCHAR;
1797 if (c == '[')
1798 {
1799 Lisp_Object tmp;
c15cfd1f 1800 tmp = read_vector (readcharfun, 0);
c2390933
RS
1801 if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS
1802 || XVECTOR (tmp)->size > CHAR_TABLE_STANDARD_SLOTS + 10)
1803 error ("Invalid size char-table");
1804 XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp));
3701b5de 1805 XCHAR_TABLE (tmp)->top = Qt;
c2390933
RS
1806 return tmp;
1807 }
3701b5de
KH
1808 else if (c == '^')
1809 {
1810 c = READCHAR;
1811 if (c == '[')
1812 {
1813 Lisp_Object tmp;
c15cfd1f 1814 tmp = read_vector (readcharfun, 0);
3701b5de
KH
1815 if (XVECTOR (tmp)->size != SUB_CHAR_TABLE_STANDARD_SLOTS)
1816 error ("Invalid size char-table");
1817 XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp));
1818 XCHAR_TABLE (tmp)->top = Qnil;
1819 return tmp;
1820 }
1821 Fsignal (Qinvalid_read_syntax,
1822 Fcons (make_string ("#^^", 3), Qnil));
1823 }
c2390933
RS
1824 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#^", 2), Qnil));
1825 }
1826 if (c == '&')
1827 {
1828 Lisp_Object length;
1829 length = read1 (readcharfun, pch, first_in_list);
1830 c = READCHAR;
1831 if (c == '"')
1832 {
1833 Lisp_Object tmp, val;
90ed3ec5 1834 int size_in_chars = ((XFASTINT (length) + BITS_PER_CHAR - 1)
68be917d 1835 / BITS_PER_CHAR);
c2390933
RS
1836
1837 UNREAD (c);
1838 tmp = read1 (readcharfun, pch, first_in_list);
90ed3ec5
RS
1839 if (size_in_chars != XSTRING (tmp)->size
1840 /* We used to print 1 char too many
1841 when the number of bits was a multiple of 8.
1842 Accept such input in case it came from an old version. */
1843 && ! (XFASTINT (length)
1844 == (XSTRING (tmp)->size - 1) * BITS_PER_CHAR))
c2390933 1845 Fsignal (Qinvalid_read_syntax,
ec3bbd7d 1846 Fcons (make_string ("#&...", 5), Qnil));
c2390933
RS
1847
1848 val = Fmake_bool_vector (length, Qnil);
1849 bcopy (XSTRING (tmp)->data, XBOOL_VECTOR (val)->data,
1850 size_in_chars);
67d3b149
EZ
1851 /* Clear the extraneous bits in the last byte. */
1852 if (XINT (length) != size_in_chars * BITS_PER_CHAR)
1853 XBOOL_VECTOR (val)->data[size_in_chars - 1]
1854 &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1;
c2390933
RS
1855 return val;
1856 }
ec3bbd7d 1857 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#&...", 5),
039dc30b 1858 Qnil));
c2390933 1859 }
200f684e
RS
1860 if (c == '[')
1861 {
1862 /* Accept compiled functions at read-time so that we don't have to
1863 build them using function calls. */
748ef62f 1864 Lisp_Object tmp;
c15cfd1f 1865 tmp = read_vector (readcharfun, 1);
748ef62f
RS
1866 return Fmake_byte_code (XVECTOR (tmp)->size,
1867 XVECTOR (tmp)->contents);
200f684e 1868 }
748ef62f
RS
1869 if (c == '(')
1870 {
1871 Lisp_Object tmp;
1872 struct gcpro gcpro1;
e28552a4 1873 int ch;
748ef62f
RS
1874
1875 /* Read the string itself. */
17634846 1876 tmp = read1 (readcharfun, &ch, 0);
6428369f 1877 if (ch != 0 || !STRINGP (tmp))
748ef62f
RS
1878 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
1879 GCPRO1 (tmp);
1880 /* Read the intervals and their properties. */
1881 while (1)
1882 {
1883 Lisp_Object beg, end, plist;
1884
17634846 1885 beg = read1 (readcharfun, &ch, 0);
7ee3bd7b 1886 end = plist = Qnil;
6428369f
KH
1887 if (ch == ')')
1888 break;
1889 if (ch == 0)
17634846 1890 end = read1 (readcharfun, &ch, 0);
6428369f 1891 if (ch == 0)
17634846 1892 plist = read1 (readcharfun, &ch, 0);
6428369f 1893 if (ch)
748ef62f 1894 Fsignal (Qinvalid_read_syntax,
6428369f
KH
1895 Fcons (build_string ("invalid string property list"),
1896 Qnil));
748ef62f
RS
1897 Fset_text_properties (beg, end, plist, tmp);
1898 }
1899 UNGCPRO;
1900 return tmp;
1901 }
339ee979 1902
20ea2964
RS
1903 /* #@NUMBER is used to skip NUMBER following characters.
1904 That's used in .elc files to skip over doc strings
1905 and function definitions. */
1906 if (c == '@')
1907 {
1908 int i, nskip = 0;
1909
1910 /* Read a decimal integer. */
1911 while ((c = READCHAR) >= 0
1912 && c >= '0' && c <= '9')
1913 {
1914 nskip *= 10;
1915 nskip += c - '0';
1916 }
1917 if (c >= 0)
1918 UNREAD (c);
1919
b2a30870
RS
1920 if (load_force_doc_strings && EQ (readcharfun, Qget_file_char))
1921 {
1922 /* If we are supposed to force doc strings into core right now,
1923 record the last string that we skipped,
1924 and record where in the file it comes from. */
c15cfd1f
RS
1925
1926 /* But first exchange saved_doc_string
1927 with prev_saved_doc_string, so we save two strings. */
1928 {
1929 char *temp = saved_doc_string;
1930 int temp_size = saved_doc_string_size;
68c45bf0 1931 file_offset temp_pos = saved_doc_string_position;
c15cfd1f
RS
1932 int temp_len = saved_doc_string_length;
1933
1934 saved_doc_string = prev_saved_doc_string;
1935 saved_doc_string_size = prev_saved_doc_string_size;
1936 saved_doc_string_position = prev_saved_doc_string_position;
1937 saved_doc_string_length = prev_saved_doc_string_length;
1938
1939 prev_saved_doc_string = temp;
1940 prev_saved_doc_string_size = temp_size;
1941 prev_saved_doc_string_position = temp_pos;
1942 prev_saved_doc_string_length = temp_len;
1943 }
1944
b2a30870
RS
1945 if (saved_doc_string_size == 0)
1946 {
1947 saved_doc_string_size = nskip + 100;
11938f10 1948 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
b2a30870
RS
1949 }
1950 if (nskip > saved_doc_string_size)
1951 {
1952 saved_doc_string_size = nskip + 100;
11938f10
KH
1953 saved_doc_string = (char *) xrealloc (saved_doc_string,
1954 saved_doc_string_size);
b2a30870
RS
1955 }
1956
68c45bf0 1957 saved_doc_string_position = file_tell (instream);
b2a30870
RS
1958
1959 /* Copy that many characters into saved_doc_string. */
1960 for (i = 0; i < nskip && c >= 0; i++)
1961 saved_doc_string[i] = c = READCHAR;
1962
1963 saved_doc_string_length = i;
1964 }
1965 else
b2a30870
RS
1966 {
1967 /* Skip that many characters. */
1968 for (i = 0; i < nskip && c >= 0; i++)
1969 c = READCHAR;
1970 }
d49f0c1a 1971
20ea2964
RS
1972 goto retry;
1973 }
1974 if (c == '$')
1975 return Vload_file_name;
2b6cae0c
RS
1976 if (c == '\'')
1977 return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
4ad679f9
EN
1978 /* #:foo is the uninterned symbol named foo. */
1979 if (c == ':')
1980 {
1981 uninterned_symbol = 1;
1982 c = READCHAR;
1983 goto default_label;
1984 }
1985 /* Reader forms that can reuse previously read objects. */
1986 if (c >= '0' && c <= '9')
1987 {
1988 int n = 0;
1989 Lisp_Object tem;
2b6cae0c 1990
4ad679f9
EN
1991 /* Read a non-negative integer. */
1992 while (c >= '0' && c <= '9')
1993 {
1994 n *= 10;
1995 n += c - '0';
1996 c = READCHAR;
1997 }
1998 /* #n=object returns object, but associates it with n for #n#. */
1999 if (c == '=')
2000 {
9e062b6c
RS
2001 /* Make a placeholder for #n# to use temporarily */
2002 Lisp_Object placeholder;
2003 Lisp_Object cell;
2004
2005 placeholder = Fcons(Qnil, Qnil);
2006 cell = Fcons (make_number (n), placeholder);
2007 read_objects = Fcons (cell, read_objects);
2008
2009 /* Read the object itself. */
4ad679f9 2010 tem = read0 (readcharfun);
9e062b6c
RS
2011
2012 /* Now put it everywhere the placeholder was... */
2013 substitute_object_in_subtree (tem, placeholder);
2014
2015 /* ...and #n# will use the real value from now on. */
2016 Fsetcdr (cell, tem);
2017
4ad679f9
EN
2018 return tem;
2019 }
2020 /* #n# returns a previously read object. */
2021 if (c == '#')
2022 {
2023 tem = Fassq (make_number (n), read_objects);
2024 if (CONSP (tem))
2025 return XCDR (tem);
2026 /* Fall through to error message. */
2027 }
bf5d1a17
GM
2028 else if (c == 'r' || c == 'R')
2029 return read_integer (readcharfun, n);
2030
4ad679f9
EN
2031 /* Fall through to error message. */
2032 }
bf5d1a17
GM
2033 else if (c == 'x' || c == 'X')
2034 return read_integer (readcharfun, 16);
2035 else if (c == 'o' || c == 'O')
2036 return read_integer (readcharfun, 8);
2037 else if (c == 'b' || c == 'B')
2038 return read_integer (readcharfun, 2);
20ea2964 2039
200f684e 2040 UNREAD (c);
748ef62f 2041 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
078e7b4a
JB
2042
2043 case ';':
2044 while ((c = READCHAR) >= 0 && c != '\n');
2045 goto retry;
2046
2047 case '\'':
2048 {
2049 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
2050 }
2051
17634846
RS
2052 case '`':
2053 if (first_in_list)
2054 goto default_label;
2055 else
2056 {
2057 Lisp_Object value;
2058
2059 new_backquote_flag = 1;
2060 value = read0 (readcharfun);
2061 new_backquote_flag = 0;
2062
2063 return Fcons (Qbackquote, Fcons (value, Qnil));
2064 }
2065
2066 case ',':
2067 if (new_backquote_flag)
2068 {
2069 Lisp_Object comma_type = Qnil;
2070 Lisp_Object value;
2071 int ch = READCHAR;
2072
2073 if (ch == '@')
2074 comma_type = Qcomma_at;
2075 else if (ch == '.')
2076 comma_type = Qcomma_dot;
2077 else
2078 {
2079 if (ch >= 0) UNREAD (ch);
2080 comma_type = Qcomma;
2081 }
2082
2083 new_backquote_flag = 0;
2084 value = read0 (readcharfun);
2085 new_backquote_flag = 1;
2086 return Fcons (comma_type, Fcons (value, Qnil));
2087 }
2088 else
2089 goto default_label;
2090
078e7b4a
JB
2091 case '?':
2092 {
078e7b4a 2093 c = READCHAR;
9c97398c
GM
2094 if (c < 0)
2095 end_of_file_error ();
078e7b4a
JB
2096
2097 if (c == '\\')
e7fc914b 2098 c = read_escape (readcharfun, 0);
fe0e03f3
KH
2099 else if (BASE_LEADING_CODE_P (c))
2100 c = read_multibyte (c, readcharfun);
078e7b4a 2101
6f7f43d5 2102 return make_number (c);
078e7b4a
JB
2103 }
2104
00a9a935 2105 case '"':
078e7b4a
JB
2106 {
2107 register char *p = read_buffer;
2108 register char *end = read_buffer + read_buffer_size;
2109 register int c;
e7fc914b
KH
2110 /* Nonzero if we saw an escape sequence specifying
2111 a multibyte character. */
2112 int force_multibyte = 0;
2113 /* Nonzero if we saw an escape sequence specifying
2114 a single-byte character. */
2115 int force_singlebyte = 0;
078e7b4a 2116 int cancel = 0;
e7fc914b 2117 int nchars;
078e7b4a
JB
2118
2119 while ((c = READCHAR) >= 0
2120 && c != '\"')
2121 {
449fea39 2122 if (end - p < MAX_MULTIBYTE_LENGTH)
078e7b4a 2123 {
5d65df0d
GM
2124 int offset = p - read_buffer;
2125 read_buffer = (char *) xrealloc (read_buffer,
2126 read_buffer_size *= 2);
2127 p = read_buffer + offset;
078e7b4a
JB
2128 end = read_buffer + read_buffer_size;
2129 }
bed23cb2 2130
078e7b4a 2131 if (c == '\\')
03e88613 2132 {
e7fc914b 2133 c = read_escape (readcharfun, 1);
bed23cb2
RS
2134
2135 /* C is -1 if \ newline has just been seen */
2136 if (c == -1)
03e88613 2137 {
bed23cb2
RS
2138 if (p == read_buffer)
2139 cancel = 1;
03e88613
RS
2140 continue;
2141 }
bed23cb2 2142
94e554db
RS
2143 /* If an escape specifies a non-ASCII single-byte character,
2144 this must be a unibyte string. */
164d590d
KH
2145 if (SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))
2146 && ! ASCII_BYTE_P ((c & ~CHAR_MODIFIER_MASK)))
e7fc914b 2147 force_singlebyte = 1;
03e88613 2148 }
6f7f43d5 2149
164d590d 2150 if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
078e7b4a 2151 {
164d590d
KH
2152 /* Any modifiers for a multibyte character are invalid. */
2153 if (c & CHAR_MODIFIER_MASK)
2154 error ("Invalid modifier in string");
449fea39
KH
2155 p += CHAR_STRING (c, p);
2156 force_multibyte = 1;
078e7b4a
JB
2157 }
2158 else
f943104a 2159 {
988c2f83
RS
2160 /* Allow `\C- ' and `\C-?'. */
2161 if (c == (CHAR_CTL | ' '))
2162 c = 0;
2163 else if (c == (CHAR_CTL | '?'))
2164 c = 127;
2165
164d590d
KH
2166 if (c & CHAR_SHIFT)
2167 {
2168 /* Shift modifier is valid only with [A-Za-z]. */
2169 if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
2170 c &= ~CHAR_SHIFT;
2171 else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
2172 c = (c & ~CHAR_SHIFT) - ('a' - 'A');
2173 }
2174
f943104a
KH
2175 if (c & CHAR_META)
2176 /* Move the meta bit to the right place for a string. */
2177 c = (c & ~CHAR_META) | 0x80;
2178 if (c & ~0xff)
2179 error ("Invalid modifier in string");
2180 *p++ = c;
2181 }
078e7b4a 2182 }
6f7f43d5 2183 if (c < 0)
9c97398c 2184 end_of_file_error ();
078e7b4a
JB
2185
2186 /* If purifying, and string starts with \ newline,
2187 return zero instead. This is for doc strings
08564963 2188 that we are really going to find in etc/DOC.nn.nn */
265a9e55 2189 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
078e7b4a
JB
2190 return make_number (0);
2191
6f46329a 2192 if (force_multibyte)
f0354c03
KH
2193 p = read_buffer + str_as_multibyte (read_buffer, end - read_buffer,
2194 p - read_buffer, &nchars);
6f46329a
RS
2195 else if (force_singlebyte)
2196 nchars = p - read_buffer;
94e554db
RS
2197 else if (load_convert_to_unibyte)
2198 {
2199 Lisp_Object string;
f0354c03
KH
2200 p = read_buffer + str_as_multibyte (read_buffer, end - read_buffer,
2201 p - read_buffer, &nchars);
94e554db
RS
2202 if (p - read_buffer != nchars)
2203 {
2204 string = make_multibyte_string (read_buffer, nchars,
2205 p - read_buffer);
2206 return Fstring_make_unibyte (string);
2207 }
2208 }
8db9dc66
RS
2209 else if (EQ (readcharfun, Qget_file_char)
2210 || EQ (readcharfun, Qlambda))
f0354c03
KH
2211 /* Nowadays, reading directly from a file is used only for
2212 compiled Emacs Lisp files, and those always use the
2213 Emacs internal encoding. Meanwhile, Qlambda is used
2214 for reading dynamic byte code (compiled with
2215 byte-compile-dynamic = t). */
2216 p = read_buffer + str_as_multibyte (read_buffer, end - read_buffer,
2217 p - read_buffer, &nchars);
e28552a4 2218 else
bed23cb2
RS
2219 /* In all other cases, if we read these bytes as
2220 separate characters, treat them as separate characters now. */
e7fc914b
KH
2221 nchars = p - read_buffer;
2222
2223 if (read_pure)
491f16a2
RS
2224 return make_pure_string (read_buffer, nchars, p - read_buffer,
2225 (force_multibyte
2226 || (p - read_buffer != nchars)));
2227 return make_specified_string (read_buffer, nchars, p - read_buffer,
2228 (force_multibyte
2229 || (p - read_buffer != nchars)));
078e7b4a
JB
2230 }
2231
109d300c
JB
2232 case '.':
2233 {
109d300c
JB
2234 int next_char = READCHAR;
2235 UNREAD (next_char);
2236
035eec48
GM
2237 if (next_char <= 040
2238 || index ("\"'`,(", next_char))
109d300c 2239 {
6428369f
KH
2240 *pch = c;
2241 return Qnil;
109d300c
JB
2242 }
2243
2244 /* Otherwise, we fall through! Note that the atom-reading loop
2245 below will now loop at least once, assuring that we will not
2246 try to UNREAD two characters in a row. */
2247 }
078e7b4a 2248 default:
17634846 2249 default_label:
078e7b4a
JB
2250 if (c <= 040) goto retry;
2251 {
38404229 2252 char *p = read_buffer;
481c6336 2253 int quoted = 0;
078e7b4a
JB
2254
2255 {
38404229 2256 char *end = read_buffer + read_buffer_size;
078e7b4a 2257
6f7f43d5 2258 while (c > 040
38404229 2259 && !(c == '\"' || c == '\'' || c == ';'
6f7f43d5 2260 || c == '(' || c == ')'
38404229 2261 || c == '[' || c == ']' || c == '#'))
078e7b4a 2262 {
449fea39 2263 if (end - p < MAX_MULTIBYTE_LENGTH)
078e7b4a 2264 {
5d65df0d
GM
2265 int offset = p - read_buffer;
2266 read_buffer = (char *) xrealloc (read_buffer,
2267 read_buffer_size *= 2);
2268 p = read_buffer + offset;
078e7b4a
JB
2269 end = read_buffer + read_buffer_size;
2270 }
38404229 2271
078e7b4a 2272 if (c == '\\')
481c6336
RS
2273 {
2274 c = READCHAR;
4ab11c09
GM
2275 if (c == -1)
2276 end_of_file_error ();
481c6336
RS
2277 quoted = 1;
2278 }
6f7f43d5 2279
bed23cb2 2280 if (! SINGLE_BYTE_CHAR_P (c))
449fea39 2281 p += CHAR_STRING (c, p);
bed23cb2
RS
2282 else
2283 *p++ = c;
6f7f43d5 2284
078e7b4a
JB
2285 c = READCHAR;
2286 }
2287
2288 if (p == end)
2289 {
5d65df0d
GM
2290 int offset = p - read_buffer;
2291 read_buffer = (char *) xrealloc (read_buffer,
2292 read_buffer_size *= 2);
2293 p = read_buffer + offset;
2294 end = read_buffer + read_buffer_size;
078e7b4a
JB
2295 }
2296 *p = 0;
2297 if (c >= 0)
2298 UNREAD (c);
2299 }
2300
4ad679f9 2301 if (!quoted && !uninterned_symbol)
481c6336
RS
2302 {
2303 register char *p1;
2304 register Lisp_Object val;
2305 p1 = read_buffer;
2306 if (*p1 == '+' || *p1 == '-') p1++;
2307 /* Is it an integer? */
2308 if (p1 != p)
2309 {
2310 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
481c6336
RS
2311 /* Integers can have trailing decimal points. */
2312 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
481c6336
RS
2313 if (p1 == p)
2314 /* It is an integer. */
2315 {
481c6336
RS
2316 if (p1[-1] == '.')
2317 p1[-1] = '\0';
faca07fb
RS
2318 if (sizeof (int) == sizeof (EMACS_INT))
2319 XSETINT (val, atoi (read_buffer));
2320 else if (sizeof (long) == sizeof (EMACS_INT))
2321 XSETINT (val, atol (read_buffer));
2322 else
2323 abort ();
481c6336
RS
2324 return val;
2325 }
2326 }
481c6336 2327 if (isfloat_string (read_buffer))
eb659c41 2328 {
a8972052
PE
2329 /* Compute NaN and infinities using 0.0 in a variable,
2330 to cope with compilers that think they are smarter
5e24a1f7 2331 than we are. */
3c329963 2332 double zero = 0.0;
a8972052
PE
2333
2334 double value;
2335
2336 /* Negate the value ourselves. This treats 0, NaNs,
2337 and infinity properly on IEEE floating point hosts,
2338 and works around a common bug where atof ("-0.0")
2339 drops the sign. */
2340 int negative = read_buffer[0] == '-';
2341
2342 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
eb659c41 2343 returns 1, is if the input ends in e+INF or e+NaN. */
a8972052 2344 switch (p[-1])
eb659c41 2345 {
a8972052
PE
2346 case 'F':
2347 value = 1.0 / zero;
2348 break;
2349 case 'N':
2350 value = zero / zero;
2351 break;
2352 default:
2353 value = atof (read_buffer + negative);
2354 break;
eb659c41 2355 }
a8972052
PE
2356
2357 return make_float (negative ? - value : value);
eb659c41 2358 }
481c6336 2359 }
078e7b4a 2360
4ad679f9
EN
2361 if (uninterned_symbol)
2362 return make_symbol (read_buffer);
2363 else
2364 return intern (read_buffer);
078e7b4a
JB
2365 }
2366 }
2367}
2368\f
9e062b6c
RS
2369
2370/* List of nodes we've seen during substitute_object_in_subtree. */
2371static Lisp_Object seen_list;
2372
2373static void
2374substitute_object_in_subtree (object, placeholder)
2375 Lisp_Object object;
2376 Lisp_Object placeholder;
2377{
2378 Lisp_Object check_object;
2379
2380 /* We haven't seen any objects when we start. */
2381 seen_list = Qnil;
2382
2383 /* Make all the substitutions. */
2384 check_object
2385 = substitute_object_recurse (object, placeholder, object);
2386
2387 /* Clear seen_list because we're done with it. */
2388 seen_list = Qnil;
2389
2390 /* The returned object here is expected to always eq the
2391 original. */
2392 if (!EQ (check_object, object))
2393 error ("Unexpected mutation error in reader");
2394}
2395
2396/* Feval doesn't get called from here, so no gc protection is needed. */
2397#define SUBSTITUTE(get_val, set_val) \
2398{ \
2399 Lisp_Object old_value = get_val; \
2400 Lisp_Object true_value \
2401 = substitute_object_recurse (object, placeholder,\
2402 old_value); \
2403 \
2404 if (!EQ (old_value, true_value)) \
2405 { \
2406 set_val; \
2407 } \
2408}
2409
2410static Lisp_Object
2411substitute_object_recurse (object, placeholder, subtree)
2412 Lisp_Object object;
2413 Lisp_Object placeholder;
2414 Lisp_Object subtree;
2415{
2416 /* If we find the placeholder, return the target object. */
2417 if (EQ (placeholder, subtree))
2418 return object;
2419
2420 /* If we've been to this node before, don't explore it again. */
2421 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
2422 return subtree;
2423
2424 /* If this node can be the entry point to a cycle, remember that
2425 we've seen it. It can only be such an entry point if it was made
2426 by #n=, which means that we can find it as a value in
2427 read_objects. */
2428 if (!EQ (Qnil, Frassq (subtree, read_objects)))
2429 seen_list = Fcons (subtree, seen_list);
2430
2431 /* Recurse according to subtree's type.
2432 Every branch must return a Lisp_Object. */
2433 switch (XTYPE (subtree))
2434 {
2435 case Lisp_Vectorlike:
2436 {
2437 int i;
7c752c80 2438 int length = XINT (Flength(subtree));
9e062b6c
RS
2439 for (i = 0; i < length; i++)
2440 {
2441 Lisp_Object idx = make_number (i);
2442 SUBSTITUTE (Faref (subtree, idx),
2443 Faset (subtree, idx, true_value));
2444 }
2445 return subtree;
2446 }
2447
2448 case Lisp_Cons:
2449 {
2450 SUBSTITUTE (Fcar_safe (subtree),
2451 Fsetcar (subtree, true_value));
2452 SUBSTITUTE (Fcdr_safe (subtree),
2453 Fsetcdr (subtree, true_value));
2454 return subtree;
2455 }
2456
9e062b6c
RS
2457 case Lisp_String:
2458 {
2459 /* Check for text properties in each interval.
2460 substitute_in_interval contains part of the logic. */
2461
2462 INTERVAL root_interval = XSTRING (subtree)->intervals;
2463 Lisp_Object arg = Fcons (object, placeholder);
2464
2465 traverse_intervals (root_interval, 1, 0,
2466 &substitute_in_interval, arg);
2467
2468 return subtree;
2469 }
9e062b6c
RS
2470
2471 /* Other types don't recurse any further. */
2472 default:
2473 return subtree;
2474 }
2475}
2476
2477/* Helper function for substitute_object_recurse. */
2478static void
2479substitute_in_interval (interval, arg)
2480 INTERVAL interval;
2481 Lisp_Object arg;
2482{
2483 Lisp_Object object = Fcar (arg);
2484 Lisp_Object placeholder = Fcdr (arg);
2485
2486 SUBSTITUTE(interval->plist, interval->plist = true_value);
2487}
2488
2489\f
078e7b4a
JB
2490#define LEAD_INT 1
2491#define DOT_CHAR 2
2492#define TRAIL_INT 4
2493#define E_CHAR 8
2494#define EXP_INT 16
2495
2496int
2497isfloat_string (cp)
2498 register char *cp;
2499{
c1a2f60a 2500 register int state;
078e7b4a 2501
d8578e58
RS
2502 char *start = cp;
2503
078e7b4a
JB
2504 state = 0;
2505 if (*cp == '+' || *cp == '-')
2506 cp++;
2507
075027b1 2508 if (*cp >= '0' && *cp <= '9')
078e7b4a
JB
2509 {
2510 state |= LEAD_INT;
075027b1
RS
2511 while (*cp >= '0' && *cp <= '9')
2512 cp++;
078e7b4a
JB
2513 }
2514 if (*cp == '.')
2515 {
2516 state |= DOT_CHAR;
2517 cp++;
2518 }
075027b1 2519 if (*cp >= '0' && *cp <= '9')
078e7b4a
JB
2520 {
2521 state |= TRAIL_INT;
075027b1 2522 while (*cp >= '0' && *cp <= '9')
078e7b4a
JB
2523 cp++;
2524 }
a35f88bf 2525 if (*cp == 'e' || *cp == 'E')
078e7b4a
JB
2526 {
2527 state |= E_CHAR;
2528 cp++;
e73997a1
RS
2529 if (*cp == '+' || *cp == '-')
2530 cp++;
078e7b4a 2531 }
078e7b4a 2532
075027b1 2533 if (*cp >= '0' && *cp <= '9')
078e7b4a
JB
2534 {
2535 state |= EXP_INT;
075027b1 2536 while (*cp >= '0' && *cp <= '9')
078e7b4a
JB
2537 cp++;
2538 }
d8578e58
RS
2539 else if (cp == start)
2540 ;
eb659c41
RS
2541 else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
2542 {
2543 state |= EXP_INT;
2544 cp += 3;
2545 }
2546 else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
2547 {
2548 state |= EXP_INT;
2549 cp += 3;
2550 }
2551
37579d7c 2552 return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
078e7b4a 2553 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
151bdc83 2554 || state == (DOT_CHAR|TRAIL_INT)
078e7b4a 2555 || state == (LEAD_INT|E_CHAR|EXP_INT)
151bdc83
JB
2556 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
2557 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
078e7b4a 2558}
cc94f3b2 2559
078e7b4a
JB
2560\f
2561static Lisp_Object
c15cfd1f 2562read_vector (readcharfun, bytecodeflag)
078e7b4a 2563 Lisp_Object readcharfun;
c15cfd1f 2564 int bytecodeflag;
078e7b4a
JB
2565{
2566 register int i;
2567 register int size;
2568 register Lisp_Object *ptr;
c15cfd1f 2569 register Lisp_Object tem, item, vector;
078e7b4a
JB
2570 register struct Lisp_Cons *otem;
2571 Lisp_Object len;
2572
2573 tem = read_list (1, readcharfun);
2574 len = Flength (tem);
2575 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
2576
078e7b4a
JB
2577 size = XVECTOR (vector)->size;
2578 ptr = XVECTOR (vector)->contents;
2579 for (i = 0; i < size; i++)
2580 {
c15cfd1f
RS
2581 item = Fcar (tem);
2582 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2583 bytecode object, the docstring containing the bytecode and
2584 constants values must be treated as unibyte and passed to
2585 Fread, to get the actual bytecode string and constants vector. */
2586 if (bytecodeflag && load_force_doc_strings)
2587 {
2588 if (i == COMPILED_BYTECODE)
2589 {
2590 if (!STRINGP (item))
2591 error ("invalid byte code");
2592
2593 /* Delay handling the bytecode slot until we know whether
2594 it is lazily-loaded (we can tell by whether the
2595 constants slot is nil). */
2596 ptr[COMPILED_CONSTANTS] = item;
2597 item = Qnil;
2598 }
2599 else if (i == COMPILED_CONSTANTS)
2600 {
2601 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
2602
2603 if (NILP (item))
2604 {
2605 /* Coerce string to unibyte (like string-as-unibyte,
2606 but without generating extra garbage and
2607 guaranteeing no change in the contents). */
2608 XSTRING (bytestr)->size = STRING_BYTES (XSTRING (bytestr));
2609 SET_STRING_BYTES (XSTRING (bytestr), -1);
2610
2611 item = Fread (bytestr);
2612 if (!CONSP (item))
2613 error ("invalid byte code");
2614
2615 otem = XCONS (item);
c1d497be
KR
2616 bytestr = XCAR (item);
2617 item = XCDR (item);
c15cfd1f
RS
2618 free_cons (otem);
2619 }
2620
2621 /* Now handle the bytecode slot. */
2622 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
2623 }
2624 }
2625 ptr[i] = read_pure ? Fpurecopy (item) : item;
078e7b4a
JB
2626 otem = XCONS (tem);
2627 tem = Fcdr (tem);
2628 free_cons (otem);
2629 }
2630 return vector;
2631}
2632
6f7f43d5
RS
2633/* FLAG = 1 means check for ] to terminate rather than ) and .
2634 FLAG = -1 means check for starting with defun
078e7b4a
JB
2635 and make structure pure. */
2636
2637static Lisp_Object
2638read_list (flag, readcharfun)
2639 int flag;
2640 register Lisp_Object readcharfun;
2641{
2642 /* -1 means check next element for defun,
2643 0 means don't check,
2644 1 means already checked and found defun. */
2645 int defunflag = flag < 0 ? -1 : 0;
2646 Lisp_Object val, tail;
2647 register Lisp_Object elt, tem;
2648 struct gcpro gcpro1, gcpro2;
821d417e 2649 /* 0 is the normal case.
b2a30870
RS
2650 1 means this list is a doc reference; replace it with the number 0.
2651 2 means this list is a doc reference; replace it with the doc string. */
821d417e 2652 int doc_reference = 0;
078e7b4a 2653
17634846
RS
2654 /* Initialize this to 1 if we are reading a list. */
2655 int first_in_list = flag <= 0;
2656
078e7b4a
JB
2657 val = Qnil;
2658 tail = Qnil;
2659
2660 while (1)
2661 {
e28552a4 2662 int ch;
078e7b4a 2663 GCPRO2 (val, tail);
17634846 2664 elt = read1 (readcharfun, &ch, first_in_list);
078e7b4a 2665 UNGCPRO;
20ea2964 2666
17634846
RS
2667 first_in_list = 0;
2668
821d417e 2669 /* While building, if the list starts with #$, treat it specially. */
20ea2964 2670 if (EQ (elt, Vload_file_name)
d49f0c1a 2671 && ! NILP (elt)
821d417e
RS
2672 && !NILP (Vpurify_flag))
2673 {
2674 if (NILP (Vdoc_file_name))
2675 /* We have not yet called Snarf-documentation, so assume
2676 this file is described in the DOC-MM.NN file
2677 and Snarf-documentation will fill in the right value later.
2678 For now, replace the whole list with 0. */
2679 doc_reference = 1;
2680 else
2681 /* We have already called Snarf-documentation, so make a relative
2682 file name for this file, so it can be found properly
2683 in the installed Lisp directory.
2684 We don't use Fexpand_file_name because that would make
2685 the directory absolute now. */
2686 elt = concat2 (build_string ("../lisp/"),
2687 Ffile_name_nondirectory (elt));
2688 }
b2a30870 2689 else if (EQ (elt, Vload_file_name)
d49f0c1a 2690 && ! NILP (elt)
b2a30870
RS
2691 && load_force_doc_strings)
2692 doc_reference = 2;
20ea2964 2693
6428369f 2694 if (ch)
078e7b4a
JB
2695 {
2696 if (flag > 0)
2697 {
6428369f 2698 if (ch == ']')
078e7b4a 2699 return val;
821d417e
RS
2700 Fsignal (Qinvalid_read_syntax,
2701 Fcons (make_string (") or . in a vector", 18), Qnil));
078e7b4a 2702 }
6428369f 2703 if (ch == ')')
078e7b4a 2704 return val;
6428369f 2705 if (ch == '.')
078e7b4a
JB
2706 {
2707 GCPRO2 (val, tail);
265a9e55 2708 if (!NILP (tail))
c1d497be 2709 XCDR (tail) = read0 (readcharfun);
078e7b4a
JB
2710 else
2711 val = read0 (readcharfun);
17634846 2712 read1 (readcharfun, &ch, 0);
078e7b4a 2713 UNGCPRO;
6428369f 2714 if (ch == ')')
821d417e
RS
2715 {
2716 if (doc_reference == 1)
2717 return make_number (0);
b2a30870
RS
2718 if (doc_reference == 2)
2719 {
2720 /* Get a doc string from the file we are loading.
2721 If it's in saved_doc_string, get it from there. */
c1d497be 2722 int pos = XINT (XCDR (val));
c15cfd1f
RS
2723 /* Position is negative for user variables. */
2724 if (pos < 0) pos = -pos;
b2a30870
RS
2725 if (pos >= saved_doc_string_position
2726 && pos < (saved_doc_string_position
2727 + saved_doc_string_length))
2728 {
2729 int start = pos - saved_doc_string_position;
2730 int from, to;
2731
2732 /* Process quoting with ^A,
2733 and find the end of the string,
2734 which is marked with ^_ (037). */
2735 for (from = start, to = start;
2736 saved_doc_string[from] != 037;)
2737 {
2738 int c = saved_doc_string[from++];
2739 if (c == 1)
2740 {
2741 c = saved_doc_string[from++];
2742 if (c == 1)
2743 saved_doc_string[to++] = c;
2744 else if (c == '0')
2745 saved_doc_string[to++] = 0;
2746 else if (c == '_')
2747 saved_doc_string[to++] = 037;
2748 }
2749 else
2750 saved_doc_string[to++] = c;
2751 }
2752
2753 return make_string (saved_doc_string + start,
2754 to - start);
2755 }
c15cfd1f
RS
2756 /* Look in prev_saved_doc_string the same way. */
2757 else if (pos >= prev_saved_doc_string_position
2758 && pos < (prev_saved_doc_string_position
2759 + prev_saved_doc_string_length))
2760 {
2761 int start = pos - prev_saved_doc_string_position;
2762 int from, to;
2763
2764 /* Process quoting with ^A,
2765 and find the end of the string,
2766 which is marked with ^_ (037). */
2767 for (from = start, to = start;
2768 prev_saved_doc_string[from] != 037;)
2769 {
2770 int c = prev_saved_doc_string[from++];
2771 if (c == 1)
2772 {
2773 c = prev_saved_doc_string[from++];
2774 if (c == 1)
2775 prev_saved_doc_string[to++] = c;
2776 else if (c == '0')
2777 prev_saved_doc_string[to++] = 0;
2778 else if (c == '_')
2779 prev_saved_doc_string[to++] = 037;
2780 }
2781 else
2782 prev_saved_doc_string[to++] = c;
2783 }
2784
2785 return make_string (prev_saved_doc_string + start,
2786 to - start);
2787 }
b2a30870 2788 else
6fe9cce5 2789 return get_doc_string (val, 0, 0);
b2a30870
RS
2790 }
2791
821d417e
RS
2792 return val;
2793 }
078e7b4a
JB
2794 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil));
2795 }
2796 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil));
2797 }
2798 tem = (read_pure && flag <= 0
2799 ? pure_cons (elt, Qnil)
2800 : Fcons (elt, Qnil));
265a9e55 2801 if (!NILP (tail))
c1d497be 2802 XCDR (tail) = tem;
078e7b4a
JB
2803 else
2804 val = tem;
2805 tail = tem;
2806 if (defunflag < 0)
2807 defunflag = EQ (elt, Qdefun);
2808 else if (defunflag > 0)
2809 read_pure = 1;
2810 }
2811}
2812\f
2813Lisp_Object Vobarray;
2814Lisp_Object initial_obarray;
2815
d007f5c8
RS
2816/* oblookup stores the bucket number here, for the sake of Funintern. */
2817
2818int oblookup_last_bucket_number;
2819
2820static int hash_string ();
2821Lisp_Object oblookup ();
2822
2823/* Get an error if OBARRAY is not an obarray.
2824 If it is one, return it. */
2825
078e7b4a
JB
2826Lisp_Object
2827check_obarray (obarray)
2828 Lisp_Object obarray;
2829{
cfff016d 2830 while (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
078e7b4a
JB
2831 {
2832 /* If Vobarray is now invalid, force it to be valid. */
2833 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
2834
2835 obarray = wrong_type_argument (Qvectorp, obarray);
2836 }
2837 return obarray;
2838}
2839
d007f5c8
RS
2840/* Intern the C string STR: return a symbol with that name,
2841 interned in the current obarray. */
078e7b4a
JB
2842
2843Lisp_Object
2844intern (str)
2845 char *str;
2846{
2847 Lisp_Object tem;
2848 int len = strlen (str);
153a17b7 2849 Lisp_Object obarray;
078e7b4a 2850
153a17b7 2851 obarray = Vobarray;
cfff016d 2852 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
078e7b4a 2853 obarray = check_obarray (obarray);
e28552a4 2854 tem = oblookup (obarray, str, len, len);
cfff016d 2855 if (SYMBOLP (tem))
078e7b4a 2856 return tem;
87631ef7 2857 return Fintern (make_string (str, len), obarray);
078e7b4a 2858}
4ad679f9
EN
2859
2860/* Create an uninterned symbol with name STR. */
2861
2862Lisp_Object
2863make_symbol (str)
2864 char *str;
2865{
2866 int len = strlen (str);
2867
2868 return Fmake_symbol ((!NILP (Vpurify_flag)
491f16a2 2869 ? make_pure_string (str, len, len, 0)
4ad679f9
EN
2870 : make_string (str, len)));
2871}
d007f5c8 2872\f
078e7b4a
JB
2873DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
2874 "Return the canonical symbol whose name is STRING.\n\
2875If there is none, one is created by this function and returned.\n\
2876A second optional argument specifies the obarray to use;\n\
2877it defaults to the value of `obarray'.")
9391b698
EN
2878 (string, obarray)
2879 Lisp_Object string, obarray;
078e7b4a
JB
2880{
2881 register Lisp_Object tem, sym, *ptr;
2882
265a9e55 2883 if (NILP (obarray)) obarray = Vobarray;
078e7b4a
JB
2884 obarray = check_obarray (obarray);
2885
9391b698 2886 CHECK_STRING (string, 0);
078e7b4a 2887
e28552a4
RS
2888 tem = oblookup (obarray, XSTRING (string)->data,
2889 XSTRING (string)->size,
fc932ac6 2890 STRING_BYTES (XSTRING (string)));
cfff016d 2891 if (!INTEGERP (tem))
078e7b4a
JB
2892 return tem;
2893
265a9e55 2894 if (!NILP (Vpurify_flag))
9391b698
EN
2895 string = Fpurecopy (string);
2896 sym = Fmake_symbol (string);
4ad679f9 2897 XSYMBOL (sym)->obarray = obarray;
078e7b4a 2898
bdd47b1c 2899 if ((XSTRING (string)->data[0] == ':')
a458d45d 2900 && EQ (obarray, initial_obarray))
a0549832
RS
2901 XSYMBOL (sym)->value = sym;
2902
078e7b4a 2903 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
cfff016d 2904 if (SYMBOLP (*ptr))
078e7b4a
JB
2905 XSYMBOL (sym)->next = XSYMBOL (*ptr);
2906 else
2907 XSYMBOL (sym)->next = 0;
2908 *ptr = sym;
2909 return sym;
2910}
2911
2912DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
b55048d4 2913 "Return the canonical symbol named NAME, or nil if none exists.\n\
3ccf78e0
DL
2914NAME may be a string or a symbol. If it is a symbol, that exact\n\
2915symbol is searched for.\n\
078e7b4a
JB
2916A second optional argument specifies the obarray to use;\n\
2917it defaults to the value of `obarray'.")
b55048d4
GM
2918 (name, obarray)
2919 Lisp_Object name, obarray;
078e7b4a
JB
2920{
2921 register Lisp_Object tem;
b55048d4 2922 struct Lisp_String *string;
078e7b4a 2923
265a9e55 2924 if (NILP (obarray)) obarray = Vobarray;
078e7b4a
JB
2925 obarray = check_obarray (obarray);
2926
b55048d4
GM
2927 if (!SYMBOLP (name))
2928 {
2929 CHECK_STRING (name, 0);
2930 string = XSTRING (name);
2931 }
2932 else
2933 string = XSYMBOL (name)->name;
078e7b4a 2934
b55048d4
GM
2935 tem = oblookup (obarray, string->data, string->size, STRING_BYTES (string));
2936 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
2937 return Qnil;
2938 else
078e7b4a 2939 return tem;
078e7b4a 2940}
d007f5c8
RS
2941\f
2942DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
2943 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2944The value is t if a symbol was found and deleted, nil otherwise.\n\
2945NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2946is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2947OBARRAY defaults to the value of the variable `obarray'.")
2948 (name, obarray)
2949 Lisp_Object name, obarray;
2950{
2951 register Lisp_Object string, tem;
2952 int hash;
2953
2954 if (NILP (obarray)) obarray = Vobarray;
2955 obarray = check_obarray (obarray);
2956
2957 if (SYMBOLP (name))
2958 XSETSTRING (string, XSYMBOL (name)->name);
2959 else
2960 {
2961 CHECK_STRING (name, 0);
2962 string = name;
2963 }
2964
e28552a4
RS
2965 tem = oblookup (obarray, XSTRING (string)->data,
2966 XSTRING (string)->size,
fc932ac6 2967 STRING_BYTES (XSTRING (string)));
d007f5c8
RS
2968 if (INTEGERP (tem))
2969 return Qnil;
2970 /* If arg was a symbol, don't delete anything but that symbol itself. */
2971 if (SYMBOLP (name) && !EQ (name, tem))
2972 return Qnil;
2973
ca69c42f
RS
2974 XSYMBOL (tem)->obarray = Qnil;
2975
d007f5c8
RS
2976 hash = oblookup_last_bucket_number;
2977
2978 if (EQ (XVECTOR (obarray)->contents[hash], tem))
b2a30870
RS
2979 {
2980 if (XSYMBOL (tem)->next)
2981 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
2982 else
2983 XSETINT (XVECTOR (obarray)->contents[hash], 0);
2984 }
d007f5c8
RS
2985 else
2986 {
2987 Lisp_Object tail, following;
2988
2989 for (tail = XVECTOR (obarray)->contents[hash];
2990 XSYMBOL (tail)->next;
2991 tail = following)
2992 {
2993 XSETSYMBOL (following, XSYMBOL (tail)->next);
2994 if (EQ (following, tem))
2995 {
2996 XSYMBOL (tail)->next = XSYMBOL (following)->next;
2997 break;
2998 }
2999 }
3000 }
3001
3002 return Qt;
3003}
3004\f
3005/* Return the symbol in OBARRAY whose names matches the string
e28552a4
RS
3006 of SIZE characters (SIZE_BYTE bytes) at PTR.
3007 If there is no such symbol in OBARRAY, return nil.
d007f5c8
RS
3008
3009 Also store the bucket number in oblookup_last_bucket_number. */
078e7b4a
JB
3010
3011Lisp_Object
e28552a4 3012oblookup (obarray, ptr, size, size_byte)
078e7b4a
JB
3013 Lisp_Object obarray;
3014 register char *ptr;
e28552a4 3015 int size, size_byte;
078e7b4a 3016{
7a70b397
RS
3017 int hash;
3018 int obsize;
078e7b4a
JB
3019 register Lisp_Object tail;
3020 Lisp_Object bucket, tem;
3021
cfff016d 3022 if (!VECTORP (obarray)
7c79a684 3023 || (obsize = XVECTOR (obarray)->size) == 0)
078e7b4a
JB
3024 {
3025 obarray = check_obarray (obarray);
3026 obsize = XVECTOR (obarray)->size;
3027 }
519418b3
RS
3028 /* This is sometimes needed in the middle of GC. */
3029 obsize &= ~ARRAY_MARK_FLAG;
078e7b4a 3030 /* Combining next two lines breaks VMS C 2.3. */
e28552a4 3031 hash = hash_string (ptr, size_byte);
078e7b4a
JB
3032 hash %= obsize;
3033 bucket = XVECTOR (obarray)->contents[hash];
d007f5c8 3034 oblookup_last_bucket_number = hash;
078e7b4a
JB
3035 if (XFASTINT (bucket) == 0)
3036 ;
cfff016d 3037 else if (!SYMBOLP (bucket))
078e7b4a 3038 error ("Bad data in guts of obarray"); /* Like CADR error message */
d007f5c8
RS
3039 else
3040 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
078e7b4a 3041 {
fc932ac6 3042 if (STRING_BYTES (XSYMBOL (tail)->name) == size_byte
e28552a4
RS
3043 && XSYMBOL (tail)->name->size == size
3044 && !bcmp (XSYMBOL (tail)->name->data, ptr, size_byte))
078e7b4a
JB
3045 return tail;
3046 else if (XSYMBOL (tail)->next == 0)
3047 break;
3048 }
1805de4f 3049 XSETINT (tem, hash);
078e7b4a
JB
3050 return tem;
3051}
3052
3053static int
3054hash_string (ptr, len)
3055 unsigned char *ptr;
3056 int len;
3057{
3058 register unsigned char *p = ptr;
3059 register unsigned char *end = p + len;
3060 register unsigned char c;
3061 register int hash = 0;
3062
3063 while (p != end)
3064 {
3065 c = *p++;
3066 if (c >= 0140) c -= 40;
3067 hash = ((hash<<3) + (hash>>28) + c);
3068 }
3069 return hash & 07777777777;
3070}
d007f5c8 3071\f
078e7b4a
JB
3072void
3073map_obarray (obarray, fn, arg)
3074 Lisp_Object obarray;
d5b28a9d 3075 void (*fn) P_ ((Lisp_Object, Lisp_Object));
078e7b4a
JB
3076 Lisp_Object arg;
3077{
3078 register int i;
3079 register Lisp_Object tail;
3080 CHECK_VECTOR (obarray, 1);
3081 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
3082 {
3083 tail = XVECTOR (obarray)->contents[i];
4f5c4403 3084 if (SYMBOLP (tail))
078e7b4a
JB
3085 while (1)
3086 {
3087 (*fn) (tail, arg);
3088 if (XSYMBOL (tail)->next == 0)
3089 break;
1805de4f 3090 XSETSYMBOL (tail, XSYMBOL (tail)->next);
078e7b4a
JB
3091 }
3092 }
3093}
3094
d5b28a9d 3095void
078e7b4a
JB
3096mapatoms_1 (sym, function)
3097 Lisp_Object sym, function;
3098{
3099 call1 (function, sym);
3100}
3101
3102DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
3103 "Call FUNCTION on every symbol in OBARRAY.\n\
3104OBARRAY defaults to the value of `obarray'.")
3105 (function, obarray)
3106 Lisp_Object function, obarray;
3107{
265a9e55 3108 if (NILP (obarray)) obarray = Vobarray;
078e7b4a
JB
3109 obarray = check_obarray (obarray);
3110
3111 map_obarray (obarray, mapatoms_1, function);
3112 return Qnil;
3113}
3114
5e88a39e 3115#define OBARRAY_SIZE 1511
078e7b4a
JB
3116
3117void
3118init_obarray ()
3119{
3120 Lisp_Object oblength;
3121 int hash;
3122 Lisp_Object *tem;
3123
baf69866 3124 XSETFASTINT (oblength, OBARRAY_SIZE);
078e7b4a 3125
491f16a2 3126 Qnil = Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
078e7b4a
JB
3127 Vobarray = Fmake_vector (oblength, make_number (0));
3128 initial_obarray = Vobarray;
3129 staticpro (&initial_obarray);
3130 /* Intern nil in the obarray */
4ad679f9 3131 XSYMBOL (Qnil)->obarray = Vobarray;
078e7b4a
JB
3132 /* These locals are to kludge around a pyramid compiler bug. */
3133 hash = hash_string ("nil", 3);
3134 /* Separate statement here to avoid VAXC bug. */
3135 hash %= OBARRAY_SIZE;
3136 tem = &XVECTOR (Vobarray)->contents[hash];
3137 *tem = Qnil;
3138
491f16a2 3139 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
078e7b4a
JB
3140 XSYMBOL (Qnil)->function = Qunbound;
3141 XSYMBOL (Qunbound)->value = Qunbound;
3142 XSYMBOL (Qunbound)->function = Qunbound;
3143
3144 Qt = intern ("t");
3145 XSYMBOL (Qnil)->value = Qnil;
3146 XSYMBOL (Qnil)->plist = Qnil;
3147 XSYMBOL (Qt)->value = Qt;
3148
3149 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3150 Vpurify_flag = Qt;
3151
3152 Qvariable_documentation = intern ("variable-documentation");
0f73bb1c 3153 staticpro (&Qvariable_documentation);
078e7b4a 3154
449fea39 3155 read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
3cb65b0e 3156 read_buffer = (char *) xmalloc (read_buffer_size);
078e7b4a
JB
3157}
3158\f
3159void
3160defsubr (sname)
3161 struct Lisp_Subr *sname;
3162{
3163 Lisp_Object sym;
3164 sym = intern (sname->symbol_name);
1805de4f 3165 XSETSUBR (XSYMBOL (sym)->function, sname);
078e7b4a
JB
3166}
3167
3168#ifdef NOTDEF /* use fset in subr.el now */
3169void
3170defalias (sname, string)
3171 struct Lisp_Subr *sname;
3172 char *string;
3173{
3174 Lisp_Object sym;
3175 sym = intern (string);
1805de4f 3176 XSETSUBR (XSYMBOL (sym)->function, sname);
078e7b4a
JB
3177}
3178#endif /* NOTDEF */
3179
078e7b4a 3180/* Define an "integer variable"; a symbol whose value is forwarded
1a0f90f7 3181 to a C variable of type int. Sample call: */
950c215d 3182 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
078e7b4a 3183void
e9e00ff2 3184defvar_int (namestring, address)
078e7b4a
JB
3185 char *namestring;
3186 int *address;
078e7b4a 3187{
1a0f90f7 3188 Lisp_Object sym, val;
078e7b4a 3189 sym = intern (namestring);
1a0f90f7 3190 val = allocate_misc ();
47e28b2c 3191 XMISCTYPE (val) = Lisp_Misc_Intfwd;
fc1e7df5 3192 XINTFWD (val)->intvar = address;
1a0f90f7 3193 XSYMBOL (sym)->value = val;
078e7b4a
JB
3194}
3195
3196/* Similar but define a variable whose value is T if address contains 1,
1a0f90f7 3197 NIL if address contains 0 */
078e7b4a 3198void
e9e00ff2 3199defvar_bool (namestring, address)
078e7b4a
JB
3200 char *namestring;
3201 int *address;
078e7b4a 3202{
1a0f90f7 3203 Lisp_Object sym, val;
078e7b4a 3204 sym = intern (namestring);
1a0f90f7 3205 val = allocate_misc ();
47e28b2c 3206 XMISCTYPE (val) = Lisp_Misc_Boolfwd;
fc1e7df5 3207 XBOOLFWD (val)->boolvar = address;
1a0f90f7 3208 XSYMBOL (sym)->value = val;
1ffcc3b1 3209 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
078e7b4a
JB
3210}
3211
1a0f90f7
KH
3212/* Similar but define a variable whose value is the Lisp Object stored
3213 at address. Two versions: with and without gc-marking of the C
3214 variable. The nopro version is used when that variable will be
3215 gc-marked for some other reason, since marking the same slot twice
3216 can cause trouble with strings. */
078e7b4a 3217void
1a0f90f7 3218defvar_lisp_nopro (namestring, address)
078e7b4a
JB
3219 char *namestring;
3220 Lisp_Object *address;
078e7b4a 3221{
1a0f90f7 3222 Lisp_Object sym, val;
078e7b4a 3223 sym = intern (namestring);
1a0f90f7 3224 val = allocate_misc ();
47e28b2c 3225 XMISCTYPE (val) = Lisp_Misc_Objfwd;
fc1e7df5 3226 XOBJFWD (val)->objvar = address;
1a0f90f7 3227 XSYMBOL (sym)->value = val;
078e7b4a
JB
3228}
3229
078e7b4a 3230void
1a0f90f7 3231defvar_lisp (namestring, address)
078e7b4a
JB
3232 char *namestring;
3233 Lisp_Object *address;
078e7b4a 3234{
1a0f90f7
KH
3235 defvar_lisp_nopro (namestring, address);
3236 staticpro (address);
078e7b4a
JB
3237}
3238
078e7b4a 3239/* Similar but define a variable whose value is the Lisp Object stored in
2836d9a4
KH
3240 the current buffer. address is the address of the slot in the buffer
3241 that is current now. */
078e7b4a
JB
3242
3243void
4360b0c6 3244defvar_per_buffer (namestring, address, type, doc)
078e7b4a
JB
3245 char *namestring;
3246 Lisp_Object *address;
4360b0c6 3247 Lisp_Object type;
078e7b4a
JB
3248 char *doc;
3249{
1a0f90f7 3250 Lisp_Object sym, val;
078e7b4a
JB
3251 int offset;
3252 extern struct buffer buffer_local_symbols;
3253
3254 sym = intern (namestring);
1a0f90f7 3255 val = allocate_misc ();
078e7b4a
JB
3256 offset = (char *)address - (char *)current_buffer;
3257
47e28b2c 3258 XMISCTYPE (val) = Lisp_Misc_Buffer_Objfwd;
fc1e7df5 3259 XBUFFER_OBJFWD (val)->offset = offset;
1a0f90f7 3260 XSYMBOL (sym)->value = val;
11fd416e
GM
3261 PER_BUFFER_SYMBOL (offset) = sym;
3262 PER_BUFFER_TYPE (offset) = type;
cf611f01 3263
11fd416e 3264 if (PER_BUFFER_IDX (offset) == 0)
078e7b4a
JB
3265 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3266 slot of buffer_local_flags */
3267 abort ();
3268}
3269
950c215d
KH
3270
3271/* Similar but define a variable whose value is the Lisp Object stored
4ac38690 3272 at a particular offset in the current kboard object. */
950c215d
KH
3273
3274void
4ac38690 3275defvar_kboard (namestring, offset)
950c215d
KH
3276 char *namestring;
3277 int offset;
3278{
3279 Lisp_Object sym, val;
3280 sym = intern (namestring);
3281 val = allocate_misc ();
47e28b2c 3282 XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd;
4ac38690 3283 XKBOARD_OBJFWD (val)->offset = offset;
950c215d
KH
3284 XSYMBOL (sym)->value = val;
3285}
078e7b4a 3286\f
11938f10
KH
3287/* Record the value of load-path used at the start of dumping
3288 so we can see if the site changed it later during dumping. */
3289static Lisp_Object dump_path;
3290
d5b28a9d 3291void
279499f0 3292init_lread ()
078e7b4a 3293{
46947372 3294 char *normal;
e73997a1 3295 int turn_off_warning = 0;
078e7b4a 3296
279499f0 3297 /* Compute the default load-path. */
46947372
JB
3298#ifdef CANNOT_DUMP
3299 normal = PATH_LOADSEARCH;
e065a56e 3300 Vload_path = decode_env_path (0, normal);
46947372
JB
3301#else
3302 if (NILP (Vpurify_flag))
3303 normal = PATH_LOADSEARCH;
279499f0 3304 else
46947372 3305 normal = PATH_DUMPLOADSEARCH;
279499f0 3306
46947372
JB
3307 /* In a dumped Emacs, we normally have to reset the value of
3308 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3309 uses ../lisp, instead of the path of the installed elisp
3310 libraries. However, if it appears that Vload_path was changed
3311 from the default before dumping, don't override that value. */
4746118a
JB
3312 if (initialized)
3313 {
4746118a 3314 if (! NILP (Fequal (dump_path, Vload_path)))
80667d53
RS
3315 {
3316 Vload_path = decode_env_path (0, normal);
74180aa4 3317 if (!NILP (Vinstallation_directory))
80667d53 3318 {
74180aa4 3319 /* Add to the path the lisp subdir of the
3a3056e5
RS
3320 installation dir, if it exists. */
3321 Lisp_Object tem, tem1;
74180aa4
RS
3322 tem = Fexpand_file_name (build_string ("lisp"),
3323 Vinstallation_directory);
3a3056e5
RS
3324 tem1 = Ffile_exists_p (tem);
3325 if (!NILP (tem1))
3326 {
3327 if (NILP (Fmember (tem, Vload_path)))
e73997a1
RS
3328 {
3329 turn_off_warning = 1;
3330 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
3331 }
3a3056e5
RS
3332 }
3333 else
3334 /* That dir doesn't exist, so add the build-time
3335 Lisp dirs instead. */
3336 Vload_path = nconc2 (Vload_path, dump_path);
c478f98c 3337
9fbc0116
RS
3338 /* Add leim under the installation dir, if it exists. */
3339 tem = Fexpand_file_name (build_string ("leim"),
3340 Vinstallation_directory);
3341 tem1 = Ffile_exists_p (tem);
3342 if (!NILP (tem1))
3343 {
3344 if (NILP (Fmember (tem, Vload_path)))
3345 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
3346 }
3347
c478f98c
RS
3348 /* Add site-list under the installation dir, if it exists. */
3349 tem = Fexpand_file_name (build_string ("site-lisp"),
3350 Vinstallation_directory);
3351 tem1 = Ffile_exists_p (tem);
3352 if (!NILP (tem1))
3353 {
3354 if (NILP (Fmember (tem, Vload_path)))
3355 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
3356 }
0f337465
RS
3357
3358 /* If Emacs was not built in the source directory,
9fbc0116
RS
3359 and it is run from where it was built, add to load-path
3360 the lisp, leim and site-lisp dirs under that directory. */
0f337465
RS
3361
3362 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
3363 {
33046fc9
RS
3364 Lisp_Object tem2;
3365
0f337465
RS
3366 tem = Fexpand_file_name (build_string ("src/Makefile"),
3367 Vinstallation_directory);
3368 tem1 = Ffile_exists_p (tem);
33046fc9
RS
3369
3370 /* Don't be fooled if they moved the entire source tree
3371 AFTER dumping Emacs. If the build directory is indeed
3372 different from the source dir, src/Makefile.in and
3373 src/Makefile will not be found together. */
3374 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
3375 Vinstallation_directory);
3376 tem2 = Ffile_exists_p (tem);
3377 if (!NILP (tem1) && NILP (tem2))
0f337465
RS
3378 {
3379 tem = Fexpand_file_name (build_string ("lisp"),
3380 Vsource_directory);
3381
3382 if (NILP (Fmember (tem, Vload_path)))
3383 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
3384
9fbc0116
RS
3385 tem = Fexpand_file_name (build_string ("leim"),
3386 Vsource_directory);
3387
3388 if (NILP (Fmember (tem, Vload_path)))
3389 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
3390
0f337465
RS
3391 tem = Fexpand_file_name (build_string ("site-lisp"),
3392 Vsource_directory);
3393
3394 if (NILP (Fmember (tem, Vload_path)))
3395 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
3396 }
3397 }
80667d53
RS
3398 }
3399 }
4746118a
JB
3400 }
3401 else
11938f10 3402 {
7b396c6c
RS
3403 /* NORMAL refers to the lisp dir in the source directory. */
3404 /* We used to add ../lisp at the front here, but
3405 that caused trouble because it was copied from dump_path
3406 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3407 It should be unnecessary. */
3408 Vload_path = decode_env_path (0, normal);
11938f10
KH
3409 dump_path = Vload_path;
3410 }
46947372 3411#endif
279499f0 3412
317073d5
RS
3413#ifndef WINDOWSNT
3414 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3415 almost never correct, thereby causing a warning to be printed out that
8e6208c5 3416 confuses users. Since PATH_LOADSEARCH is always overridden by the
317073d5
RS
3417 EMACSLOADPATH environment variable below, disable the warning on NT. */
3418
078e7b4a 3419 /* Warn if dirs in the *standard* path don't exist. */
e73997a1
RS
3420 if (!turn_off_warning)
3421 {
3422 Lisp_Object path_tail;
078e7b4a 3423
e73997a1
RS
3424 for (path_tail = Vload_path;
3425 !NILP (path_tail);
c1d497be 3426 path_tail = XCDR (path_tail))
e73997a1
RS
3427 {
3428 Lisp_Object dirfile;
3429 dirfile = Fcar (path_tail);
3430 if (STRINGP (dirfile))
3431 {
3432 dirfile = Fdirectory_file_name (dirfile);
3433 if (access (XSTRING (dirfile)->data, 0) < 0)
85496b8c 3434 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
c1d497be 3435 XCAR (path_tail));
e73997a1
RS
3436 }
3437 }
3438 }
317073d5 3439#endif /* WINDOWSNT */
46947372
JB
3440
3441 /* If the EMACSLOADPATH environment variable is set, use its value.
3442 This doesn't apply if we're dumping. */
ffd9c2a1 3443#ifndef CANNOT_DUMP
46947372
JB
3444 if (NILP (Vpurify_flag)
3445 && egetenv ("EMACSLOADPATH"))
ffd9c2a1 3446#endif
279499f0 3447 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
279499f0
JB
3448
3449 Vvalues = Qnil;
3450
078e7b4a 3451 load_in_progress = 0;
4e53f562 3452 Vload_file_name = Qnil;
d2c6be7f
RS
3453
3454 load_descriptor_list = Qnil;
8f6b0411
RS
3455
3456 Vstandard_input = Qt;
f74b0705 3457 Vloads_in_progress = Qnil;
078e7b4a
JB
3458}
3459
85496b8c
RS
3460/* Print a warning, using format string FORMAT, that directory DIRNAME
3461 does not exist. Print it on stderr and put it in *Message*. */
3462
d5b28a9d 3463void
85496b8c
RS
3464dir_warning (format, dirname)
3465 char *format;
3466 Lisp_Object dirname;
3467{
3468 char *buffer
3469 = (char *) alloca (XSTRING (dirname)->size + strlen (format) + 5);
3470
3471 fprintf (stderr, format, XSTRING (dirname)->data);
3472 sprintf (buffer, format, XSTRING (dirname)->data);
9b69357e
GV
3473 /* Don't log the warning before we've initialized!! */
3474 if (initialized)
3475 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
85496b8c
RS
3476}
3477
078e7b4a 3478void
279499f0 3479syms_of_lread ()
078e7b4a
JB
3480{
3481 defsubr (&Sread);
3482 defsubr (&Sread_from_string);
3483 defsubr (&Sintern);
3484 defsubr (&Sintern_soft);
d007f5c8 3485 defsubr (&Sunintern);
078e7b4a 3486 defsubr (&Sload);
228d4b1c 3487 defsubr (&Seval_buffer);
078e7b4a
JB
3488 defsubr (&Seval_region);
3489 defsubr (&Sread_char);
3490 defsubr (&Sread_char_exclusive);
078e7b4a 3491 defsubr (&Sread_event);
078e7b4a
JB
3492 defsubr (&Sget_file_char);
3493 defsubr (&Smapatoms);
3494
3495 DEFVAR_LISP ("obarray", &Vobarray,
3496 "Symbol table for use by `intern' and `read'.\n\
3497It is a vector whose length ought to be prime for best results.\n\
3498The vector's contents don't make sense if examined from Lisp programs;\n\
3499to find all the symbols in an obarray, use `mapatoms'.");
3500
3501 DEFVAR_LISP ("values", &Vvalues,
3502 "List of values of all expressions which were read, evaluated and printed.\n\
3503Order is reverse chronological.");
3504
3505 DEFVAR_LISP ("standard-input", &Vstandard_input,
3506 "Stream for read to get input from.\n\
3507See documentation of `read' for possible values.");
3508 Vstandard_input = Qt;
3509
3510 DEFVAR_LISP ("load-path", &Vload_path,
3511 "*List of directories to search for files to load.\n\
3512Each element is a string (directory name) or nil (try default directory).\n\
3513Initialized based on EMACSLOADPATH environment variable, if any,\n\
57bda87a 3514otherwise to default specified by file `epaths.h' when Emacs was built.");
078e7b4a
JB
3515
3516 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
3517 "Non-nil iff inside of `load'.");
3518
3519 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
3520 "An alist of expressions to be evalled when particular files are loaded.\n\
3521Each element looks like (FILENAME FORMS...).\n\
3522When `load' is run and the file-name argument is FILENAME,\n\
3523the FORMS in the corresponding element are executed at the end of loading.\n\n\
3524FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3525with no directory specified, since that is how `load' is normally called.\n\
3526An error in FORMS does not undo the load,\n\
3527but does prevent execution of the rest of the FORMS.");
3528 Vafter_load_alist = Qnil;
3529
ae321d28
RS
3530 DEFVAR_LISP ("load-history", &Vload_history,
3531 "Alist mapping source file names to symbols and features.\n\
3532Each alist element is a list that starts with a file name,\n\
3533except for one element (optional) that starts with nil and describes\n\
3534definitions evaluated from buffers not visiting files.\n\
3535The remaining elements of each list are symbols defined as functions\n\
e8c7d424 3536or variables, and cons cells `(provide . FEATURE)', `(require . FEATURE)',\n\
7973e637 3537and `(autoload . SYMBOL)'.");
ae321d28
RS
3538 Vload_history = Qnil;
3539
20ea2964
RS
3540 DEFVAR_LISP ("load-file-name", &Vload_file_name,
3541 "Full name of file being loaded by `load'.");
3542 Vload_file_name = Qnil;
3543
4116ab9f 3544 DEFVAR_LISP ("user-init-file", &Vuser_init_file,
d750b1f5
AI
3545 "File name, including directory, of user's initialization file.\n\
3546If the file loaded had extension `.elc' and there was a corresponding `.el'\n\
3547file, this variable contains the name of the .el file, suitable for use\n\
d826d78b 3548by functions like `custom-save-all' which edit the init file.");
4116ab9f
KH
3549 Vuser_init_file = Qnil;
3550
8a1f1537
RS
3551 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
3552 "Used for internal purposes by `load'.");
ae321d28
RS
3553 Vcurrent_load_list = Qnil;
3554
84a15045
RS
3555 DEFVAR_LISP ("load-read-function", &Vload_read_function,
3556 "Function used by `load' and `eval-region' for reading expressions.\n\
3557The default is nil, which means use the function `read'.");
3558 Vload_read_function = Qnil;
3559
fe0e03f3
KH
3560 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
3561 "Function called in `load' for loading an Emacs lisp source file.\n\
3562This function is for doing code conversion before reading the source file.\n\
3563If nil, loading is done without any code conversion.\n\
3564Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3565 FULLNAME is the full name of FILE.\n\
3566See `load' for the meaning of the remaining arguments.");
3567 Vload_source_file_function = Qnil;
3568
b2a30870
RS
3569 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
3570 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3571This is useful when the file being loaded is a temporary copy.");
3572 load_force_doc_strings = 0;
3573
94e554db 3574 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
afdca070
RS
3575 "Non-nil means `read' converts strings to unibyte whenever possible.\n\
3576This is normally bound by `load' and `eval-buffer' to control `read',\n\
3577and is not meant for users to change.");
94e554db
RS
3578 load_convert_to_unibyte = 0;
3579
1521a8fa
RS
3580 DEFVAR_LISP ("source-directory", &Vsource_directory,
3581 "Directory in which Emacs sources were found when Emacs was built.\n\
3582You cannot count on them to still be there!");
a90ba1e2
KH
3583 Vsource_directory
3584 = Fexpand_file_name (build_string ("../"),
3585 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
3586
4b104c41
RS
3587 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
3588 "List of files that were preloaded (when dumping Emacs).");
3589 Vpreloaded_file_list = Qnil;
3590
1ffcc3b1
DL
3591 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
3592 "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
3593 Vbyte_boolean_vars = Qnil;
3594
da84f340
GM
3595 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries,
3596 "Non-nil means load dangerous compiled Lisp files.\n\
3597Some versions of XEmacs use different byte codes than Emacs. These\n\
3598incompatible byte codes can make Emacs crash when it tries to execute\n\
3599them.");
3600 load_dangerous_libraries = 0;
3601
bb970e67
GM
3602 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp,
3603 "Regular expression matching safe to load compiled Lisp files.\n\
3604When Emacs loads a compiled Lisp file, it reads the first 512 bytes\n\
3605from the file, and matches them against this regular expression.\n\
3606When the regular expression matches, the file is considered to be safe\n\
3607to load. See also `load-dangerous-libraries'.");
3608 Vbytecomp_version_regexp
f2e7d5eb 3609 = build_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
da84f340 3610
550a625e
GM
3611 DEFVAR_LISP ("recursive-load-depth-limit", &Vrecursive_load_depth_limit,
3612 "Limit for depth of recursive loads.\n\
3613Value should be either an integer > 0 specifying the limit, or nil for\n\
3614no limit.");
3615 Vrecursive_load_depth_limit = make_number (10);
3616
a90ba1e2
KH
3617 /* Vsource_directory was initialized in init_lread. */
3618
d2c6be7f
RS
3619 load_descriptor_list = Qnil;
3620 staticpro (&load_descriptor_list);
3621
8a1f1537
RS
3622 Qcurrent_load_list = intern ("current-load-list");
3623 staticpro (&Qcurrent_load_list);
3624
078e7b4a
JB
3625 Qstandard_input = intern ("standard-input");
3626 staticpro (&Qstandard_input);
3627
3628 Qread_char = intern ("read-char");
3629 staticpro (&Qread_char);
3630
3631 Qget_file_char = intern ("get-file-char");
3632 staticpro (&Qget_file_char);
7bd279cd 3633
17634846
RS
3634 Qbackquote = intern ("`");
3635 staticpro (&Qbackquote);
3636 Qcomma = intern (",");
3637 staticpro (&Qcomma);
3638 Qcomma_at = intern (",@");
3639 staticpro (&Qcomma_at);
3640 Qcomma_dot = intern (",.");
3641 staticpro (&Qcomma_dot);
3642
74549846
RS
3643 Qinhibit_file_name_operation = intern ("inhibit-file-name-operation");
3644 staticpro (&Qinhibit_file_name_operation);
3645
7bd279cd
RS
3646 Qascii_character = intern ("ascii-character");
3647 staticpro (&Qascii_character);
c2225d00 3648
2b6cae0c
RS
3649 Qfunction = intern ("function");
3650 staticpro (&Qfunction);
3651
c2225d00
RS
3652 Qload = intern ("load");
3653 staticpro (&Qload);
20ea2964
RS
3654
3655 Qload_file_name = intern ("load-file-name");
3656 staticpro (&Qload_file_name);
11938f10
KH
3657
3658 staticpro (&dump_path);
4ad679f9
EN
3659
3660 staticpro (&read_objects);
3661 read_objects = Qnil;
9e062b6c
RS
3662 staticpro (&seen_list);
3663
7ee3bd7b
GM
3664 Vloads_in_progress = Qnil;
3665 staticpro (&Vloads_in_progress);
078e7b4a 3666}