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