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