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