Remove support for DJGPP v1.x (bug#5813).
[emacs.git] / src / lread.c
blob90edca90a16c9f568dbf8d7304fd32d54d2b40dc
1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 #include <config.h>
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/file.h>
27 #include <errno.h>
28 #include <setjmp.h>
29 #include "lisp.h"
30 #include "intervals.h"
31 #include "buffer.h"
32 #include "character.h"
33 #include "charset.h"
34 #include "coding.h"
35 #include <epaths.h>
36 #include "commands.h"
37 #include "keyboard.h"
38 #include "frame.h"
39 #include "termhooks.h"
40 #include "coding.h"
41 #include "blockinput.h"
43 #ifdef MSDOS
44 #include "msdos.h"
45 #endif
47 #ifdef HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
51 #ifndef X_OK
52 #define X_OK 01
53 #endif
55 #include <math.h>
57 #ifdef HAVE_SETLOCALE
58 #include <locale.h>
59 #endif /* HAVE_SETLOCALE */
61 #ifdef HAVE_FCNTL_H
62 #include <fcntl.h>
63 #endif
64 #ifndef O_RDONLY
65 #define O_RDONLY 0
66 #endif
68 #ifdef HAVE_FSEEKO
69 #define file_offset off_t
70 #define file_tell ftello
71 #else
72 #define file_offset long
73 #define file_tell ftell
74 #endif
76 #ifndef USE_CRT_DLL
77 extern int errno;
78 #endif
80 /* hash table read constants */
81 Lisp_Object Qhash_table, Qdata;
82 Lisp_Object Qtest, Qsize;
83 Lisp_Object Qweakness;
84 Lisp_Object Qrehash_size;
85 Lisp_Object Qrehash_threshold;
86 extern Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
88 Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
89 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
90 Lisp_Object Qascii_character, Qload, Qload_file_name;
91 Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
92 Lisp_Object Qinhibit_file_name_operation;
93 Lisp_Object Qeval_buffer_list, Veval_buffer_list;
94 Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */
96 /* Used instead of Qget_file_char while loading *.elc files compiled
97 by Emacs 21 or older. */
98 static Lisp_Object Qget_emacs_mule_file_char;
100 static Lisp_Object Qload_force_doc_strings;
102 extern Lisp_Object Qevent_symbol_element_mask;
103 extern Lisp_Object Qfile_exists_p;
105 /* non-zero if inside `load' */
106 int load_in_progress;
107 static Lisp_Object Qload_in_progress;
109 /* Directory in which the sources were found. */
110 Lisp_Object Vsource_directory;
112 /* Search path and suffixes for files to be loaded. */
113 Lisp_Object Vload_path, Vload_suffixes, Vload_file_rep_suffixes;
115 /* File name of user's init file. */
116 Lisp_Object Vuser_init_file;
118 /* This is the user-visible association list that maps features to
119 lists of defs in their load files. */
120 Lisp_Object Vload_history;
122 /* This is used to build the load history. */
123 Lisp_Object Vcurrent_load_list;
125 /* List of files that were preloaded. */
126 Lisp_Object Vpreloaded_file_list;
128 /* Name of file actually being read by `load'. */
129 Lisp_Object Vload_file_name;
131 /* Function to use for reading, in `load' and friends. */
132 Lisp_Object Vload_read_function;
134 /* Non-nil means read recursive structures using #n= and #n# syntax. */
135 Lisp_Object Vread_circle;
137 /* The association list of objects read with the #n=object form.
138 Each member of the list has the form (n . object), and is used to
139 look up the object for the corresponding #n# construct.
140 It must be set to nil before all top-level calls to read0. */
141 Lisp_Object read_objects;
143 /* Nonzero means load should forcibly load all dynamic doc strings. */
144 static int load_force_doc_strings;
146 /* Nonzero means read should convert strings to unibyte. */
147 static int load_convert_to_unibyte;
149 /* Nonzero means READCHAR should read bytes one by one (not character)
150 when READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char.
151 This is set to 1 by read1 temporarily while handling #@NUMBER. */
152 static int load_each_byte;
154 /* Function to use for loading an Emacs Lisp source file (not
155 compiled) instead of readevalloop. */
156 Lisp_Object Vload_source_file_function;
158 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
159 Lisp_Object Vbyte_boolean_vars;
161 /* Whether or not to add a `read-positions' property to symbols
162 read. */
163 Lisp_Object Vread_with_symbol_positions;
165 /* List of (SYMBOL . POSITION) accumulated so far. */
166 Lisp_Object Vread_symbol_positions_list;
168 /* List of descriptors now open for Fload. */
169 static Lisp_Object load_descriptor_list;
171 /* File for get_file_char to read from. Use by load. */
172 static FILE *instream;
174 /* When nonzero, read conses in pure space */
175 static int read_pure;
177 /* For use within read-from-string (this reader is non-reentrant!!) */
178 static int read_from_string_index;
179 static int read_from_string_index_byte;
180 static int read_from_string_limit;
182 /* Number of characters read in the current call to Fread or
183 Fread_from_string. */
184 static int readchar_count;
186 /* This contains the last string skipped with #@. */
187 static char *saved_doc_string;
188 /* Length of buffer allocated in saved_doc_string. */
189 static int saved_doc_string_size;
190 /* Length of actual data in saved_doc_string. */
191 static int saved_doc_string_length;
192 /* This is the file position that string came from. */
193 static file_offset saved_doc_string_position;
195 /* This contains the previous string skipped with #@.
196 We copy it from saved_doc_string when a new string
197 is put in saved_doc_string. */
198 static char *prev_saved_doc_string;
199 /* Length of buffer allocated in prev_saved_doc_string. */
200 static int prev_saved_doc_string_size;
201 /* Length of actual data in prev_saved_doc_string. */
202 static int prev_saved_doc_string_length;
203 /* This is the file position that string came from. */
204 static file_offset prev_saved_doc_string_position;
206 /* Nonzero means inside a new-style backquote
207 with no surrounding parentheses.
208 Fread initializes this to zero, so we need not specbind it
209 or worry about what happens to it when there is an error. */
210 static int new_backquote_flag;
211 static Lisp_Object Vold_style_backquotes, Qold_style_backquotes;
213 /* A list of file names for files being loaded in Fload. Used to
214 check for recursive loads. */
216 static Lisp_Object Vloads_in_progress;
218 /* Non-zero means load dangerous compiled Lisp files. */
220 int load_dangerous_libraries;
222 /* Non-zero means force printing messages when loading Lisp files. */
224 int force_load_messages;
226 /* A regular expression used to detect files compiled with Emacs. */
228 static Lisp_Object Vbytecomp_version_regexp;
230 static int read_emacs_mule_char P_ ((int, int (*) (int, Lisp_Object),
231 Lisp_Object));
233 static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
234 Lisp_Object (*) (), int,
235 Lisp_Object, Lisp_Object,
236 Lisp_Object, Lisp_Object));
237 static Lisp_Object load_unwind P_ ((Lisp_Object));
238 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
240 static void invalid_syntax P_ ((const char *, int)) NO_RETURN;
241 static void end_of_file_error P_ (()) NO_RETURN;
244 /* Functions that read one byte from the current source READCHARFUN
245 or unreads one byte. If the integer argument C is -1, it returns
246 one read byte, or -1 when there's no more byte in the source. If C
247 is 0 or positive, it unreads C, and the return value is not
248 interesting. */
250 static int readbyte_for_lambda P_ ((int, Lisp_Object));
251 static int readbyte_from_file P_ ((int, Lisp_Object));
252 static int readbyte_from_string P_ ((int, Lisp_Object));
254 /* Handle unreading and rereading of characters.
255 Write READCHAR to read a character,
256 UNREAD(c) to unread c to be read again.
258 These macros correctly read/unread multibyte characters. */
260 #define READCHAR readchar (readcharfun, NULL)
261 #define UNREAD(c) unreadchar (readcharfun, c)
263 /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
264 #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
266 /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
267 Qlambda, or a cons, we use this to keep an unread character because
268 a file stream can't handle multibyte-char unreading. The value -1
269 means that there's no unread character. */
270 static int unread_char;
272 static int
273 readchar (readcharfun, multibyte)
274 Lisp_Object readcharfun;
275 int *multibyte;
277 Lisp_Object tem;
278 register int c;
279 int (*readbyte) P_ ((int, Lisp_Object));
280 unsigned char buf[MAX_MULTIBYTE_LENGTH];
281 int i, len;
282 int emacs_mule_encoding = 0;
284 if (multibyte)
285 *multibyte = 0;
287 readchar_count++;
289 if (BUFFERP (readcharfun))
291 register struct buffer *inbuffer = XBUFFER (readcharfun);
293 int pt_byte = BUF_PT_BYTE (inbuffer);
295 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
296 return -1;
298 if (! NILP (inbuffer->enable_multibyte_characters))
300 /* Fetch the character code from the buffer. */
301 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
302 BUF_INC_POS (inbuffer, pt_byte);
303 c = STRING_CHAR (p);
304 if (multibyte)
305 *multibyte = 1;
307 else
309 c = BUF_FETCH_BYTE (inbuffer, pt_byte);
310 if (! ASCII_BYTE_P (c))
311 c = BYTE8_TO_CHAR (c);
312 pt_byte++;
314 SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
316 return c;
318 if (MARKERP (readcharfun))
320 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
322 int bytepos = marker_byte_position (readcharfun);
324 if (bytepos >= BUF_ZV_BYTE (inbuffer))
325 return -1;
327 if (! NILP (inbuffer->enable_multibyte_characters))
329 /* Fetch the character code from the buffer. */
330 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
331 BUF_INC_POS (inbuffer, bytepos);
332 c = STRING_CHAR (p);
333 if (multibyte)
334 *multibyte = 1;
336 else
338 c = BUF_FETCH_BYTE (inbuffer, bytepos);
339 if (! ASCII_BYTE_P (c))
340 c = BYTE8_TO_CHAR (c);
341 bytepos++;
344 XMARKER (readcharfun)->bytepos = bytepos;
345 XMARKER (readcharfun)->charpos++;
347 return c;
350 if (EQ (readcharfun, Qlambda))
352 readbyte = readbyte_for_lambda;
353 goto read_multibyte;
356 if (EQ (readcharfun, Qget_file_char))
358 readbyte = readbyte_from_file;
359 goto read_multibyte;
362 if (STRINGP (readcharfun))
364 if (read_from_string_index >= read_from_string_limit)
365 c = -1;
366 else if (STRING_MULTIBYTE (readcharfun))
368 if (multibyte)
369 *multibyte = 1;
370 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, readcharfun,
371 read_from_string_index,
372 read_from_string_index_byte);
374 else
376 c = SREF (readcharfun, read_from_string_index_byte);
377 read_from_string_index++;
378 read_from_string_index_byte++;
380 return c;
383 if (CONSP (readcharfun))
385 /* This is the case that read_vector is reading from a unibyte
386 string that contains a byte sequence previously skipped
387 because of #@NUMBER. The car part of readcharfun is that
388 string, and the cdr part is a value of readcharfun given to
389 read_vector. */
390 readbyte = readbyte_from_string;
391 if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char))
392 emacs_mule_encoding = 1;
393 goto read_multibyte;
396 if (EQ (readcharfun, Qget_emacs_mule_file_char))
398 readbyte = readbyte_from_file;
399 emacs_mule_encoding = 1;
400 goto read_multibyte;
403 tem = call0 (readcharfun);
405 if (NILP (tem))
406 return -1;
407 return XINT (tem);
409 read_multibyte:
410 if (unread_char >= 0)
412 c = unread_char;
413 unread_char = -1;
414 return c;
416 c = (*readbyte) (-1, readcharfun);
417 if (c < 0 || load_each_byte)
418 return c;
419 if (multibyte)
420 *multibyte = 1;
421 if (ASCII_BYTE_P (c))
422 return c;
423 if (emacs_mule_encoding)
424 return read_emacs_mule_char (c, readbyte, readcharfun);
425 i = 0;
426 buf[i++] = c;
427 len = BYTES_BY_CHAR_HEAD (c);
428 while (i < len)
430 c = (*readbyte) (-1, readcharfun);
431 if (c < 0 || ! TRAILING_CODE_P (c))
433 while (--i > 1)
434 (*readbyte) (buf[i], readcharfun);
435 return BYTE8_TO_CHAR (buf[0]);
437 buf[i++] = c;
439 return STRING_CHAR (buf);
442 /* Unread the character C in the way appropriate for the stream READCHARFUN.
443 If the stream is a user function, call it with the char as argument. */
445 static void
446 unreadchar (readcharfun, c)
447 Lisp_Object readcharfun;
448 int c;
450 readchar_count--;
451 if (c == -1)
452 /* Don't back up the pointer if we're unreading the end-of-input mark,
453 since readchar didn't advance it when we read it. */
455 else if (BUFFERP (readcharfun))
457 struct buffer *b = XBUFFER (readcharfun);
458 int bytepos = BUF_PT_BYTE (b);
460 BUF_PT (b)--;
461 if (! NILP (b->enable_multibyte_characters))
462 BUF_DEC_POS (b, bytepos);
463 else
464 bytepos--;
466 BUF_PT_BYTE (b) = bytepos;
468 else if (MARKERP (readcharfun))
470 struct buffer *b = XMARKER (readcharfun)->buffer;
471 int bytepos = XMARKER (readcharfun)->bytepos;
473 XMARKER (readcharfun)->charpos--;
474 if (! NILP (b->enable_multibyte_characters))
475 BUF_DEC_POS (b, bytepos);
476 else
477 bytepos--;
479 XMARKER (readcharfun)->bytepos = bytepos;
481 else if (STRINGP (readcharfun))
483 read_from_string_index--;
484 read_from_string_index_byte
485 = string_char_to_byte (readcharfun, read_from_string_index);
487 else if (CONSP (readcharfun))
489 unread_char = c;
491 else if (EQ (readcharfun, Qlambda))
493 unread_char = c;
495 else if (EQ (readcharfun, Qget_file_char)
496 || EQ (readcharfun, Qget_emacs_mule_file_char))
498 if (load_each_byte)
500 BLOCK_INPUT;
501 ungetc (c, instream);
502 UNBLOCK_INPUT;
504 else
505 unread_char = c;
507 else
508 call1 (readcharfun, make_number (c));
511 static int
512 readbyte_for_lambda (c, readcharfun)
513 int c;
514 Lisp_Object readcharfun;
516 return read_bytecode_char (c >= 0);
520 static int
521 readbyte_from_file (c, readcharfun)
522 int c;
523 Lisp_Object readcharfun;
525 if (c >= 0)
527 BLOCK_INPUT;
528 ungetc (c, instream);
529 UNBLOCK_INPUT;
530 return 0;
533 BLOCK_INPUT;
534 c = getc (instream);
536 #ifdef EINTR
537 /* Interrupted reads have been observed while reading over the network */
538 while (c == EOF && ferror (instream) && errno == EINTR)
540 UNBLOCK_INPUT;
541 QUIT;
542 BLOCK_INPUT;
543 clearerr (instream);
544 c = getc (instream);
546 #endif
548 UNBLOCK_INPUT;
550 return (c == EOF ? -1 : c);
553 static int
554 readbyte_from_string (c, readcharfun)
555 int c;
556 Lisp_Object readcharfun;
558 Lisp_Object string = XCAR (readcharfun);
560 if (c >= 0)
562 read_from_string_index--;
563 read_from_string_index_byte
564 = string_char_to_byte (string, read_from_string_index);
567 if (read_from_string_index >= read_from_string_limit)
568 c = -1;
569 else
570 FETCH_STRING_CHAR_ADVANCE (c, string,
571 read_from_string_index,
572 read_from_string_index_byte);
573 return c;
577 /* Read one non-ASCII character from INSTREAM. The character is
578 encoded in `emacs-mule' and the first byte is already read in
579 C. */
581 extern char emacs_mule_bytes[256];
583 static int
584 read_emacs_mule_char (c, readbyte, readcharfun)
585 int c;
586 int (*readbyte) P_ ((int, Lisp_Object));
587 Lisp_Object readcharfun;
589 /* Emacs-mule coding uses at most 4-byte for one character. */
590 unsigned char buf[4];
591 int len = emacs_mule_bytes[c];
592 struct charset *charset;
593 int i;
594 unsigned code;
596 if (len == 1)
597 /* C is not a valid leading-code of `emacs-mule'. */
598 return BYTE8_TO_CHAR (c);
600 i = 0;
601 buf[i++] = c;
602 while (i < len)
604 c = (*readbyte) (-1, readcharfun);
605 if (c < 0xA0)
607 while (--i > 1)
608 (*readbyte) (buf[i], readcharfun);
609 return BYTE8_TO_CHAR (buf[0]);
611 buf[i++] = c;
614 if (len == 2)
616 charset = emacs_mule_charset[buf[0]];
617 code = buf[1] & 0x7F;
619 else if (len == 3)
621 if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11
622 || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12)
624 charset = emacs_mule_charset[buf[1]];
625 code = buf[2] & 0x7F;
627 else
629 charset = emacs_mule_charset[buf[0]];
630 code = ((buf[1] << 8) | buf[2]) & 0x7F7F;
633 else
635 charset = emacs_mule_charset[buf[1]];
636 code = ((buf[2] << 8) | buf[3]) & 0x7F7F;
638 c = DECODE_CHAR (charset, code);
639 if (c < 0)
640 Fsignal (Qinvalid_read_syntax,
641 Fcons (build_string ("invalid multibyte form"), Qnil));
642 return c;
646 static Lisp_Object read_internal_start P_ ((Lisp_Object, Lisp_Object,
647 Lisp_Object));
648 static Lisp_Object read0 P_ ((Lisp_Object));
649 static Lisp_Object read1 P_ ((Lisp_Object, int *, int));
651 static Lisp_Object read_list P_ ((int, Lisp_Object));
652 static Lisp_Object read_vector P_ ((Lisp_Object, int));
654 static Lisp_Object substitute_object_recurse P_ ((Lisp_Object, Lisp_Object,
655 Lisp_Object));
656 static void substitute_object_in_subtree P_ ((Lisp_Object,
657 Lisp_Object));
658 static void substitute_in_interval P_ ((INTERVAL, Lisp_Object));
661 /* Get a character from the tty. */
663 /* Read input events until we get one that's acceptable for our purposes.
665 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
666 until we get a character we like, and then stuffed into
667 unread_switch_frame.
669 If ASCII_REQUIRED is non-zero, we check function key events to see
670 if the unmodified version of the symbol has a Qascii_character
671 property, and use that character, if present.
673 If ERROR_NONASCII is non-zero, we signal an error if the input we
674 get isn't an ASCII character with modifiers. If it's zero but
675 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
676 character.
678 If INPUT_METHOD is nonzero, we invoke the current input method
679 if the character warrants that.
681 If SECONDS is a number, we wait that many seconds for input, and
682 return Qnil if no input arrives within that time. */
684 Lisp_Object
685 read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
686 input_method, seconds)
687 int no_switch_frame, ascii_required, error_nonascii, input_method;
688 Lisp_Object seconds;
690 Lisp_Object val, delayed_switch_frame;
691 EMACS_TIME end_time;
693 #ifdef HAVE_WINDOW_SYSTEM
694 if (display_hourglass_p)
695 cancel_hourglass ();
696 #endif
698 delayed_switch_frame = Qnil;
700 /* Compute timeout. */
701 if (NUMBERP (seconds))
703 EMACS_TIME wait_time;
704 int sec, usec;
705 double duration = extract_float (seconds);
707 sec = (int) duration;
708 usec = (duration - sec) * 1000000;
709 EMACS_GET_TIME (end_time);
710 EMACS_SET_SECS_USECS (wait_time, sec, usec);
711 EMACS_ADD_TIME (end_time, end_time, wait_time);
714 /* Read until we get an acceptable event. */
715 retry:
717 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0,
718 NUMBERP (seconds) ? &end_time : NULL);
719 while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */
721 if (BUFFERP (val))
722 goto retry;
724 /* switch-frame events are put off until after the next ASCII
725 character. This is better than signaling an error just because
726 the last characters were typed to a separate minibuffer frame,
727 for example. Eventually, some code which can deal with
728 switch-frame events will read it and process it. */
729 if (no_switch_frame
730 && EVENT_HAS_PARAMETERS (val)
731 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame))
733 delayed_switch_frame = val;
734 goto retry;
737 if (ascii_required && !(NUMBERP (seconds) && NILP (val)))
739 /* Convert certain symbols to their ASCII equivalents. */
740 if (SYMBOLP (val))
742 Lisp_Object tem, tem1;
743 tem = Fget (val, Qevent_symbol_element_mask);
744 if (!NILP (tem))
746 tem1 = Fget (Fcar (tem), Qascii_character);
747 /* Merge this symbol's modifier bits
748 with the ASCII equivalent of its basic code. */
749 if (!NILP (tem1))
750 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
754 /* If we don't have a character now, deal with it appropriately. */
755 if (!INTEGERP (val))
757 if (error_nonascii)
759 Vunread_command_events = Fcons (val, Qnil);
760 error ("Non-character input-event");
762 else
763 goto retry;
767 if (! NILP (delayed_switch_frame))
768 unread_switch_frame = delayed_switch_frame;
770 #if 0
772 #ifdef HAVE_WINDOW_SYSTEM
773 if (display_hourglass_p)
774 start_hourglass ();
775 #endif
777 #endif
779 return val;
782 DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
783 doc: /* Read a character from the command input (keyboard or macro).
784 It is returned as a number.
785 If the character has modifiers, they are resolved and reflected to the
786 character code if possible (e.g. C-SPC -> 0).
788 If the user generates an event which is not a character (i.e. a mouse
789 click or function key event), `read-char' signals an error. As an
790 exception, switch-frame events are put off until non-character events
791 can be read.
792 If you want to read non-character events, or ignore them, call
793 `read-event' or `read-char-exclusive' instead.
795 If the optional argument PROMPT is non-nil, display that as a prompt.
796 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
797 input method is turned on in the current buffer, that input method
798 is used for reading a character.
799 If the optional argument SECONDS is non-nil, it should be a number
800 specifying the maximum number of seconds to wait for input. If no
801 input arrives in that time, return nil. SECONDS may be a
802 floating-point value. */)
803 (prompt, inherit_input_method, seconds)
804 Lisp_Object prompt, inherit_input_method, seconds;
806 Lisp_Object val;
808 if (! NILP (prompt))
809 message_with_string ("%s", prompt, 0);
810 val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
812 return (NILP (val) ? Qnil
813 : make_number (char_resolve_modifier_mask (XINT (val))));
816 DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
817 doc: /* Read an event object from the input stream.
818 If the optional argument PROMPT is non-nil, display that as a prompt.
819 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
820 input method is turned on in the current buffer, that input method
821 is used for reading a character.
822 If the optional argument SECONDS is non-nil, it should be a number
823 specifying the maximum number of seconds to wait for input. If no
824 input arrives in that time, return nil. SECONDS may be a
825 floating-point value. */)
826 (prompt, inherit_input_method, seconds)
827 Lisp_Object prompt, inherit_input_method, seconds;
829 if (! NILP (prompt))
830 message_with_string ("%s", prompt, 0);
831 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds);
834 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0,
835 doc: /* Read a character from the command input (keyboard or macro).
836 It is returned as a number. Non-character events are ignored.
837 If the character has modifiers, they are resolved and reflected to the
838 character code if possible (e.g. C-SPC -> 0).
840 If the optional argument PROMPT is non-nil, display that as a prompt.
841 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
842 input method is turned on in the current buffer, that input method
843 is used for reading a character.
844 If the optional argument SECONDS is non-nil, it should be a number
845 specifying the maximum number of seconds to wait for input. If no
846 input arrives in that time, return nil. SECONDS may be a
847 floating-point value. */)
848 (prompt, inherit_input_method, seconds)
849 Lisp_Object prompt, inherit_input_method, seconds;
851 Lisp_Object val;
853 if (! NILP (prompt))
854 message_with_string ("%s", prompt, 0);
856 val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds);
858 return (NILP (val) ? Qnil
859 : make_number (char_resolve_modifier_mask (XINT (val))));
862 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
863 doc: /* Don't use this yourself. */)
866 register Lisp_Object val;
867 BLOCK_INPUT;
868 XSETINT (val, getc (instream));
869 UNBLOCK_INPUT;
870 return val;
875 /* Value is a version number of byte compiled code if the file
876 associated with file descriptor FD is a compiled Lisp file that's
877 safe to load. Only files compiled with Emacs are safe to load.
878 Files compiled with XEmacs can lead to a crash in Fbyte_code
879 because of an incompatible change in the byte compiler. */
881 static int
882 safe_to_load_p (fd)
883 int fd;
885 char buf[512];
886 int nbytes, i;
887 int safe_p = 1;
888 int version = 1;
890 /* Read the first few bytes from the file, and look for a line
891 specifying the byte compiler version used. */
892 nbytes = emacs_read (fd, buf, sizeof buf - 1);
893 if (nbytes > 0)
895 buf[nbytes] = '\0';
897 /* Skip to the next newline, skipping over the initial `ELC'
898 with NUL bytes following it, but note the version. */
899 for (i = 0; i < nbytes && buf[i] != '\n'; ++i)
900 if (i == 4)
901 version = buf[i];
903 if (i == nbytes
904 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
905 buf + i) < 0)
906 safe_p = 0;
908 if (safe_p)
909 safe_p = version;
911 lseek (fd, 0, SEEK_SET);
912 return safe_p;
916 /* Callback for record_unwind_protect. Restore the old load list OLD,
917 after loading a file successfully. */
919 static Lisp_Object
920 record_load_unwind (old)
921 Lisp_Object old;
923 return Vloads_in_progress = old;
926 /* This handler function is used via internal_condition_case_1. */
928 static Lisp_Object
929 load_error_handler (data)
930 Lisp_Object data;
932 return Qnil;
935 static Lisp_Object
936 load_warn_old_style_backquotes (file)
937 Lisp_Object file;
939 if (!NILP (Vold_style_backquotes))
941 Lisp_Object args[2];
942 args[0] = build_string ("Loading `%s': old-style backquotes detected!");
943 args[1] = file;
944 Fmessage (2, args);
946 return Qnil;
949 DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
950 doc: /* Return the suffixes that `load' should try if a suffix is \
951 required.
952 This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
955 Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext;
956 while (CONSP (suffixes))
958 Lisp_Object exts = Vload_file_rep_suffixes;
959 suffix = XCAR (suffixes);
960 suffixes = XCDR (suffixes);
961 while (CONSP (exts))
963 ext = XCAR (exts);
964 exts = XCDR (exts);
965 lst = Fcons (concat2 (suffix, ext), lst);
968 return Fnreverse (lst);
971 DEFUN ("load", Fload, Sload, 1, 5, 0,
972 doc: /* Execute a file of Lisp code named FILE.
973 First try FILE with `.elc' appended, then try with `.el',
974 then try FILE unmodified (the exact suffixes in the exact order are
975 determined by `load-suffixes'). Environment variable references in
976 FILE are replaced with their values by calling `substitute-in-file-name'.
977 This function searches the directories in `load-path'.
979 If optional second arg NOERROR is non-nil,
980 report no error if FILE doesn't exist.
981 Print messages at start and end of loading unless
982 optional third arg NOMESSAGE is non-nil (but `force-load-messages'
983 overrides that).
984 If optional fourth arg NOSUFFIX is non-nil, don't try adding
985 suffixes `.elc' or `.el' to the specified name FILE.
986 If optional fifth arg MUST-SUFFIX is non-nil, insist on
987 the suffix `.elc' or `.el'; don't accept just FILE unless
988 it ends in one of those suffixes or includes a directory name.
990 If this function fails to find a file, it may look for different
991 representations of that file before trying another file.
992 It does so by adding the non-empty suffixes in `load-file-rep-suffixes'
993 to the file name. Emacs uses this feature mainly to find compressed
994 versions of files when Auto Compression mode is enabled.
996 The exact suffixes that this function tries out, in the exact order,
997 are given by the value of the variable `load-file-rep-suffixes' if
998 NOSUFFIX is non-nil and by the return value of the function
999 `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and
1000 MUST-SUFFIX are nil, this function first tries out the latter suffixes
1001 and then the former.
1003 Loading a file records its definitions, and its `provide' and
1004 `require' calls, in an element of `load-history' whose
1005 car is the file name loaded. See `load-history'.
1007 Return t if the file exists and loads successfully. */)
1008 (file, noerror, nomessage, nosuffix, must_suffix)
1009 Lisp_Object file, noerror, nomessage, nosuffix, must_suffix;
1011 register FILE *stream;
1012 register int fd = -1;
1013 int count = SPECPDL_INDEX ();
1014 struct gcpro gcpro1, gcpro2, gcpro3;
1015 Lisp_Object found, efound, hist_file_name;
1016 /* 1 means we printed the ".el is newer" message. */
1017 int newer = 0;
1018 /* 1 means we are loading a compiled file. */
1019 int compiled = 0;
1020 Lisp_Object handler;
1021 int safe_p = 1;
1022 char *fmode = "r";
1023 Lisp_Object tmp[2];
1024 int version;
1026 #ifdef DOS_NT
1027 fmode = "rt";
1028 #endif /* DOS_NT */
1030 CHECK_STRING (file);
1032 /* If file name is magic, call the handler. */
1033 /* This shouldn't be necessary any more now that `openp' handles it right.
1034 handler = Ffind_file_name_handler (file, Qload);
1035 if (!NILP (handler))
1036 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
1038 /* Do this after the handler to avoid
1039 the need to gcpro noerror, nomessage and nosuffix.
1040 (Below here, we care only whether they are nil or not.)
1041 The presence of this call is the result of a historical accident:
1042 it used to be in every file-operation and when it got removed
1043 everywhere, it accidentally stayed here. Since then, enough people
1044 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
1045 that it seemed risky to remove. */
1046 if (! NILP (noerror))
1048 file = internal_condition_case_1 (Fsubstitute_in_file_name, file,
1049 Qt, load_error_handler);
1050 if (NILP (file))
1051 return Qnil;
1053 else
1054 file = Fsubstitute_in_file_name (file);
1057 /* Avoid weird lossage with null string as arg,
1058 since it would try to load a directory as a Lisp file */
1059 if (SCHARS (file) > 0)
1061 int size = SBYTES (file);
1063 found = Qnil;
1064 GCPRO2 (file, found);
1066 if (! NILP (must_suffix))
1068 /* Don't insist on adding a suffix if FILE already ends with one. */
1069 if (size > 3
1070 && !strcmp (SDATA (file) + size - 3, ".el"))
1071 must_suffix = Qnil;
1072 else if (size > 4
1073 && !strcmp (SDATA (file) + size - 4, ".elc"))
1074 must_suffix = Qnil;
1075 /* Don't insist on adding a suffix
1076 if the argument includes a directory name. */
1077 else if (! NILP (Ffile_name_directory (file)))
1078 must_suffix = Qnil;
1081 fd = openp (Vload_path, file,
1082 (!NILP (nosuffix) ? Qnil
1083 : !NILP (must_suffix) ? Fget_load_suffixes ()
1084 : Fappend (2, (tmp[0] = Fget_load_suffixes (),
1085 tmp[1] = Vload_file_rep_suffixes,
1086 tmp))),
1087 &found, Qnil);
1088 UNGCPRO;
1091 if (fd == -1)
1093 if (NILP (noerror))
1094 xsignal2 (Qfile_error, build_string ("Cannot open load file"), file);
1095 return Qnil;
1098 /* Tell startup.el whether or not we found the user's init file. */
1099 if (EQ (Qt, Vuser_init_file))
1100 Vuser_init_file = found;
1102 /* If FD is -2, that means openp found a magic file. */
1103 if (fd == -2)
1105 if (NILP (Fequal (found, file)))
1106 /* If FOUND is a different file name from FILE,
1107 find its handler even if we have already inhibited
1108 the `load' operation on FILE. */
1109 handler = Ffind_file_name_handler (found, Qt);
1110 else
1111 handler = Ffind_file_name_handler (found, Qload);
1112 if (! NILP (handler))
1113 return call5 (handler, Qload, found, noerror, nomessage, Qt);
1116 /* Check if we're stuck in a recursive load cycle.
1118 2000-09-21: It's not possible to just check for the file loaded
1119 being a member of Vloads_in_progress. This fails because of the
1120 way the byte compiler currently works; `provide's are not
1121 evaluated, see font-lock.el/jit-lock.el as an example. This
1122 leads to a certain amount of ``normal'' recursion.
1124 Also, just loading a file recursively is not always an error in
1125 the general case; the second load may do something different. */
1127 int count = 0;
1128 Lisp_Object tem;
1129 for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
1130 if (!NILP (Fequal (found, XCAR (tem))) && (++count > 3))
1132 if (fd >= 0)
1133 emacs_close (fd);
1134 signal_error ("Recursive load", Fcons (found, Vloads_in_progress));
1136 record_unwind_protect (record_load_unwind, Vloads_in_progress);
1137 Vloads_in_progress = Fcons (found, Vloads_in_progress);
1140 /* Get the name for load-history. */
1141 hist_file_name = (! NILP (Vpurify_flag)
1142 ? Fconcat (2, (tmp[0] = Ffile_name_directory (file),
1143 tmp[1] = Ffile_name_nondirectory (found),
1144 tmp))
1145 : found) ;
1147 version = -1;
1149 /* Check for the presence of old-style quotes and warn about them. */
1150 specbind (Qold_style_backquotes, Qnil);
1151 record_unwind_protect (load_warn_old_style_backquotes, file);
1153 if (!bcmp (SDATA (found) + SBYTES (found) - 4,
1154 ".elc", 4)
1155 || (fd >= 0 && (version = safe_to_load_p (fd)) > 0))
1156 /* Load .elc files directly, but not when they are
1157 remote and have no handler! */
1159 if (fd != -2)
1161 struct stat s1, s2;
1162 int result;
1164 GCPRO3 (file, found, hist_file_name);
1166 if (version < 0
1167 && ! (version = safe_to_load_p (fd)))
1169 safe_p = 0;
1170 if (!load_dangerous_libraries)
1172 if (fd >= 0)
1173 emacs_close (fd);
1174 error ("File `%s' was not compiled in Emacs",
1175 SDATA (found));
1177 else if (!NILP (nomessage) && !force_load_messages)
1178 message_with_string ("File `%s' not compiled in Emacs", found, 1);
1181 compiled = 1;
1183 efound = ENCODE_FILE (found);
1185 #ifdef DOS_NT
1186 fmode = "rb";
1187 #endif /* DOS_NT */
1188 stat ((char *)SDATA (efound), &s1);
1189 SSET (efound, SBYTES (efound) - 1, 0);
1190 result = stat ((char *)SDATA (efound), &s2);
1191 SSET (efound, SBYTES (efound) - 1, 'c');
1193 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
1195 /* Make the progress messages mention that source is newer. */
1196 newer = 1;
1198 /* If we won't print another message, mention this anyway. */
1199 if (!NILP (nomessage) && !force_load_messages)
1201 Lisp_Object msg_file;
1202 msg_file = Fsubstring (found, make_number (0), make_number (-1));
1203 message_with_string ("Source file `%s' newer than byte-compiled file",
1204 msg_file, 1);
1207 UNGCPRO;
1210 else
1212 /* We are loading a source file (*.el). */
1213 if (!NILP (Vload_source_file_function))
1215 Lisp_Object val;
1217 if (fd >= 0)
1218 emacs_close (fd);
1219 val = call4 (Vload_source_file_function, found, hist_file_name,
1220 NILP (noerror) ? Qnil : Qt,
1221 (NILP (nomessage) || force_load_messages) ? Qnil : Qt);
1222 return unbind_to (count, val);
1226 GCPRO3 (file, found, hist_file_name);
1228 #ifdef WINDOWSNT
1229 emacs_close (fd);
1230 efound = ENCODE_FILE (found);
1231 stream = fopen ((char *) SDATA (efound), fmode);
1232 #else /* not WINDOWSNT */
1233 stream = fdopen (fd, fmode);
1234 #endif /* not WINDOWSNT */
1235 if (stream == 0)
1237 emacs_close (fd);
1238 error ("Failure to create stdio stream for %s", SDATA (file));
1241 if (! NILP (Vpurify_flag))
1242 Vpreloaded_file_list = Fcons (Fpurecopy(file), Vpreloaded_file_list);
1244 if (NILP (nomessage) || force_load_messages)
1246 if (!safe_p)
1247 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
1248 file, 1);
1249 else if (!compiled)
1250 message_with_string ("Loading %s (source)...", file, 1);
1251 else if (newer)
1252 message_with_string ("Loading %s (compiled; note, source file is newer)...",
1253 file, 1);
1254 else /* The typical case; compiled file newer than source file. */
1255 message_with_string ("Loading %s...", file, 1);
1258 record_unwind_protect (load_unwind, make_save_value (stream, 0));
1259 record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
1260 specbind (Qload_file_name, found);
1261 specbind (Qinhibit_file_name_operation, Qnil);
1262 load_descriptor_list
1263 = Fcons (make_number (fileno (stream)), load_descriptor_list);
1264 specbind (Qload_in_progress, Qt);
1265 if (! version || version >= 22)
1266 readevalloop (Qget_file_char, stream, hist_file_name,
1267 Feval, 0, Qnil, Qnil, Qnil, Qnil);
1268 else
1270 /* We can't handle a file which was compiled with
1271 byte-compile-dynamic by older version of Emacs. */
1272 specbind (Qload_force_doc_strings, Qt);
1273 readevalloop (Qget_emacs_mule_file_char, stream, hist_file_name, Feval,
1274 0, Qnil, Qnil, Qnil, Qnil);
1276 unbind_to (count, Qnil);
1278 /* Run any eval-after-load forms for this file */
1279 if (!NILP (Ffboundp (Qdo_after_load_evaluation)))
1280 call1 (Qdo_after_load_evaluation, hist_file_name) ;
1282 UNGCPRO;
1284 xfree (saved_doc_string);
1285 saved_doc_string = 0;
1286 saved_doc_string_size = 0;
1288 xfree (prev_saved_doc_string);
1289 prev_saved_doc_string = 0;
1290 prev_saved_doc_string_size = 0;
1292 if (!noninteractive && (NILP (nomessage) || force_load_messages))
1294 if (!safe_p)
1295 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
1296 file, 1);
1297 else if (!compiled)
1298 message_with_string ("Loading %s (source)...done", file, 1);
1299 else if (newer)
1300 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
1301 file, 1);
1302 else /* The typical case; compiled file newer than source file. */
1303 message_with_string ("Loading %s...done", file, 1);
1306 return Qt;
1309 static Lisp_Object
1310 load_unwind (arg) /* used as unwind-protect function in load */
1311 Lisp_Object arg;
1313 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
1314 if (stream != NULL)
1316 BLOCK_INPUT;
1317 fclose (stream);
1318 UNBLOCK_INPUT;
1320 return Qnil;
1323 static Lisp_Object
1324 load_descriptor_unwind (oldlist)
1325 Lisp_Object oldlist;
1327 load_descriptor_list = oldlist;
1328 return Qnil;
1331 /* Close all descriptors in use for Floads.
1332 This is used when starting a subprocess. */
1334 void
1335 close_load_descs ()
1337 #ifndef WINDOWSNT
1338 Lisp_Object tail;
1339 for (tail = load_descriptor_list; CONSP (tail); tail = XCDR (tail))
1340 emacs_close (XFASTINT (XCAR (tail)));
1341 #endif
1344 static int
1345 complete_filename_p (pathname)
1346 Lisp_Object pathname;
1348 register const unsigned char *s = SDATA (pathname);
1349 return (IS_DIRECTORY_SEP (s[0])
1350 || (SCHARS (pathname) > 2
1351 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])));
1354 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
1355 doc: /* Search for FILENAME through PATH.
1356 Returns the file's name in absolute form, or nil if not found.
1357 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1358 file name when searching.
1359 If non-nil, PREDICATE is used instead of `file-readable-p'.
1360 PREDICATE can also be an integer to pass to the access(2) function,
1361 in which case file-name-handlers are ignored. */)
1362 (filename, path, suffixes, predicate)
1363 Lisp_Object filename, path, suffixes, predicate;
1365 Lisp_Object file;
1366 int fd = openp (path, filename, suffixes, &file, predicate);
1367 if (NILP (predicate) && fd > 0)
1368 close (fd);
1369 return file;
1373 /* Search for a file whose name is STR, looking in directories
1374 in the Lisp list PATH, and trying suffixes from SUFFIX.
1375 On success, returns a file descriptor. On failure, returns -1.
1377 SUFFIXES is a list of strings containing possible suffixes.
1378 The empty suffix is automatically added if the list is empty.
1380 PREDICATE non-nil means don't open the files,
1381 just look for one that satisfies the predicate. In this case,
1382 returns 1 on success. The predicate can be a lisp function or
1383 an integer to pass to `access' (in which case file-name-handlers
1384 are ignored).
1386 If STOREPTR is nonzero, it points to a slot where the name of
1387 the file actually found should be stored as a Lisp string.
1388 nil is stored there on failure.
1390 If the file we find is remote, return -2
1391 but store the found remote file name in *STOREPTR. */
1394 openp (path, str, suffixes, storeptr, predicate)
1395 Lisp_Object path, str;
1396 Lisp_Object suffixes;
1397 Lisp_Object *storeptr;
1398 Lisp_Object predicate;
1400 register int fd;
1401 int fn_size = 100;
1402 char buf[100];
1403 register char *fn = buf;
1404 int absolute = 0;
1405 int want_size;
1406 Lisp_Object filename;
1407 struct stat st;
1408 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1409 Lisp_Object string, tail, encoded_fn;
1410 int max_suffix_len = 0;
1412 CHECK_STRING (str);
1414 for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
1416 CHECK_STRING_CAR (tail);
1417 max_suffix_len = max (max_suffix_len,
1418 SBYTES (XCAR (tail)));
1421 string = filename = encoded_fn = Qnil;
1422 GCPRO6 (str, string, filename, path, suffixes, encoded_fn);
1424 if (storeptr)
1425 *storeptr = Qnil;
1427 if (complete_filename_p (str))
1428 absolute = 1;
1430 for (; CONSP (path); path = XCDR (path))
1432 filename = Fexpand_file_name (str, XCAR (path));
1433 if (!complete_filename_p (filename))
1434 /* If there are non-absolute elts in PATH (eg ".") */
1435 /* Of course, this could conceivably lose if luser sets
1436 default-directory to be something non-absolute... */
1438 filename = Fexpand_file_name (filename, current_buffer->directory);
1439 if (!complete_filename_p (filename))
1440 /* Give up on this path element! */
1441 continue;
1444 /* Calculate maximum size of any filename made from
1445 this path element/specified file name and any possible suffix. */
1446 want_size = max_suffix_len + SBYTES (filename) + 1;
1447 if (fn_size < want_size)
1448 fn = (char *) alloca (fn_size = 100 + want_size);
1450 /* Loop over suffixes. */
1451 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1452 CONSP (tail); tail = XCDR (tail))
1454 int lsuffix = SBYTES (XCAR (tail));
1455 Lisp_Object handler;
1456 int exists;
1458 /* Concatenate path element/specified name with the suffix.
1459 If the directory starts with /:, remove that. */
1460 if (SCHARS (filename) > 2
1461 && SREF (filename, 0) == '/'
1462 && SREF (filename, 1) == ':')
1464 strncpy (fn, SDATA (filename) + 2,
1465 SBYTES (filename) - 2);
1466 fn[SBYTES (filename) - 2] = 0;
1468 else
1470 strncpy (fn, SDATA (filename),
1471 SBYTES (filename));
1472 fn[SBYTES (filename)] = 0;
1475 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1476 strncat (fn, SDATA (XCAR (tail)), lsuffix);
1478 /* Check that the file exists and is not a directory. */
1479 /* We used to only check for handlers on non-absolute file names:
1480 if (absolute)
1481 handler = Qnil;
1482 else
1483 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1484 It's not clear why that was the case and it breaks things like
1485 (load "/bar.el") where the file is actually "/bar.el.gz". */
1486 string = build_string (fn);
1487 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1488 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1490 if (NILP (predicate))
1491 exists = !NILP (Ffile_readable_p (string));
1492 else
1493 exists = !NILP (call1 (predicate, string));
1494 if (exists && !NILP (Ffile_directory_p (string)))
1495 exists = 0;
1497 if (exists)
1499 /* We succeeded; return this descriptor and filename. */
1500 if (storeptr)
1501 *storeptr = string;
1502 UNGCPRO;
1503 return -2;
1506 else
1508 const char *pfn;
1510 encoded_fn = ENCODE_FILE (string);
1511 pfn = SDATA (encoded_fn);
1512 exists = (stat (pfn, &st) >= 0
1513 && (st.st_mode & S_IFMT) != S_IFDIR);
1514 if (exists)
1516 /* Check that we can access or open it. */
1517 if (NATNUMP (predicate))
1518 fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1;
1519 else
1520 fd = emacs_open (pfn, O_RDONLY, 0);
1522 if (fd >= 0)
1524 /* We succeeded; return this descriptor and filename. */
1525 if (storeptr)
1526 *storeptr = string;
1527 UNGCPRO;
1528 return fd;
1533 if (absolute)
1534 break;
1537 UNGCPRO;
1538 return -1;
1542 /* Merge the list we've accumulated of globals from the current input source
1543 into the load_history variable. The details depend on whether
1544 the source has an associated file name or not.
1546 FILENAME is the file name that we are loading from.
1547 ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */
1549 static void
1550 build_load_history (filename, entire)
1551 Lisp_Object filename;
1552 int entire;
1554 register Lisp_Object tail, prev, newelt;
1555 register Lisp_Object tem, tem2;
1556 register int foundit = 0;
1558 tail = Vload_history;
1559 prev = Qnil;
1561 while (CONSP (tail))
1563 tem = XCAR (tail);
1565 /* Find the feature's previous assoc list... */
1566 if (!NILP (Fequal (filename, Fcar (tem))))
1568 foundit = 1;
1570 /* If we're loading the entire file, remove old data. */
1571 if (entire)
1573 if (NILP (prev))
1574 Vload_history = XCDR (tail);
1575 else
1576 Fsetcdr (prev, XCDR (tail));
1579 /* Otherwise, cons on new symbols that are not already members. */
1580 else
1582 tem2 = Vcurrent_load_list;
1584 while (CONSP (tem2))
1586 newelt = XCAR (tem2);
1588 if (NILP (Fmember (newelt, tem)))
1589 Fsetcar (tail, Fcons (XCAR (tem),
1590 Fcons (newelt, XCDR (tem))));
1592 tem2 = XCDR (tem2);
1593 QUIT;
1597 else
1598 prev = tail;
1599 tail = XCDR (tail);
1600 QUIT;
1603 /* If we're loading an entire file, cons the new assoc onto the
1604 front of load-history, the most-recently-loaded position. Also
1605 do this if we didn't find an existing member for the file. */
1606 if (entire || !foundit)
1607 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1608 Vload_history);
1611 Lisp_Object
1612 unreadpure (junk) /* Used as unwind-protect function in readevalloop */
1613 Lisp_Object junk;
1615 read_pure = 0;
1616 return Qnil;
1619 static Lisp_Object
1620 readevalloop_1 (old)
1621 Lisp_Object old;
1623 load_convert_to_unibyte = ! NILP (old);
1624 return Qnil;
1627 /* Signal an `end-of-file' error, if possible with file name
1628 information. */
1630 static void
1631 end_of_file_error ()
1633 if (STRINGP (Vload_file_name))
1634 xsignal1 (Qend_of_file, Vload_file_name);
1636 xsignal0 (Qend_of_file);
1639 /* UNIBYTE specifies how to set load_convert_to_unibyte
1640 for this invocation.
1641 READFUN, if non-nil, is used instead of `read'.
1643 START, END specify region to read in current buffer (from eval-region).
1644 If the input is not from a buffer, they must be nil. */
1646 static void
1647 readevalloop (readcharfun, stream, sourcename, evalfun,
1648 printflag, unibyte, readfun, start, end)
1649 Lisp_Object readcharfun;
1650 FILE *stream;
1651 Lisp_Object sourcename;
1652 Lisp_Object (*evalfun) ();
1653 int printflag;
1654 Lisp_Object unibyte, readfun;
1655 Lisp_Object start, end;
1657 register int c;
1658 register Lisp_Object val;
1659 int count = SPECPDL_INDEX ();
1660 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1661 struct buffer *b = 0;
1662 int continue_reading_p;
1663 /* Nonzero if reading an entire buffer. */
1664 int whole_buffer = 0;
1665 /* 1 on the first time around. */
1666 int first_sexp = 1;
1668 if (MARKERP (readcharfun))
1670 if (NILP (start))
1671 start = readcharfun;
1674 if (BUFFERP (readcharfun))
1675 b = XBUFFER (readcharfun);
1676 else if (MARKERP (readcharfun))
1677 b = XMARKER (readcharfun)->buffer;
1679 /* We assume START is nil when input is not from a buffer. */
1680 if (! NILP (start) && !b)
1681 abort ();
1683 specbind (Qstandard_input, readcharfun); /* GCPROs readcharfun. */
1684 specbind (Qcurrent_load_list, Qnil);
1685 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
1686 load_convert_to_unibyte = !NILP (unibyte);
1688 GCPRO4 (sourcename, readfun, start, end);
1690 /* Try to ensure sourcename is a truename, except whilst preloading. */
1691 if (NILP (Vpurify_flag)
1692 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename))
1693 && !NILP (Ffboundp (Qfile_truename)))
1694 sourcename = call1 (Qfile_truename, sourcename) ;
1696 LOADHIST_ATTACH (sourcename);
1698 continue_reading_p = 1;
1699 while (continue_reading_p)
1701 int count1 = SPECPDL_INDEX ();
1703 if (b != 0 && NILP (b->name))
1704 error ("Reading from killed buffer");
1706 if (!NILP (start))
1708 /* Switch to the buffer we are reading from. */
1709 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1710 set_buffer_internal (b);
1712 /* Save point in it. */
1713 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1714 /* Save ZV in it. */
1715 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1716 /* Those get unbound after we read one expression. */
1718 /* Set point and ZV around stuff to be read. */
1719 Fgoto_char (start);
1720 if (!NILP (end))
1721 Fnarrow_to_region (make_number (BEGV), end);
1723 /* Just for cleanliness, convert END to a marker
1724 if it is an integer. */
1725 if (INTEGERP (end))
1726 end = Fpoint_max_marker ();
1729 /* On the first cycle, we can easily test here
1730 whether we are reading the whole buffer. */
1731 if (b && first_sexp)
1732 whole_buffer = (PT == BEG && ZV == Z);
1734 instream = stream;
1735 read_next:
1736 c = READCHAR;
1737 if (c == ';')
1739 while ((c = READCHAR) != '\n' && c != -1);
1740 goto read_next;
1742 if (c < 0)
1744 unbind_to (count1, Qnil);
1745 break;
1748 /* Ignore whitespace here, so we can detect eof. */
1749 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'
1750 || c == 0x8a0) /* NBSP */
1751 goto read_next;
1753 if (!NILP (Vpurify_flag) && c == '(')
1755 record_unwind_protect (unreadpure, Qnil);
1756 val = read_list (-1, readcharfun);
1758 else
1760 UNREAD (c);
1761 read_objects = Qnil;
1762 if (!NILP (readfun))
1764 val = call1 (readfun, readcharfun);
1766 /* If READCHARFUN has set point to ZV, we should
1767 stop reading, even if the form read sets point
1768 to a different value when evaluated. */
1769 if (BUFFERP (readcharfun))
1771 struct buffer *b = XBUFFER (readcharfun);
1772 if (BUF_PT (b) == BUF_ZV (b))
1773 continue_reading_p = 0;
1776 else if (! NILP (Vload_read_function))
1777 val = call1 (Vload_read_function, readcharfun);
1778 else
1779 val = read_internal_start (readcharfun, Qnil, Qnil);
1782 if (!NILP (start) && continue_reading_p)
1783 start = Fpoint_marker ();
1785 /* Restore saved point and BEGV. */
1786 unbind_to (count1, Qnil);
1788 /* Now eval what we just read. */
1789 val = (*evalfun) (val);
1791 if (printflag)
1793 Vvalues = Fcons (val, Vvalues);
1794 if (EQ (Vstandard_output, Qt))
1795 Fprin1 (val, Qnil);
1796 else
1797 Fprint (val, Qnil);
1800 first_sexp = 0;
1803 build_load_history (sourcename,
1804 stream || whole_buffer);
1806 UNGCPRO;
1808 unbind_to (count, Qnil);
1811 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
1812 doc: /* Execute the current buffer as Lisp code.
1813 When called from a Lisp program (i.e., not interactively), this
1814 function accepts up to five optional arguments:
1815 BUFFER is the buffer to evaluate (nil means use current buffer).
1816 PRINTFLAG controls printing of output:
1817 A value of nil means discard it; anything else is stream for print.
1818 FILENAME specifies the file name to use for `load-history'.
1819 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
1820 invocation.
1821 DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1822 functions should work normally even if PRINTFLAG is nil.
1824 This function preserves the position of point. */)
1825 (buffer, printflag, filename, unibyte, do_allow_print)
1826 Lisp_Object buffer, printflag, filename, unibyte, do_allow_print;
1828 int count = SPECPDL_INDEX ();
1829 Lisp_Object tem, buf;
1831 if (NILP (buffer))
1832 buf = Fcurrent_buffer ();
1833 else
1834 buf = Fget_buffer (buffer);
1835 if (NILP (buf))
1836 error ("No such buffer");
1838 if (NILP (printflag) && NILP (do_allow_print))
1839 tem = Qsymbolp;
1840 else
1841 tem = printflag;
1843 if (NILP (filename))
1844 filename = XBUFFER (buf)->filename;
1846 specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
1847 specbind (Qstandard_output, tem);
1848 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1849 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
1850 readevalloop (buf, 0, filename, Feval,
1851 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
1852 unbind_to (count, Qnil);
1854 return Qnil;
1857 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
1858 doc: /* Execute the region as Lisp code.
1859 When called from programs, expects two arguments,
1860 giving starting and ending indices in the current buffer
1861 of the text to be executed.
1862 Programs can pass third argument PRINTFLAG which controls output:
1863 A value of nil means discard it; anything else is stream for printing it.
1864 Also the fourth argument READ-FUNCTION, if non-nil, is used
1865 instead of `read' to read each expression. It gets one argument
1866 which is the input stream for reading characters.
1868 This function does not move point. */)
1869 (start, end, printflag, read_function)
1870 Lisp_Object start, end, printflag, read_function;
1872 int count = SPECPDL_INDEX ();
1873 Lisp_Object tem, cbuf;
1875 cbuf = Fcurrent_buffer ();
1877 if (NILP (printflag))
1878 tem = Qsymbolp;
1879 else
1880 tem = printflag;
1881 specbind (Qstandard_output, tem);
1882 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list));
1884 /* readevalloop calls functions which check the type of start and end. */
1885 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
1886 !NILP (printflag), Qnil, read_function,
1887 start, end);
1889 return unbind_to (count, Qnil);
1893 DEFUN ("read", Fread, Sread, 0, 1, 0,
1894 doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1895 If STREAM is nil, use the value of `standard-input' (which see).
1896 STREAM or the value of `standard-input' may be:
1897 a buffer (read from point and advance it)
1898 a marker (read from where it points and advance it)
1899 a function (call it with no arguments for each character,
1900 call it with a char as argument to push a char back)
1901 a string (takes text from string, starting at the beginning)
1902 t (read text line using minibuffer and use it, or read from
1903 standard input in batch mode). */)
1904 (stream)
1905 Lisp_Object stream;
1907 if (NILP (stream))
1908 stream = Vstandard_input;
1909 if (EQ (stream, Qt))
1910 stream = Qread_char;
1911 if (EQ (stream, Qread_char))
1912 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
1914 return read_internal_start (stream, Qnil, Qnil);
1917 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
1918 doc: /* Read one Lisp expression which is represented as text by STRING.
1919 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1920 START and END optionally delimit a substring of STRING from which to read;
1921 they default to 0 and (length STRING) respectively. */)
1922 (string, start, end)
1923 Lisp_Object string, start, end;
1925 Lisp_Object ret;
1926 CHECK_STRING (string);
1927 /* read_internal_start sets read_from_string_index. */
1928 ret = read_internal_start (string, start, end);
1929 return Fcons (ret, make_number (read_from_string_index));
1932 /* Function to set up the global context we need in toplevel read
1933 calls. */
1934 static Lisp_Object
1935 read_internal_start (stream, start, end)
1936 Lisp_Object stream;
1937 Lisp_Object start; /* Only used when stream is a string. */
1938 Lisp_Object end; /* Only used when stream is a string. */
1940 Lisp_Object retval;
1942 readchar_count = 0;
1943 new_backquote_flag = 0;
1944 read_objects = Qnil;
1945 if (EQ (Vread_with_symbol_positions, Qt)
1946 || EQ (Vread_with_symbol_positions, stream))
1947 Vread_symbol_positions_list = Qnil;
1949 if (STRINGP (stream)
1950 || ((CONSP (stream) && STRINGP (XCAR (stream)))))
1952 int startval, endval;
1953 Lisp_Object string;
1955 if (STRINGP (stream))
1956 string = stream;
1957 else
1958 string = XCAR (stream);
1960 if (NILP (end))
1961 endval = SCHARS (string);
1962 else
1964 CHECK_NUMBER (end);
1965 endval = XINT (end);
1966 if (endval < 0 || endval > SCHARS (string))
1967 args_out_of_range (string, end);
1970 if (NILP (start))
1971 startval = 0;
1972 else
1974 CHECK_NUMBER (start);
1975 startval = XINT (start);
1976 if (startval < 0 || startval > endval)
1977 args_out_of_range (string, start);
1979 read_from_string_index = startval;
1980 read_from_string_index_byte = string_char_to_byte (string, startval);
1981 read_from_string_limit = endval;
1984 retval = read0 (stream);
1985 if (EQ (Vread_with_symbol_positions, Qt)
1986 || EQ (Vread_with_symbol_positions, stream))
1987 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list);
1988 return retval;
1992 /* Signal Qinvalid_read_syntax error.
1993 S is error string of length N (if > 0) */
1995 static void
1996 invalid_syntax (s, n)
1997 const char *s;
1998 int n;
2000 if (!n)
2001 n = strlen (s);
2002 xsignal1 (Qinvalid_read_syntax, make_string (s, n));
2006 /* Use this for recursive reads, in contexts where internal tokens
2007 are not allowed. */
2009 static Lisp_Object
2010 read0 (readcharfun)
2011 Lisp_Object readcharfun;
2013 register Lisp_Object val;
2014 int c;
2016 val = read1 (readcharfun, &c, 0);
2017 if (!c)
2018 return val;
2020 xsignal1 (Qinvalid_read_syntax,
2021 Fmake_string (make_number (1), make_number (c)));
2024 static int read_buffer_size;
2025 static char *read_buffer;
2027 /* Read a \-escape sequence, assuming we already read the `\'.
2028 If the escape sequence forces unibyte, return eight-bit char. */
2030 static int
2031 read_escape (readcharfun, stringp)
2032 Lisp_Object readcharfun;
2033 int stringp;
2035 register int c = READCHAR;
2036 /* \u allows up to four hex digits, \U up to eight. Default to the
2037 behavior for \u, and change this value in the case that \U is seen. */
2038 int unicode_hex_count = 4;
2040 switch (c)
2042 case -1:
2043 end_of_file_error ();
2045 case 'a':
2046 return '\007';
2047 case 'b':
2048 return '\b';
2049 case 'd':
2050 return 0177;
2051 case 'e':
2052 return 033;
2053 case 'f':
2054 return '\f';
2055 case 'n':
2056 return '\n';
2057 case 'r':
2058 return '\r';
2059 case 't':
2060 return '\t';
2061 case 'v':
2062 return '\v';
2063 case '\n':
2064 return -1;
2065 case ' ':
2066 if (stringp)
2067 return -1;
2068 return ' ';
2070 case 'M':
2071 c = READCHAR;
2072 if (c != '-')
2073 error ("Invalid escape character syntax");
2074 c = READCHAR;
2075 if (c == '\\')
2076 c = read_escape (readcharfun, 0);
2077 return c | meta_modifier;
2079 case 'S':
2080 c = READCHAR;
2081 if (c != '-')
2082 error ("Invalid escape character syntax");
2083 c = READCHAR;
2084 if (c == '\\')
2085 c = read_escape (readcharfun, 0);
2086 return c | shift_modifier;
2088 case 'H':
2089 c = READCHAR;
2090 if (c != '-')
2091 error ("Invalid escape character syntax");
2092 c = READCHAR;
2093 if (c == '\\')
2094 c = read_escape (readcharfun, 0);
2095 return c | hyper_modifier;
2097 case 'A':
2098 c = READCHAR;
2099 if (c != '-')
2100 error ("Invalid escape character syntax");
2101 c = READCHAR;
2102 if (c == '\\')
2103 c = read_escape (readcharfun, 0);
2104 return c | alt_modifier;
2106 case 's':
2107 c = READCHAR;
2108 if (stringp || c != '-')
2110 UNREAD (c);
2111 return ' ';
2113 c = READCHAR;
2114 if (c == '\\')
2115 c = read_escape (readcharfun, 0);
2116 return c | super_modifier;
2118 case 'C':
2119 c = READCHAR;
2120 if (c != '-')
2121 error ("Invalid escape character syntax");
2122 case '^':
2123 c = READCHAR;
2124 if (c == '\\')
2125 c = read_escape (readcharfun, 0);
2126 if ((c & ~CHAR_MODIFIER_MASK) == '?')
2127 return 0177 | (c & CHAR_MODIFIER_MASK);
2128 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
2129 return c | ctrl_modifier;
2130 /* ASCII control chars are made from letters (both cases),
2131 as well as the non-letters within 0100...0137. */
2132 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
2133 return (c & (037 | ~0177));
2134 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
2135 return (c & (037 | ~0177));
2136 else
2137 return c | ctrl_modifier;
2139 case '0':
2140 case '1':
2141 case '2':
2142 case '3':
2143 case '4':
2144 case '5':
2145 case '6':
2146 case '7':
2147 /* An octal escape, as in ANSI C. */
2149 register int i = c - '0';
2150 register int count = 0;
2151 while (++count < 3)
2153 if ((c = READCHAR) >= '0' && c <= '7')
2155 i *= 8;
2156 i += c - '0';
2158 else
2160 UNREAD (c);
2161 break;
2165 if (i >= 0x80 && i < 0x100)
2166 i = BYTE8_TO_CHAR (i);
2167 return i;
2170 case 'x':
2171 /* A hex escape, as in ANSI C. */
2173 int i = 0;
2174 int count = 0;
2175 while (1)
2177 c = READCHAR;
2178 if (c >= '0' && c <= '9')
2180 i *= 16;
2181 i += c - '0';
2183 else if ((c >= 'a' && c <= 'f')
2184 || (c >= 'A' && c <= 'F'))
2186 i *= 16;
2187 if (c >= 'a' && c <= 'f')
2188 i += c - 'a' + 10;
2189 else
2190 i += c - 'A' + 10;
2192 else
2194 UNREAD (c);
2195 break;
2197 count++;
2200 if (count < 3 && i >= 0x80)
2201 return BYTE8_TO_CHAR (i);
2202 return i;
2205 case 'U':
2206 /* Post-Unicode-2.0: Up to eight hex chars. */
2207 unicode_hex_count = 8;
2208 case 'u':
2210 /* A Unicode escape. We only permit them in strings and characters,
2211 not arbitrarily in the source code, as in some other languages. */
2213 unsigned int i = 0;
2214 int count = 0;
2216 while (++count <= unicode_hex_count)
2218 c = READCHAR;
2219 /* isdigit and isalpha may be locale-specific, which we don't
2220 want. */
2221 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
2222 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
2223 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
2224 else
2226 error ("Non-hex digit used for Unicode escape");
2227 break;
2230 if (i > 0x10FFFF)
2231 error ("Non-Unicode character: 0x%x", i);
2232 return i;
2235 default:
2236 return c;
2240 /* Read an integer in radix RADIX using READCHARFUN to read
2241 characters. RADIX must be in the interval [2..36]; if it isn't, a
2242 read error is signaled . Value is the integer read. Signals an
2243 error if encountering invalid read syntax or if RADIX is out of
2244 range. */
2246 static Lisp_Object
2247 read_integer (readcharfun, radix)
2248 Lisp_Object readcharfun;
2249 int radix;
2251 int ndigits = 0, invalid_p, c, sign = 0;
2252 /* We use a floating point number because */
2253 double number = 0;
2255 if (radix < 2 || radix > 36)
2256 invalid_p = 1;
2257 else
2259 number = ndigits = invalid_p = 0;
2260 sign = 1;
2262 c = READCHAR;
2263 if (c == '-')
2265 c = READCHAR;
2266 sign = -1;
2268 else if (c == '+')
2269 c = READCHAR;
2271 while (c >= 0)
2273 int digit;
2275 if (c >= '0' && c <= '9')
2276 digit = c - '0';
2277 else if (c >= 'a' && c <= 'z')
2278 digit = c - 'a' + 10;
2279 else if (c >= 'A' && c <= 'Z')
2280 digit = c - 'A' + 10;
2281 else
2283 UNREAD (c);
2284 break;
2287 if (digit < 0 || digit >= radix)
2288 invalid_p = 1;
2290 number = radix * number + digit;
2291 ++ndigits;
2292 c = READCHAR;
2296 if (ndigits == 0 || invalid_p)
2298 char buf[50];
2299 sprintf (buf, "integer, radix %d", radix);
2300 invalid_syntax (buf, 0);
2303 return make_fixnum_or_float (sign * number);
2307 /* If the next token is ')' or ']' or '.', we store that character
2308 in *PCH and the return value is not interesting. Else, we store
2309 zero in *PCH and we read and return one lisp object.
2311 FIRST_IN_LIST is nonzero if this is the first element of a list. */
2313 static Lisp_Object
2314 read1 (readcharfun, pch, first_in_list)
2315 register Lisp_Object readcharfun;
2316 int *pch;
2317 int first_in_list;
2319 register int c;
2320 int uninterned_symbol = 0;
2321 int multibyte;
2323 *pch = 0;
2324 load_each_byte = 0;
2326 retry:
2328 c = READCHAR_REPORT_MULTIBYTE (&multibyte);
2329 if (c < 0)
2330 end_of_file_error ();
2332 switch (c)
2334 case '(':
2335 return read_list (0, readcharfun);
2337 case '[':
2338 return read_vector (readcharfun, 0);
2340 case ')':
2341 case ']':
2343 *pch = c;
2344 return Qnil;
2347 case '#':
2348 c = READCHAR;
2349 if (c == 's')
2351 c = READCHAR;
2352 if (c == '(')
2354 /* Accept extended format for hashtables (extensible to
2355 other types), e.g.
2356 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2357 Lisp_Object tmp = read_list (0, readcharfun);
2358 Lisp_Object head = CAR_SAFE (tmp);
2359 Lisp_Object data = Qnil;
2360 Lisp_Object val = Qnil;
2361 /* The size is 2 * number of allowed keywords to
2362 make-hash-table. */
2363 Lisp_Object params[10];
2364 Lisp_Object ht;
2365 Lisp_Object key = Qnil;
2366 int param_count = 0;
2368 if (!EQ (head, Qhash_table))
2369 error ("Invalid extended read marker at head of #s list "
2370 "(only hash-table allowed)");
2372 tmp = CDR_SAFE (tmp);
2374 /* This is repetitive but fast and simple. */
2375 params[param_count] = QCsize;
2376 params[param_count+1] = Fplist_get (tmp, Qsize);
2377 if (!NILP (params[param_count+1]))
2378 param_count+=2;
2380 params[param_count] = QCtest;
2381 params[param_count+1] = Fplist_get (tmp, Qtest);
2382 if (!NILP (params[param_count+1]))
2383 param_count+=2;
2385 params[param_count] = QCweakness;
2386 params[param_count+1] = Fplist_get (tmp, Qweakness);
2387 if (!NILP (params[param_count+1]))
2388 param_count+=2;
2390 params[param_count] = QCrehash_size;
2391 params[param_count+1] = Fplist_get (tmp, Qrehash_size);
2392 if (!NILP (params[param_count+1]))
2393 param_count+=2;
2395 params[param_count] = QCrehash_threshold;
2396 params[param_count+1] = Fplist_get (tmp, Qrehash_threshold);
2397 if (!NILP (params[param_count+1]))
2398 param_count+=2;
2400 /* This is the hashtable data. */
2401 data = Fplist_get (tmp, Qdata);
2403 /* Now use params to make a new hashtable and fill it. */
2404 ht = Fmake_hash_table (param_count, params);
2406 while (CONSP (data))
2408 key = XCAR (data);
2409 data = XCDR (data);
2410 if (!CONSP (data))
2411 error ("Odd number of elements in hashtable data");
2412 val = XCAR (data);
2413 data = XCDR (data);
2414 Fputhash (key, val, ht);
2417 return ht;
2420 if (c == '^')
2422 c = READCHAR;
2423 if (c == '[')
2425 Lisp_Object tmp;
2426 tmp = read_vector (readcharfun, 0);
2427 if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS)
2428 error ("Invalid size char-table");
2429 XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE);
2430 return tmp;
2432 else if (c == '^')
2434 c = READCHAR;
2435 if (c == '[')
2437 Lisp_Object tmp;
2438 int depth, size;
2440 tmp = read_vector (readcharfun, 0);
2441 if (!INTEGERP (AREF (tmp, 0)))
2442 error ("Invalid depth in char-table");
2443 depth = XINT (AREF (tmp, 0));
2444 if (depth < 1 || depth > 3)
2445 error ("Invalid depth in char-table");
2446 size = XVECTOR (tmp)->size - 2;
2447 if (chartab_size [depth] != size)
2448 error ("Invalid size char-table");
2449 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
2450 return tmp;
2452 invalid_syntax ("#^^", 3);
2454 invalid_syntax ("#^", 2);
2456 if (c == '&')
2458 Lisp_Object length;
2459 length = read1 (readcharfun, pch, first_in_list);
2460 c = READCHAR;
2461 if (c == '"')
2463 Lisp_Object tmp, val;
2464 int size_in_chars
2465 = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2466 / BOOL_VECTOR_BITS_PER_CHAR);
2468 UNREAD (c);
2469 tmp = read1 (readcharfun, pch, first_in_list);
2470 if (STRING_MULTIBYTE (tmp)
2471 || (size_in_chars != SCHARS (tmp)
2472 /* We used to print 1 char too many
2473 when the number of bits was a multiple of 8.
2474 Accept such input in case it came from an old
2475 version. */
2476 && ! (XFASTINT (length)
2477 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
2478 invalid_syntax ("#&...", 5);
2480 val = Fmake_bool_vector (length, Qnil);
2481 bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data,
2482 size_in_chars);
2483 /* Clear the extraneous bits in the last byte. */
2484 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
2485 XBOOL_VECTOR (val)->data[size_in_chars - 1]
2486 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2487 return val;
2489 invalid_syntax ("#&...", 5);
2491 if (c == '[')
2493 /* Accept compiled functions at read-time so that we don't have to
2494 build them using function calls. */
2495 Lisp_Object tmp;
2496 tmp = read_vector (readcharfun, 1);
2497 return Fmake_byte_code (XVECTOR (tmp)->size,
2498 XVECTOR (tmp)->contents);
2500 if (c == '(')
2502 Lisp_Object tmp;
2503 struct gcpro gcpro1;
2504 int ch;
2506 /* Read the string itself. */
2507 tmp = read1 (readcharfun, &ch, 0);
2508 if (ch != 0 || !STRINGP (tmp))
2509 invalid_syntax ("#", 1);
2510 GCPRO1 (tmp);
2511 /* Read the intervals and their properties. */
2512 while (1)
2514 Lisp_Object beg, end, plist;
2516 beg = read1 (readcharfun, &ch, 0);
2517 end = plist = Qnil;
2518 if (ch == ')')
2519 break;
2520 if (ch == 0)
2521 end = read1 (readcharfun, &ch, 0);
2522 if (ch == 0)
2523 plist = read1 (readcharfun, &ch, 0);
2524 if (ch)
2525 invalid_syntax ("Invalid string property list", 0);
2526 Fset_text_properties (beg, end, plist, tmp);
2528 UNGCPRO;
2529 return tmp;
2532 /* #@NUMBER is used to skip NUMBER following characters.
2533 That's used in .elc files to skip over doc strings
2534 and function definitions. */
2535 if (c == '@')
2537 int i, nskip = 0;
2539 load_each_byte = 1;
2540 /* Read a decimal integer. */
2541 while ((c = READCHAR) >= 0
2542 && c >= '0' && c <= '9')
2544 nskip *= 10;
2545 nskip += c - '0';
2547 if (c >= 0)
2548 UNREAD (c);
2550 if (load_force_doc_strings
2551 && (EQ (readcharfun, Qget_file_char)
2552 || EQ (readcharfun, Qget_emacs_mule_file_char)))
2554 /* If we are supposed to force doc strings into core right now,
2555 record the last string that we skipped,
2556 and record where in the file it comes from. */
2558 /* But first exchange saved_doc_string
2559 with prev_saved_doc_string, so we save two strings. */
2561 char *temp = saved_doc_string;
2562 int temp_size = saved_doc_string_size;
2563 file_offset temp_pos = saved_doc_string_position;
2564 int temp_len = saved_doc_string_length;
2566 saved_doc_string = prev_saved_doc_string;
2567 saved_doc_string_size = prev_saved_doc_string_size;
2568 saved_doc_string_position = prev_saved_doc_string_position;
2569 saved_doc_string_length = prev_saved_doc_string_length;
2571 prev_saved_doc_string = temp;
2572 prev_saved_doc_string_size = temp_size;
2573 prev_saved_doc_string_position = temp_pos;
2574 prev_saved_doc_string_length = temp_len;
2577 if (saved_doc_string_size == 0)
2579 saved_doc_string_size = nskip + 100;
2580 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
2582 if (nskip > saved_doc_string_size)
2584 saved_doc_string_size = nskip + 100;
2585 saved_doc_string = (char *) xrealloc (saved_doc_string,
2586 saved_doc_string_size);
2589 saved_doc_string_position = file_tell (instream);
2591 /* Copy that many characters into saved_doc_string. */
2592 for (i = 0; i < nskip && c >= 0; i++)
2593 saved_doc_string[i] = c = READCHAR;
2595 saved_doc_string_length = i;
2597 else
2599 /* Skip that many characters. */
2600 for (i = 0; i < nskip && c >= 0; i++)
2601 c = READCHAR;
2604 load_each_byte = 0;
2605 goto retry;
2607 if (c == '!')
2609 /* #! appears at the beginning of an executable file.
2610 Skip the first line. */
2611 while (c != '\n' && c >= 0)
2612 c = READCHAR;
2613 goto retry;
2615 if (c == '$')
2616 return Vload_file_name;
2617 if (c == '\'')
2618 return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
2619 /* #:foo is the uninterned symbol named foo. */
2620 if (c == ':')
2622 uninterned_symbol = 1;
2623 c = READCHAR;
2624 goto default_label;
2626 /* Reader forms that can reuse previously read objects. */
2627 if (c >= '0' && c <= '9')
2629 int n = 0;
2630 Lisp_Object tem;
2632 /* Read a non-negative integer. */
2633 while (c >= '0' && c <= '9')
2635 n *= 10;
2636 n += c - '0';
2637 c = READCHAR;
2639 /* #n=object returns object, but associates it with n for #n#. */
2640 if (c == '=' && !NILP (Vread_circle))
2642 /* Make a placeholder for #n# to use temporarily */
2643 Lisp_Object placeholder;
2644 Lisp_Object cell;
2646 placeholder = Fcons (Qnil, Qnil);
2647 cell = Fcons (make_number (n), placeholder);
2648 read_objects = Fcons (cell, read_objects);
2650 /* Read the object itself. */
2651 tem = read0 (readcharfun);
2653 /* Now put it everywhere the placeholder was... */
2654 substitute_object_in_subtree (tem, placeholder);
2656 /* ...and #n# will use the real value from now on. */
2657 Fsetcdr (cell, tem);
2659 return tem;
2661 /* #n# returns a previously read object. */
2662 if (c == '#' && !NILP (Vread_circle))
2664 tem = Fassq (make_number (n), read_objects);
2665 if (CONSP (tem))
2666 return XCDR (tem);
2667 /* Fall through to error message. */
2669 else if (c == 'r' || c == 'R')
2670 return read_integer (readcharfun, n);
2672 /* Fall through to error message. */
2674 else if (c == 'x' || c == 'X')
2675 return read_integer (readcharfun, 16);
2676 else if (c == 'o' || c == 'O')
2677 return read_integer (readcharfun, 8);
2678 else if (c == 'b' || c == 'B')
2679 return read_integer (readcharfun, 2);
2681 UNREAD (c);
2682 invalid_syntax ("#", 1);
2684 case ';':
2685 while ((c = READCHAR) >= 0 && c != '\n');
2686 goto retry;
2688 case '\'':
2690 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
2693 case '`':
2694 if (first_in_list)
2696 Vold_style_backquotes = Qt;
2697 goto default_label;
2699 else
2701 Lisp_Object value;
2703 new_backquote_flag++;
2704 value = read0 (readcharfun);
2705 new_backquote_flag--;
2707 return Fcons (Qbackquote, Fcons (value, Qnil));
2710 case ',':
2711 if (new_backquote_flag)
2713 Lisp_Object comma_type = Qnil;
2714 Lisp_Object value;
2715 int ch = READCHAR;
2717 if (ch == '@')
2718 comma_type = Qcomma_at;
2719 else if (ch == '.')
2720 comma_type = Qcomma_dot;
2721 else
2723 if (ch >= 0) UNREAD (ch);
2724 comma_type = Qcomma;
2727 new_backquote_flag--;
2728 value = read0 (readcharfun);
2729 new_backquote_flag++;
2730 return Fcons (comma_type, Fcons (value, Qnil));
2732 else
2734 Vold_style_backquotes = Qt;
2735 goto default_label;
2738 case '?':
2740 int modifiers;
2741 int next_char;
2742 int ok;
2744 c = READCHAR;
2745 if (c < 0)
2746 end_of_file_error ();
2748 /* Accept `single space' syntax like (list ? x) where the
2749 whitespace character is SPC or TAB.
2750 Other literal whitespace like NL, CR, and FF are not accepted,
2751 as there are well-established escape sequences for these. */
2752 if (c == ' ' || c == '\t')
2753 return make_number (c);
2755 if (c == '\\')
2756 c = read_escape (readcharfun, 0);
2757 modifiers = c & CHAR_MODIFIER_MASK;
2758 c &= ~CHAR_MODIFIER_MASK;
2759 if (CHAR_BYTE8_P (c))
2760 c = CHAR_TO_BYTE8 (c);
2761 c |= modifiers;
2763 next_char = READCHAR;
2764 if (next_char == '.')
2766 /* Only a dotted-pair dot is valid after a char constant. */
2767 int next_next_char = READCHAR;
2768 UNREAD (next_next_char);
2770 ok = (next_next_char <= 040
2771 || (next_next_char < 0200
2772 && (index ("\"';([#?", next_next_char)
2773 || (!first_in_list && next_next_char == '`')
2774 || (new_backquote_flag && next_next_char == ','))));
2776 else
2778 ok = (next_char <= 040
2779 || (next_char < 0200
2780 && (index ("\"';()[]#?", next_char)
2781 || (!first_in_list && next_char == '`')
2782 || (new_backquote_flag && next_char == ','))));
2784 UNREAD (next_char);
2785 if (ok)
2786 return make_number (c);
2788 invalid_syntax ("?", 1);
2791 case '"':
2793 char *p = read_buffer;
2794 char *end = read_buffer + read_buffer_size;
2795 register int c;
2796 /* Nonzero if we saw an escape sequence specifying
2797 a multibyte character. */
2798 int force_multibyte = 0;
2799 /* Nonzero if we saw an escape sequence specifying
2800 a single-byte character. */
2801 int force_singlebyte = 0;
2802 int cancel = 0;
2803 int nchars = 0;
2805 while ((c = READCHAR) >= 0
2806 && c != '\"')
2808 if (end - p < MAX_MULTIBYTE_LENGTH)
2810 int offset = p - read_buffer;
2811 read_buffer = (char *) xrealloc (read_buffer,
2812 read_buffer_size *= 2);
2813 p = read_buffer + offset;
2814 end = read_buffer + read_buffer_size;
2817 if (c == '\\')
2819 int modifiers;
2821 c = read_escape (readcharfun, 1);
2823 /* C is -1 if \ newline has just been seen */
2824 if (c == -1)
2826 if (p == read_buffer)
2827 cancel = 1;
2828 continue;
2831 modifiers = c & CHAR_MODIFIER_MASK;
2832 c = c & ~CHAR_MODIFIER_MASK;
2834 if (CHAR_BYTE8_P (c))
2835 force_singlebyte = 1;
2836 else if (! ASCII_CHAR_P (c))
2837 force_multibyte = 1;
2838 else /* i.e. ASCII_CHAR_P (c) */
2840 /* Allow `\C- ' and `\C-?'. */
2841 if (modifiers == CHAR_CTL)
2843 if (c == ' ')
2844 c = 0, modifiers = 0;
2845 else if (c == '?')
2846 c = 127, modifiers = 0;
2848 if (modifiers & CHAR_SHIFT)
2850 /* Shift modifier is valid only with [A-Za-z]. */
2851 if (c >= 'A' && c <= 'Z')
2852 modifiers &= ~CHAR_SHIFT;
2853 else if (c >= 'a' && c <= 'z')
2854 c -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
2857 if (modifiers & CHAR_META)
2859 /* Move the meta bit to the right place for a
2860 string. */
2861 modifiers &= ~CHAR_META;
2862 c = BYTE8_TO_CHAR (c | 0x80);
2863 force_singlebyte = 1;
2867 /* Any modifiers remaining are invalid. */
2868 if (modifiers)
2869 error ("Invalid modifier in string");
2870 p += CHAR_STRING (c, (unsigned char *) p);
2872 else
2874 p += CHAR_STRING (c, (unsigned char *) p);
2875 if (CHAR_BYTE8_P (c))
2876 force_singlebyte = 1;
2877 else if (! ASCII_CHAR_P (c))
2878 force_multibyte = 1;
2880 nchars++;
2883 if (c < 0)
2884 end_of_file_error ();
2886 /* If purifying, and string starts with \ newline,
2887 return zero instead. This is for doc strings
2888 that we are really going to find in etc/DOC.nn.nn */
2889 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
2890 return make_number (0);
2892 if (force_multibyte)
2893 /* READ_BUFFER already contains valid multibyte forms. */
2895 else if (force_singlebyte)
2897 nchars = str_as_unibyte (read_buffer, p - read_buffer);
2898 p = read_buffer + nchars;
2900 else
2901 /* Otherwise, READ_BUFFER contains only ASCII. */
2904 /* We want readchar_count to be the number of characters, not
2905 bytes. Hence we adjust for multibyte characters in the
2906 string. ... But it doesn't seem to be necessary, because
2907 READCHAR *does* read multibyte characters from buffers. */
2908 /* readchar_count -= (p - read_buffer) - nchars; */
2909 if (read_pure)
2910 return make_pure_string (read_buffer, nchars, p - read_buffer,
2911 (force_multibyte
2912 || (p - read_buffer != nchars)));
2913 return make_specified_string (read_buffer, nchars, p - read_buffer,
2914 (force_multibyte
2915 || (p - read_buffer != nchars)));
2918 case '.':
2920 int next_char = READCHAR;
2921 UNREAD (next_char);
2923 if (next_char <= 040
2924 || (next_char < 0200
2925 && (index ("\"';([#?", next_char)
2926 || (!first_in_list && next_char == '`')
2927 || (new_backquote_flag && next_char == ','))))
2929 *pch = c;
2930 return Qnil;
2933 /* Otherwise, we fall through! Note that the atom-reading loop
2934 below will now loop at least once, assuring that we will not
2935 try to UNREAD two characters in a row. */
2937 default:
2938 default_label:
2939 if (c <= 040) goto retry;
2940 if (c == 0x8a0) /* NBSP */
2941 goto retry;
2943 char *p = read_buffer;
2944 int quoted = 0;
2947 char *end = read_buffer + read_buffer_size;
2949 while (c > 040
2950 && c != 0x8a0 /* NBSP */
2951 && (c >= 0200
2952 || (!index ("\"';()[]#", c)
2953 && !(!first_in_list && c == '`')
2954 && !(new_backquote_flag && c == ','))))
2956 if (end - p < MAX_MULTIBYTE_LENGTH)
2958 int offset = p - read_buffer;
2959 read_buffer = (char *) xrealloc (read_buffer,
2960 read_buffer_size *= 2);
2961 p = read_buffer + offset;
2962 end = read_buffer + read_buffer_size;
2965 if (c == '\\')
2967 c = READCHAR;
2968 if (c == -1)
2969 end_of_file_error ();
2970 quoted = 1;
2973 if (multibyte)
2974 p += CHAR_STRING (c, p);
2975 else
2976 *p++ = c;
2977 c = READCHAR;
2980 if (p == end)
2982 int offset = p - read_buffer;
2983 read_buffer = (char *) xrealloc (read_buffer,
2984 read_buffer_size *= 2);
2985 p = read_buffer + offset;
2986 end = read_buffer + read_buffer_size;
2988 *p = 0;
2989 if (c >= 0)
2990 UNREAD (c);
2993 if (!quoted && !uninterned_symbol)
2995 register char *p1;
2996 p1 = read_buffer;
2997 if (*p1 == '+' || *p1 == '-') p1++;
2998 /* Is it an integer? */
2999 if (p1 != p)
3001 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
3002 /* Integers can have trailing decimal points. */
3003 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
3004 if (p1 == p)
3005 /* It is an integer. */
3007 if (p1[-1] == '.')
3008 p1[-1] = '\0';
3010 /* EMACS_INT n = atol (read_buffer); */
3011 char *endptr = NULL;
3012 EMACS_INT n = (errno = 0,
3013 strtol (read_buffer, &endptr, 10));
3014 if (errno == ERANGE && endptr)
3016 Lisp_Object args
3017 = Fcons (make_string (read_buffer,
3018 endptr - read_buffer),
3019 Qnil);
3020 xsignal (Qoverflow_error, args);
3022 return make_fixnum_or_float (n);
3026 if (isfloat_string (read_buffer, 0))
3028 /* Compute NaN and infinities using 0.0 in a variable,
3029 to cope with compilers that think they are smarter
3030 than we are. */
3031 double zero = 0.0;
3033 double value;
3035 /* Negate the value ourselves. This treats 0, NaNs,
3036 and infinity properly on IEEE floating point hosts,
3037 and works around a common bug where atof ("-0.0")
3038 drops the sign. */
3039 int negative = read_buffer[0] == '-';
3041 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
3042 returns 1, is if the input ends in e+INF or e+NaN. */
3043 switch (p[-1])
3045 case 'F':
3046 value = 1.0 / zero;
3047 break;
3048 case 'N':
3049 value = zero / zero;
3051 /* If that made a "negative" NaN, negate it. */
3054 int i;
3055 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
3057 u_data.d = value;
3058 u_minus_zero.d = - 0.0;
3059 for (i = 0; i < sizeof (double); i++)
3060 if (u_data.c[i] & u_minus_zero.c[i])
3062 value = - value;
3063 break;
3066 /* Now VALUE is a positive NaN. */
3067 break;
3068 default:
3069 value = atof (read_buffer + negative);
3070 break;
3073 return make_float (negative ? - value : value);
3077 Lisp_Object name, result;
3078 EMACS_INT nbytes = p - read_buffer;
3079 EMACS_INT nchars
3080 = (multibyte ? multibyte_chars_in_text (read_buffer, nbytes)
3081 : nbytes);
3083 if (uninterned_symbol && ! NILP (Vpurify_flag))
3084 name = make_pure_string (read_buffer, nchars, nbytes, multibyte);
3085 else
3086 name = make_specified_string (read_buffer, nchars, nbytes,multibyte);
3087 result = (uninterned_symbol ? Fmake_symbol (name)
3088 : Fintern (name, Qnil));
3090 if (EQ (Vread_with_symbol_positions, Qt)
3091 || EQ (Vread_with_symbol_positions, readcharfun))
3092 Vread_symbol_positions_list =
3093 /* Kind of a hack; this will probably fail if characters
3094 in the symbol name were escaped. Not really a big
3095 deal, though. */
3096 Fcons (Fcons (result,
3097 make_number (readchar_count
3098 - XFASTINT (Flength (Fsymbol_name (result))))),
3099 Vread_symbol_positions_list);
3100 return result;
3107 /* List of nodes we've seen during substitute_object_in_subtree. */
3108 static Lisp_Object seen_list;
3110 static void
3111 substitute_object_in_subtree (object, placeholder)
3112 Lisp_Object object;
3113 Lisp_Object placeholder;
3115 Lisp_Object check_object;
3117 /* We haven't seen any objects when we start. */
3118 seen_list = Qnil;
3120 /* Make all the substitutions. */
3121 check_object
3122 = substitute_object_recurse (object, placeholder, object);
3124 /* Clear seen_list because we're done with it. */
3125 seen_list = Qnil;
3127 /* The returned object here is expected to always eq the
3128 original. */
3129 if (!EQ (check_object, object))
3130 error ("Unexpected mutation error in reader");
3133 /* Feval doesn't get called from here, so no gc protection is needed. */
3134 #define SUBSTITUTE(get_val, set_val) \
3135 do { \
3136 Lisp_Object old_value = get_val; \
3137 Lisp_Object true_value \
3138 = substitute_object_recurse (object, placeholder, \
3139 old_value); \
3141 if (!EQ (old_value, true_value)) \
3143 set_val; \
3145 } while (0)
3147 static Lisp_Object
3148 substitute_object_recurse (object, placeholder, subtree)
3149 Lisp_Object object;
3150 Lisp_Object placeholder;
3151 Lisp_Object subtree;
3153 /* If we find the placeholder, return the target object. */
3154 if (EQ (placeholder, subtree))
3155 return object;
3157 /* If we've been to this node before, don't explore it again. */
3158 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
3159 return subtree;
3161 /* If this node can be the entry point to a cycle, remember that
3162 we've seen it. It can only be such an entry point if it was made
3163 by #n=, which means that we can find it as a value in
3164 read_objects. */
3165 if (!EQ (Qnil, Frassq (subtree, read_objects)))
3166 seen_list = Fcons (subtree, seen_list);
3168 /* Recurse according to subtree's type.
3169 Every branch must return a Lisp_Object. */
3170 switch (XTYPE (subtree))
3172 case Lisp_Vectorlike:
3174 int i, length = 0;
3175 if (BOOL_VECTOR_P (subtree))
3176 return subtree; /* No sub-objects anyway. */
3177 else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
3178 || COMPILEDP (subtree))
3179 length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK;
3180 else if (VECTORP (subtree))
3181 length = ASIZE (subtree);
3182 else
3183 /* An unknown pseudovector may contain non-Lisp fields, so we
3184 can't just blindly traverse all its fields. We used to call
3185 `Flength' which signaled `sequencep', so I just preserved this
3186 behavior. */
3187 wrong_type_argument (Qsequencep, subtree);
3189 for (i = 0; i < length; i++)
3190 SUBSTITUTE (AREF (subtree, i),
3191 ASET (subtree, i, true_value));
3192 return subtree;
3195 case Lisp_Cons:
3197 SUBSTITUTE (XCAR (subtree),
3198 XSETCAR (subtree, true_value));
3199 SUBSTITUTE (XCDR (subtree),
3200 XSETCDR (subtree, true_value));
3201 return subtree;
3204 case Lisp_String:
3206 /* Check for text properties in each interval.
3207 substitute_in_interval contains part of the logic. */
3209 INTERVAL root_interval = STRING_INTERVALS (subtree);
3210 Lisp_Object arg = Fcons (object, placeholder);
3212 traverse_intervals_noorder (root_interval,
3213 &substitute_in_interval, arg);
3215 return subtree;
3218 /* Other types don't recurse any further. */
3219 default:
3220 return subtree;
3224 /* Helper function for substitute_object_recurse. */
3225 static void
3226 substitute_in_interval (interval, arg)
3227 INTERVAL interval;
3228 Lisp_Object arg;
3230 Lisp_Object object = Fcar (arg);
3231 Lisp_Object placeholder = Fcdr (arg);
3233 SUBSTITUTE (interval->plist, interval->plist = true_value);
3237 #define LEAD_INT 1
3238 #define DOT_CHAR 2
3239 #define TRAIL_INT 4
3240 #define E_CHAR 8
3241 #define EXP_INT 16
3244 isfloat_string (cp, ignore_trailing)
3245 register char *cp;
3246 int ignore_trailing;
3248 register int state;
3250 char *start = cp;
3252 state = 0;
3253 if (*cp == '+' || *cp == '-')
3254 cp++;
3256 if (*cp >= '0' && *cp <= '9')
3258 state |= LEAD_INT;
3259 while (*cp >= '0' && *cp <= '9')
3260 cp++;
3262 if (*cp == '.')
3264 state |= DOT_CHAR;
3265 cp++;
3267 if (*cp >= '0' && *cp <= '9')
3269 state |= TRAIL_INT;
3270 while (*cp >= '0' && *cp <= '9')
3271 cp++;
3273 if (*cp == 'e' || *cp == 'E')
3275 state |= E_CHAR;
3276 cp++;
3277 if (*cp == '+' || *cp == '-')
3278 cp++;
3281 if (*cp >= '0' && *cp <= '9')
3283 state |= EXP_INT;
3284 while (*cp >= '0' && *cp <= '9')
3285 cp++;
3287 else if (cp == start)
3289 else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
3291 state |= EXP_INT;
3292 cp += 3;
3294 else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
3296 state |= EXP_INT;
3297 cp += 3;
3300 return ((ignore_trailing
3301 || (*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
3302 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
3303 || state == (DOT_CHAR|TRAIL_INT)
3304 || state == (LEAD_INT|E_CHAR|EXP_INT)
3305 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
3306 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
3310 static Lisp_Object
3311 read_vector (readcharfun, bytecodeflag)
3312 Lisp_Object readcharfun;
3313 int bytecodeflag;
3315 register int i;
3316 register int size;
3317 register Lisp_Object *ptr;
3318 register Lisp_Object tem, item, vector;
3319 register struct Lisp_Cons *otem;
3320 Lisp_Object len;
3322 tem = read_list (1, readcharfun);
3323 len = Flength (tem);
3324 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
3326 size = XVECTOR (vector)->size;
3327 ptr = XVECTOR (vector)->contents;
3328 for (i = 0; i < size; i++)
3330 item = Fcar (tem);
3331 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3332 bytecode object, the docstring containing the bytecode and
3333 constants values must be treated as unibyte and passed to
3334 Fread, to get the actual bytecode string and constants vector. */
3335 if (bytecodeflag && load_force_doc_strings)
3337 if (i == COMPILED_BYTECODE)
3339 if (!STRINGP (item))
3340 error ("Invalid byte code");
3342 /* Delay handling the bytecode slot until we know whether
3343 it is lazily-loaded (we can tell by whether the
3344 constants slot is nil). */
3345 ptr[COMPILED_CONSTANTS] = item;
3346 item = Qnil;
3348 else if (i == COMPILED_CONSTANTS)
3350 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
3352 if (NILP (item))
3354 /* Coerce string to unibyte (like string-as-unibyte,
3355 but without generating extra garbage and
3356 guaranteeing no change in the contents). */
3357 STRING_SET_CHARS (bytestr, SBYTES (bytestr));
3358 STRING_SET_UNIBYTE (bytestr);
3360 item = Fread (Fcons (bytestr, readcharfun));
3361 if (!CONSP (item))
3362 error ("Invalid byte code");
3364 otem = XCONS (item);
3365 bytestr = XCAR (item);
3366 item = XCDR (item);
3367 free_cons (otem);
3370 /* Now handle the bytecode slot. */
3371 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
3373 else if (i == COMPILED_DOC_STRING
3374 && STRINGP (item)
3375 && ! STRING_MULTIBYTE (item))
3377 if (EQ (readcharfun, Qget_emacs_mule_file_char))
3378 item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil);
3379 else
3380 item = Fstring_as_multibyte (item);
3383 ptr[i] = read_pure ? Fpurecopy (item) : item;
3384 otem = XCONS (tem);
3385 tem = Fcdr (tem);
3386 free_cons (otem);
3388 return vector;
3391 /* FLAG = 1 means check for ] to terminate rather than ) and .
3392 FLAG = -1 means check for starting with defun
3393 and make structure pure. */
3395 static Lisp_Object
3396 read_list (flag, readcharfun)
3397 int flag;
3398 register Lisp_Object readcharfun;
3400 /* -1 means check next element for defun,
3401 0 means don't check,
3402 1 means already checked and found defun. */
3403 int defunflag = flag < 0 ? -1 : 0;
3404 Lisp_Object val, tail;
3405 register Lisp_Object elt, tem;
3406 struct gcpro gcpro1, gcpro2;
3407 /* 0 is the normal case.
3408 1 means this list is a doc reference; replace it with the number 0.
3409 2 means this list is a doc reference; replace it with the doc string. */
3410 int doc_reference = 0;
3412 /* Initialize this to 1 if we are reading a list. */
3413 int first_in_list = flag <= 0;
3415 val = Qnil;
3416 tail = Qnil;
3418 while (1)
3420 int ch;
3421 GCPRO2 (val, tail);
3422 elt = read1 (readcharfun, &ch, first_in_list);
3423 UNGCPRO;
3425 first_in_list = 0;
3427 /* While building, if the list starts with #$, treat it specially. */
3428 if (EQ (elt, Vload_file_name)
3429 && ! NILP (elt)
3430 && !NILP (Vpurify_flag))
3432 if (NILP (Vdoc_file_name))
3433 /* We have not yet called Snarf-documentation, so assume
3434 this file is described in the DOC-MM.NN file
3435 and Snarf-documentation will fill in the right value later.
3436 For now, replace the whole list with 0. */
3437 doc_reference = 1;
3438 else
3439 /* We have already called Snarf-documentation, so make a relative
3440 file name for this file, so it can be found properly
3441 in the installed Lisp directory.
3442 We don't use Fexpand_file_name because that would make
3443 the directory absolute now. */
3444 elt = concat2 (build_string ("../lisp/"),
3445 Ffile_name_nondirectory (elt));
3447 else if (EQ (elt, Vload_file_name)
3448 && ! NILP (elt)
3449 && load_force_doc_strings)
3450 doc_reference = 2;
3452 if (ch)
3454 if (flag > 0)
3456 if (ch == ']')
3457 return val;
3458 invalid_syntax (") or . in a vector", 18);
3460 if (ch == ')')
3461 return val;
3462 if (ch == '.')
3464 GCPRO2 (val, tail);
3465 if (!NILP (tail))
3466 XSETCDR (tail, read0 (readcharfun));
3467 else
3468 val = read0 (readcharfun);
3469 read1 (readcharfun, &ch, 0);
3470 UNGCPRO;
3471 if (ch == ')')
3473 if (doc_reference == 1)
3474 return make_number (0);
3475 if (doc_reference == 2)
3477 /* Get a doc string from the file we are loading.
3478 If it's in saved_doc_string, get it from there.
3480 Here, we don't know if the string is a
3481 bytecode string or a doc string. As a
3482 bytecode string must be unibyte, we always
3483 return a unibyte string. If it is actually a
3484 doc string, caller must make it
3485 multibyte. */
3487 int pos = XINT (XCDR (val));
3488 /* Position is negative for user variables. */
3489 if (pos < 0) pos = -pos;
3490 if (pos >= saved_doc_string_position
3491 && pos < (saved_doc_string_position
3492 + saved_doc_string_length))
3494 int start = pos - saved_doc_string_position;
3495 int from, to;
3497 /* Process quoting with ^A,
3498 and find the end of the string,
3499 which is marked with ^_ (037). */
3500 for (from = start, to = start;
3501 saved_doc_string[from] != 037;)
3503 int c = saved_doc_string[from++];
3504 if (c == 1)
3506 c = saved_doc_string[from++];
3507 if (c == 1)
3508 saved_doc_string[to++] = c;
3509 else if (c == '0')
3510 saved_doc_string[to++] = 0;
3511 else if (c == '_')
3512 saved_doc_string[to++] = 037;
3514 else
3515 saved_doc_string[to++] = c;
3518 return make_unibyte_string (saved_doc_string + start,
3519 to - start);
3521 /* Look in prev_saved_doc_string the same way. */
3522 else if (pos >= prev_saved_doc_string_position
3523 && pos < (prev_saved_doc_string_position
3524 + prev_saved_doc_string_length))
3526 int start = pos - prev_saved_doc_string_position;
3527 int from, to;
3529 /* Process quoting with ^A,
3530 and find the end of the string,
3531 which is marked with ^_ (037). */
3532 for (from = start, to = start;
3533 prev_saved_doc_string[from] != 037;)
3535 int c = prev_saved_doc_string[from++];
3536 if (c == 1)
3538 c = prev_saved_doc_string[from++];
3539 if (c == 1)
3540 prev_saved_doc_string[to++] = c;
3541 else if (c == '0')
3542 prev_saved_doc_string[to++] = 0;
3543 else if (c == '_')
3544 prev_saved_doc_string[to++] = 037;
3546 else
3547 prev_saved_doc_string[to++] = c;
3550 return make_unibyte_string (prev_saved_doc_string
3551 + start,
3552 to - start);
3554 else
3555 return get_doc_string (val, 1, 0);
3558 return val;
3560 invalid_syntax (". in wrong context", 18);
3562 invalid_syntax ("] in a list", 11);
3564 tem = (read_pure && flag <= 0
3565 ? pure_cons (elt, Qnil)
3566 : Fcons (elt, Qnil));
3567 if (!NILP (tail))
3568 XSETCDR (tail, tem);
3569 else
3570 val = tem;
3571 tail = tem;
3572 if (defunflag < 0)
3573 defunflag = EQ (elt, Qdefun);
3574 else if (defunflag > 0)
3575 read_pure = 1;
3579 Lisp_Object Vobarray;
3580 Lisp_Object initial_obarray;
3582 /* oblookup stores the bucket number here, for the sake of Funintern. */
3584 int oblookup_last_bucket_number;
3586 static int hash_string ();
3588 /* Get an error if OBARRAY is not an obarray.
3589 If it is one, return it. */
3591 Lisp_Object
3592 check_obarray (obarray)
3593 Lisp_Object obarray;
3595 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3597 /* If Vobarray is now invalid, force it to be valid. */
3598 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
3599 wrong_type_argument (Qvectorp, obarray);
3601 return obarray;
3604 /* Intern the C string STR: return a symbol with that name,
3605 interned in the current obarray. */
3607 Lisp_Object
3608 intern (str)
3609 const char *str;
3611 Lisp_Object tem;
3612 int len = strlen (str);
3613 Lisp_Object obarray;
3615 obarray = Vobarray;
3616 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3617 obarray = check_obarray (obarray);
3618 tem = oblookup (obarray, str, len, len);
3619 if (SYMBOLP (tem))
3620 return tem;
3621 return Fintern (make_string (str, len), obarray);
3624 Lisp_Object
3625 intern_c_string (const char *str)
3627 Lisp_Object tem;
3628 int len = strlen (str);
3629 Lisp_Object obarray;
3631 obarray = Vobarray;
3632 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3633 obarray = check_obarray (obarray);
3634 tem = oblookup (obarray, str, len, len);
3635 if (SYMBOLP (tem))
3636 return tem;
3638 if (NILP (Vpurify_flag))
3639 /* Creating a non-pure string from a string literal not
3640 implemented yet. We could just use make_string here and live
3641 with the extra copy. */
3642 abort ();
3644 return Fintern (make_pure_c_string (str), obarray);
3647 /* Create an uninterned symbol with name STR. */
3649 Lisp_Object
3650 make_symbol (str)
3651 char *str;
3653 int len = strlen (str);
3655 return Fmake_symbol ((!NILP (Vpurify_flag)
3656 ? make_pure_string (str, len, len, 0)
3657 : make_string (str, len)));
3660 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
3661 doc: /* Return the canonical symbol whose name is STRING.
3662 If there is none, one is created by this function and returned.
3663 A second optional argument specifies the obarray to use;
3664 it defaults to the value of `obarray'. */)
3665 (string, obarray)
3666 Lisp_Object string, obarray;
3668 register Lisp_Object tem, sym, *ptr;
3670 if (NILP (obarray)) obarray = Vobarray;
3671 obarray = check_obarray (obarray);
3673 CHECK_STRING (string);
3675 tem = oblookup (obarray, SDATA (string),
3676 SCHARS (string),
3677 SBYTES (string));
3678 if (!INTEGERP (tem))
3679 return tem;
3681 if (!NILP (Vpurify_flag))
3682 string = Fpurecopy (string);
3683 sym = Fmake_symbol (string);
3685 if (EQ (obarray, initial_obarray))
3686 XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3687 else
3688 XSYMBOL (sym)->interned = SYMBOL_INTERNED;
3690 if ((SREF (string, 0) == ':')
3691 && EQ (obarray, initial_obarray))
3693 XSYMBOL (sym)->constant = 1;
3694 XSYMBOL (sym)->value = sym;
3697 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
3698 if (SYMBOLP (*ptr))
3699 XSYMBOL (sym)->next = XSYMBOL (*ptr);
3700 else
3701 XSYMBOL (sym)->next = 0;
3702 *ptr = sym;
3703 return sym;
3706 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
3707 doc: /* Return the canonical symbol named NAME, or nil if none exists.
3708 NAME may be a string or a symbol. If it is a symbol, that exact
3709 symbol is searched for.
3710 A second optional argument specifies the obarray to use;
3711 it defaults to the value of `obarray'. */)
3712 (name, obarray)
3713 Lisp_Object name, obarray;
3715 register Lisp_Object tem, string;
3717 if (NILP (obarray)) obarray = Vobarray;
3718 obarray = check_obarray (obarray);
3720 if (!SYMBOLP (name))
3722 CHECK_STRING (name);
3723 string = name;
3725 else
3726 string = SYMBOL_NAME (name);
3728 tem = oblookup (obarray, SDATA (string), SCHARS (string), SBYTES (string));
3729 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
3730 return Qnil;
3731 else
3732 return tem;
3735 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
3736 doc: /* Delete the symbol named NAME, if any, from OBARRAY.
3737 The value is t if a symbol was found and deleted, nil otherwise.
3738 NAME may be a string or a symbol. If it is a symbol, that symbol
3739 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3740 OBARRAY defaults to the value of the variable `obarray'. */)
3741 (name, obarray)
3742 Lisp_Object name, obarray;
3744 register Lisp_Object string, tem;
3745 int hash;
3747 if (NILP (obarray)) obarray = Vobarray;
3748 obarray = check_obarray (obarray);
3750 if (SYMBOLP (name))
3751 string = SYMBOL_NAME (name);
3752 else
3754 CHECK_STRING (name);
3755 string = name;
3758 tem = oblookup (obarray, SDATA (string),
3759 SCHARS (string),
3760 SBYTES (string));
3761 if (INTEGERP (tem))
3762 return Qnil;
3763 /* If arg was a symbol, don't delete anything but that symbol itself. */
3764 if (SYMBOLP (name) && !EQ (name, tem))
3765 return Qnil;
3767 /* There are plenty of other symbols which will screw up the Emacs
3768 session if we unintern them, as well as even more ways to use
3769 `setq' or `fset' or whatnot to make the Emacs session
3770 unusable. Let's not go down this silly road. --Stef */
3771 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
3772 error ("Attempt to unintern t or nil"); */
3774 XSYMBOL (tem)->interned = SYMBOL_UNINTERNED;
3775 XSYMBOL (tem)->constant = 0;
3776 XSYMBOL (tem)->indirect_variable = 0;
3778 hash = oblookup_last_bucket_number;
3780 if (EQ (XVECTOR (obarray)->contents[hash], tem))
3782 if (XSYMBOL (tem)->next)
3783 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
3784 else
3785 XSETINT (XVECTOR (obarray)->contents[hash], 0);
3787 else
3789 Lisp_Object tail, following;
3791 for (tail = XVECTOR (obarray)->contents[hash];
3792 XSYMBOL (tail)->next;
3793 tail = following)
3795 XSETSYMBOL (following, XSYMBOL (tail)->next);
3796 if (EQ (following, tem))
3798 XSYMBOL (tail)->next = XSYMBOL (following)->next;
3799 break;
3804 return Qt;
3807 /* Return the symbol in OBARRAY whose names matches the string
3808 of SIZE characters (SIZE_BYTE bytes) at PTR.
3809 If there is no such symbol in OBARRAY, return nil.
3811 Also store the bucket number in oblookup_last_bucket_number. */
3813 Lisp_Object
3814 oblookup (obarray, ptr, size, size_byte)
3815 Lisp_Object obarray;
3816 register const char *ptr;
3817 int size, size_byte;
3819 int hash;
3820 int obsize;
3821 register Lisp_Object tail;
3822 Lisp_Object bucket, tem;
3824 if (!VECTORP (obarray)
3825 || (obsize = XVECTOR (obarray)->size) == 0)
3827 obarray = check_obarray (obarray);
3828 obsize = XVECTOR (obarray)->size;
3830 /* This is sometimes needed in the middle of GC. */
3831 obsize &= ~ARRAY_MARK_FLAG;
3832 hash = hash_string (ptr, size_byte) % obsize;
3833 bucket = XVECTOR (obarray)->contents[hash];
3834 oblookup_last_bucket_number = hash;
3835 if (EQ (bucket, make_number (0)))
3837 else if (!SYMBOLP (bucket))
3838 error ("Bad data in guts of obarray"); /* Like CADR error message */
3839 else
3840 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
3842 if (SBYTES (SYMBOL_NAME (tail)) == size_byte
3843 && SCHARS (SYMBOL_NAME (tail)) == size
3844 && !bcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
3845 return tail;
3846 else if (XSYMBOL (tail)->next == 0)
3847 break;
3849 XSETINT (tem, hash);
3850 return tem;
3853 static int
3854 hash_string (ptr, len)
3855 const unsigned char *ptr;
3856 int len;
3858 register const unsigned char *p = ptr;
3859 register const unsigned char *end = p + len;
3860 register unsigned char c;
3861 register int hash = 0;
3863 while (p != end)
3865 c = *p++;
3866 if (c >= 0140) c -= 40;
3867 hash = ((hash<<3) + (hash>>28) + c);
3869 return hash & 07777777777;
3872 void
3873 map_obarray (obarray, fn, arg)
3874 Lisp_Object obarray;
3875 void (*fn) P_ ((Lisp_Object, Lisp_Object));
3876 Lisp_Object arg;
3878 register int i;
3879 register Lisp_Object tail;
3880 CHECK_VECTOR (obarray);
3881 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
3883 tail = XVECTOR (obarray)->contents[i];
3884 if (SYMBOLP (tail))
3885 while (1)
3887 (*fn) (tail, arg);
3888 if (XSYMBOL (tail)->next == 0)
3889 break;
3890 XSETSYMBOL (tail, XSYMBOL (tail)->next);
3895 void
3896 mapatoms_1 (sym, function)
3897 Lisp_Object sym, function;
3899 call1 (function, sym);
3902 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
3903 doc: /* Call FUNCTION on every symbol in OBARRAY.
3904 OBARRAY defaults to the value of `obarray'. */)
3905 (function, obarray)
3906 Lisp_Object function, obarray;
3908 if (NILP (obarray)) obarray = Vobarray;
3909 obarray = check_obarray (obarray);
3911 map_obarray (obarray, mapatoms_1, function);
3912 return Qnil;
3915 #define OBARRAY_SIZE 1511
3917 void
3918 init_obarray ()
3920 Lisp_Object oblength;
3921 int hash;
3922 Lisp_Object *tem;
3924 XSETFASTINT (oblength, OBARRAY_SIZE);
3926 Qnil = Fmake_symbol (make_pure_c_string ("nil"));
3927 Vobarray = Fmake_vector (oblength, make_number (0));
3928 initial_obarray = Vobarray;
3929 staticpro (&initial_obarray);
3930 /* Intern nil in the obarray */
3931 XSYMBOL (Qnil)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3932 XSYMBOL (Qnil)->constant = 1;
3934 /* These locals are to kludge around a pyramid compiler bug. */
3935 hash = hash_string ("nil", 3);
3936 /* Separate statement here to avoid VAXC bug. */
3937 hash %= OBARRAY_SIZE;
3938 tem = &XVECTOR (Vobarray)->contents[hash];
3939 *tem = Qnil;
3941 Qunbound = Fmake_symbol (make_pure_c_string ("unbound"));
3942 XSYMBOL (Qnil)->function = Qunbound;
3943 XSYMBOL (Qunbound)->value = Qunbound;
3944 XSYMBOL (Qunbound)->function = Qunbound;
3946 Qt = intern_c_string ("t");
3947 XSYMBOL (Qnil)->value = Qnil;
3948 XSYMBOL (Qnil)->plist = Qnil;
3949 XSYMBOL (Qt)->value = Qt;
3950 XSYMBOL (Qt)->constant = 1;
3952 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3953 Vpurify_flag = Qt;
3955 Qvariable_documentation = intern_c_string ("variable-documentation");
3956 staticpro (&Qvariable_documentation);
3958 read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
3959 read_buffer = (char *) xmalloc (read_buffer_size);
3962 void
3963 defsubr (sname)
3964 struct Lisp_Subr *sname;
3966 Lisp_Object sym;
3967 sym = intern_c_string (sname->symbol_name);
3968 XSETPVECTYPE (sname, PVEC_SUBR);
3969 XSETSUBR (XSYMBOL (sym)->function, sname);
3972 #ifdef NOTDEF /* use fset in subr.el now */
3973 void
3974 defalias (sname, string)
3975 struct Lisp_Subr *sname;
3976 char *string;
3978 Lisp_Object sym;
3979 sym = intern (string);
3980 XSETSUBR (XSYMBOL (sym)->function, sname);
3982 #endif /* NOTDEF */
3984 /* Define an "integer variable"; a symbol whose value is forwarded
3985 to a C variable of type int. Sample call:
3986 DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
3987 void
3988 defvar_int (const char *namestring, EMACS_INT *address)
3990 Lisp_Object sym, val;
3991 sym = intern_c_string (namestring);
3992 val = allocate_misc ();
3993 XMISCTYPE (val) = Lisp_Misc_Intfwd;
3994 XINTFWD (val)->intvar = address;
3995 SET_SYMBOL_VALUE (sym, val);
3998 /* Similar but define a variable whose value is t if address contains 1,
3999 nil if address contains 0. */
4000 void
4001 defvar_bool (const char *namestring, int *address)
4003 Lisp_Object sym, val;
4004 sym = intern_c_string (namestring);
4005 val = allocate_misc ();
4006 XMISCTYPE (val) = Lisp_Misc_Boolfwd;
4007 XBOOLFWD (val)->boolvar = address;
4008 SET_SYMBOL_VALUE (sym, val);
4009 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
4012 /* Similar but define a variable whose value is the Lisp Object stored
4013 at address. Two versions: with and without gc-marking of the C
4014 variable. The nopro version is used when that variable will be
4015 gc-marked for some other reason, since marking the same slot twice
4016 can cause trouble with strings. */
4017 void
4018 defvar_lisp_nopro (const char *namestring, Lisp_Object *address)
4020 Lisp_Object sym, val;
4021 sym = intern_c_string (namestring);
4022 val = allocate_misc ();
4023 XMISCTYPE (val) = Lisp_Misc_Objfwd;
4024 XOBJFWD (val)->objvar = address;
4025 SET_SYMBOL_VALUE (sym, val);
4028 void
4029 defvar_lisp (const char *namestring, Lisp_Object *address)
4031 defvar_lisp_nopro (namestring, address);
4032 staticpro (address);
4035 /* Similar but define a variable whose value is the Lisp Object stored
4036 at a particular offset in the current kboard object. */
4038 void
4039 defvar_kboard (const char *namestring, int offset)
4041 Lisp_Object sym, val;
4042 sym = intern_c_string (namestring);
4043 val = allocate_misc ();
4044 XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd;
4045 XKBOARD_OBJFWD (val)->offset = offset;
4046 SET_SYMBOL_VALUE (sym, val);
4049 /* Record the value of load-path used at the start of dumping
4050 so we can see if the site changed it later during dumping. */
4051 static Lisp_Object dump_path;
4053 void
4054 init_lread ()
4056 char *normal;
4057 int turn_off_warning = 0;
4059 /* Compute the default load-path. */
4060 #ifdef CANNOT_DUMP
4061 normal = PATH_LOADSEARCH;
4062 Vload_path = decode_env_path (0, normal);
4063 #else
4064 if (NILP (Vpurify_flag))
4065 normal = PATH_LOADSEARCH;
4066 else
4067 normal = PATH_DUMPLOADSEARCH;
4069 /* In a dumped Emacs, we normally have to reset the value of
4070 Vload_path from PATH_LOADSEARCH, since the value that was dumped
4071 uses ../lisp, instead of the path of the installed elisp
4072 libraries. However, if it appears that Vload_path was changed
4073 from the default before dumping, don't override that value. */
4074 if (initialized)
4076 if (! NILP (Fequal (dump_path, Vload_path)))
4078 Vload_path = decode_env_path (0, normal);
4079 if (!NILP (Vinstallation_directory))
4081 Lisp_Object tem, tem1, sitelisp;
4083 /* Remove site-lisp dirs from path temporarily and store
4084 them in sitelisp, then conc them on at the end so
4085 they're always first in path. */
4086 sitelisp = Qnil;
4087 while (1)
4089 tem = Fcar (Vload_path);
4090 tem1 = Fstring_match (build_string ("site-lisp"),
4091 tem, Qnil);
4092 if (!NILP (tem1))
4094 Vload_path = Fcdr (Vload_path);
4095 sitelisp = Fcons (tem, sitelisp);
4097 else
4098 break;
4101 /* Add to the path the lisp subdir of the
4102 installation dir, if it exists. */
4103 tem = Fexpand_file_name (build_string ("lisp"),
4104 Vinstallation_directory);
4105 tem1 = Ffile_exists_p (tem);
4106 if (!NILP (tem1))
4108 if (NILP (Fmember (tem, Vload_path)))
4110 turn_off_warning = 1;
4111 Vload_path = Fcons (tem, Vload_path);
4114 else
4115 /* That dir doesn't exist, so add the build-time
4116 Lisp dirs instead. */
4117 Vload_path = nconc2 (Vload_path, dump_path);
4119 /* Add leim under the installation dir, if it exists. */
4120 tem = Fexpand_file_name (build_string ("leim"),
4121 Vinstallation_directory);
4122 tem1 = Ffile_exists_p (tem);
4123 if (!NILP (tem1))
4125 if (NILP (Fmember (tem, Vload_path)))
4126 Vload_path = Fcons (tem, Vload_path);
4129 /* Add site-lisp under the installation dir, if it exists. */
4130 tem = Fexpand_file_name (build_string ("site-lisp"),
4131 Vinstallation_directory);
4132 tem1 = Ffile_exists_p (tem);
4133 if (!NILP (tem1))
4135 if (NILP (Fmember (tem, Vload_path)))
4136 Vload_path = Fcons (tem, Vload_path);
4139 /* If Emacs was not built in the source directory,
4140 and it is run from where it was built, add to load-path
4141 the lisp, leim and site-lisp dirs under that directory. */
4143 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
4145 Lisp_Object tem2;
4147 tem = Fexpand_file_name (build_string ("src/Makefile"),
4148 Vinstallation_directory);
4149 tem1 = Ffile_exists_p (tem);
4151 /* Don't be fooled if they moved the entire source tree
4152 AFTER dumping Emacs. If the build directory is indeed
4153 different from the source dir, src/Makefile.in and
4154 src/Makefile will not be found together. */
4155 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
4156 Vinstallation_directory);
4157 tem2 = Ffile_exists_p (tem);
4158 if (!NILP (tem1) && NILP (tem2))
4160 tem = Fexpand_file_name (build_string ("lisp"),
4161 Vsource_directory);
4163 if (NILP (Fmember (tem, Vload_path)))
4164 Vload_path = Fcons (tem, Vload_path);
4166 tem = Fexpand_file_name (build_string ("leim"),
4167 Vsource_directory);
4169 if (NILP (Fmember (tem, Vload_path)))
4170 Vload_path = Fcons (tem, Vload_path);
4172 tem = Fexpand_file_name (build_string ("site-lisp"),
4173 Vsource_directory);
4175 if (NILP (Fmember (tem, Vload_path)))
4176 Vload_path = Fcons (tem, Vload_path);
4179 if (!NILP (sitelisp))
4180 Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path);
4184 else
4186 /* NORMAL refers to the lisp dir in the source directory. */
4187 /* We used to add ../lisp at the front here, but
4188 that caused trouble because it was copied from dump_path
4189 into Vload_path, above, when Vinstallation_directory was non-nil.
4190 It should be unnecessary. */
4191 Vload_path = decode_env_path (0, normal);
4192 dump_path = Vload_path;
4194 #endif
4196 #if (!(defined (WINDOWSNT) || (defined (HAVE_NS))))
4197 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
4198 almost never correct, thereby causing a warning to be printed out that
4199 confuses users. Since PATH_LOADSEARCH is always overridden by the
4200 EMACSLOADPATH environment variable below, disable the warning on NT. */
4202 /* Warn if dirs in the *standard* path don't exist. */
4203 if (!turn_off_warning)
4205 Lisp_Object path_tail;
4207 for (path_tail = Vload_path;
4208 !NILP (path_tail);
4209 path_tail = XCDR (path_tail))
4211 Lisp_Object dirfile;
4212 dirfile = Fcar (path_tail);
4213 if (STRINGP (dirfile))
4215 dirfile = Fdirectory_file_name (dirfile);
4216 if (access (SDATA (dirfile), 0) < 0)
4217 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4218 XCAR (path_tail));
4222 #endif /* !(WINDOWSNT || HAVE_NS) */
4224 /* If the EMACSLOADPATH environment variable is set, use its value.
4225 This doesn't apply if we're dumping. */
4226 #ifndef CANNOT_DUMP
4227 if (NILP (Vpurify_flag)
4228 && egetenv ("EMACSLOADPATH"))
4229 #endif
4230 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4232 Vvalues = Qnil;
4234 load_in_progress = 0;
4235 Vload_file_name = Qnil;
4237 load_descriptor_list = Qnil;
4239 Vstandard_input = Qt;
4240 Vloads_in_progress = Qnil;
4243 /* Print a warning, using format string FORMAT, that directory DIRNAME
4244 does not exist. Print it on stderr and put it in *Messages*. */
4246 void
4247 dir_warning (format, dirname)
4248 char *format;
4249 Lisp_Object dirname;
4251 char *buffer
4252 = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);
4254 fprintf (stderr, format, SDATA (dirname));
4255 sprintf (buffer, format, SDATA (dirname));
4256 /* Don't log the warning before we've initialized!! */
4257 if (initialized)
4258 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
4261 void
4262 syms_of_lread ()
4264 defsubr (&Sread);
4265 defsubr (&Sread_from_string);
4266 defsubr (&Sintern);
4267 defsubr (&Sintern_soft);
4268 defsubr (&Sunintern);
4269 defsubr (&Sget_load_suffixes);
4270 defsubr (&Sload);
4271 defsubr (&Seval_buffer);
4272 defsubr (&Seval_region);
4273 defsubr (&Sread_char);
4274 defsubr (&Sread_char_exclusive);
4275 defsubr (&Sread_event);
4276 defsubr (&Sget_file_char);
4277 defsubr (&Smapatoms);
4278 defsubr (&Slocate_file_internal);
4280 DEFVAR_LISP ("obarray", &Vobarray,
4281 doc: /* Symbol table for use by `intern' and `read'.
4282 It is a vector whose length ought to be prime for best results.
4283 The vector's contents don't make sense if examined from Lisp programs;
4284 to find all the symbols in an obarray, use `mapatoms'. */);
4286 DEFVAR_LISP ("values", &Vvalues,
4287 doc: /* List of values of all expressions which were read, evaluated and printed.
4288 Order is reverse chronological. */);
4290 DEFVAR_LISP ("standard-input", &Vstandard_input,
4291 doc: /* Stream for read to get input from.
4292 See documentation of `read' for possible values. */);
4293 Vstandard_input = Qt;
4295 DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions,
4296 doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4298 If this variable is a buffer, then only forms read from that buffer
4299 will be added to `read-symbol-positions-list'.
4300 If this variable is t, then all read forms will be added.
4301 The effect of all other values other than nil are not currently
4302 defined, although they may be in the future.
4304 The positions are relative to the last call to `read' or
4305 `read-from-string'. It is probably a bad idea to set this variable at
4306 the toplevel; bind it instead. */);
4307 Vread_with_symbol_positions = Qnil;
4309 DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list,
4310 doc: /* A list mapping read symbols to their positions.
4311 This variable is modified during calls to `read' or
4312 `read-from-string', but only when `read-with-symbol-positions' is
4313 non-nil.
4315 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4316 CHAR-POSITION is an integer giving the offset of that occurrence of the
4317 symbol from the position where `read' or `read-from-string' started.
4319 Note that a symbol will appear multiple times in this list, if it was
4320 read multiple times. The list is in the same order as the symbols
4321 were read in. */);
4322 Vread_symbol_positions_list = Qnil;
4324 DEFVAR_LISP ("read-circle", &Vread_circle,
4325 doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4326 Vread_circle = Qt;
4328 DEFVAR_LISP ("load-path", &Vload_path,
4329 doc: /* *List of directories to search for files to load.
4330 Each element is a string (directory name) or nil (try default directory).
4331 Initialized based on EMACSLOADPATH environment variable, if any,
4332 otherwise to default specified by file `epaths.h' when Emacs was built. */);
4334 DEFVAR_LISP ("load-suffixes", &Vload_suffixes,
4335 doc: /* List of suffixes for (compiled or source) Emacs Lisp files.
4336 This list should not include the empty string.
4337 `load' and related functions try to append these suffixes, in order,
4338 to the specified file name if a Lisp suffix is allowed or required. */);
4339 Vload_suffixes = Fcons (make_pure_c_string (".elc"),
4340 Fcons (make_pure_c_string (".el"), Qnil));
4341 DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes,
4342 doc: /* List of suffixes that indicate representations of \
4343 the same file.
4344 This list should normally start with the empty string.
4346 Enabling Auto Compression mode appends the suffixes in
4347 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4348 mode removes them again. `load' and related functions use this list to
4349 determine whether they should look for compressed versions of a file
4350 and, if so, which suffixes they should try to append to the file name
4351 in order to do so. However, if you want to customize which suffixes
4352 the loading functions recognize as compression suffixes, you should
4353 customize `jka-compr-load-suffixes' rather than the present variable. */);
4354 Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil);
4356 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
4357 doc: /* Non-nil if inside of `load'. */);
4358 Qload_in_progress = intern_c_string ("load-in-progress");
4359 staticpro (&Qload_in_progress);
4361 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
4362 doc: /* An alist of expressions to be evalled when particular files are loaded.
4363 Each element looks like (REGEXP-OR-FEATURE FORMS...).
4365 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4366 a symbol \(a feature name).
4368 When `load' is run and the file-name argument matches an element's
4369 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4370 REGEXP-OR-FEATURE, the FORMS in the element are executed.
4372 An error in FORMS does not undo the load, but does prevent execution of
4373 the rest of the FORMS. */);
4374 Vafter_load_alist = Qnil;
4376 DEFVAR_LISP ("load-history", &Vload_history,
4377 doc: /* Alist mapping loaded file names to symbols and features.
4378 Each alist element should be a list (FILE-NAME ENTRIES...), where
4379 FILE-NAME is the name of a file that has been loaded into Emacs.
4380 The file name is absolute and true (i.e. it doesn't contain symlinks).
4381 As an exception, one of the alist elements may have FILE-NAME nil,
4382 for symbols and features not associated with any file.
4384 The remaining ENTRIES in the alist element describe the functions and
4385 variables defined in that file, the features provided, and the
4386 features required. Each entry has the form `(provide . FEATURE)',
4387 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4388 `(defface . SYMBOL)', or `(t . SYMBOL)'. In addition, an entry `(t
4389 . SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
4390 SYMBOL was an autoload before this file redefined it as a function.
4392 During preloading, the file name recorded is relative to the main Lisp
4393 directory. These file names are converted to absolute at startup. */);
4394 Vload_history = Qnil;
4396 DEFVAR_LISP ("load-file-name", &Vload_file_name,
4397 doc: /* Full name of file being loaded by `load'. */);
4398 Vload_file_name = Qnil;
4400 DEFVAR_LISP ("user-init-file", &Vuser_init_file,
4401 doc: /* File name, including directory, of user's initialization file.
4402 If the file loaded had extension `.elc', and the corresponding source file
4403 exists, this variable contains the name of source file, suitable for use
4404 by functions like `custom-save-all' which edit the init file.
4405 While Emacs loads and evaluates the init file, value is the real name
4406 of the file, regardless of whether or not it has the `.elc' extension. */);
4407 Vuser_init_file = Qnil;
4409 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
4410 doc: /* Used for internal purposes by `load'. */);
4411 Vcurrent_load_list = Qnil;
4413 DEFVAR_LISP ("load-read-function", &Vload_read_function,
4414 doc: /* Function used by `load' and `eval-region' for reading expressions.
4415 The default is nil, which means use the function `read'. */);
4416 Vload_read_function = Qnil;
4418 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
4419 doc: /* Function called in `load' for loading an Emacs Lisp source file.
4420 This function is for doing code conversion before reading the source file.
4421 If nil, loading is done without any code conversion.
4422 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
4423 FULLNAME is the full name of FILE.
4424 See `load' for the meaning of the remaining arguments. */);
4425 Vload_source_file_function = Qnil;
4427 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
4428 doc: /* Non-nil means `load' should force-load all dynamic doc strings.
4429 This is useful when the file being loaded is a temporary copy. */);
4430 load_force_doc_strings = 0;
4432 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
4433 doc: /* Non-nil means `read' converts strings to unibyte whenever possible.
4434 This is normally bound by `load' and `eval-buffer' to control `read',
4435 and is not meant for users to change. */);
4436 load_convert_to_unibyte = 0;
4438 DEFVAR_LISP ("source-directory", &Vsource_directory,
4439 doc: /* Directory in which Emacs sources were found when Emacs was built.
4440 You cannot count on them to still be there! */);
4441 Vsource_directory
4442 = Fexpand_file_name (build_string ("../"),
4443 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
4445 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
4446 doc: /* List of files that were preloaded (when dumping Emacs). */);
4447 Vpreloaded_file_list = Qnil;
4449 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
4450 doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4451 Vbyte_boolean_vars = Qnil;
4453 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries,
4454 doc: /* Non-nil means load dangerous compiled Lisp files.
4455 Some versions of XEmacs use different byte codes than Emacs. These
4456 incompatible byte codes can make Emacs crash when it tries to execute
4457 them. */);
4458 load_dangerous_libraries = 0;
4460 DEFVAR_BOOL ("force-load-messages", &force_load_messages,
4461 doc: /* Non-nil means force printing messages when loading Lisp files.
4462 This overrides the value of the NOMESSAGE argument to `load'. */);
4463 force_load_messages = 0;
4465 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp,
4466 doc: /* Regular expression matching safe to load compiled Lisp files.
4467 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4468 from the file, and matches them against this regular expression.
4469 When the regular expression matches, the file is considered to be safe
4470 to load. See also `load-dangerous-libraries'. */);
4471 Vbytecomp_version_regexp
4472 = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4474 DEFVAR_LISP ("eval-buffer-list", &Veval_buffer_list,
4475 doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4476 Veval_buffer_list = Qnil;
4478 DEFVAR_LISP ("old-style-backquotes", &Vold_style_backquotes,
4479 doc: /* Set to non-nil when `read' encounters an old-style backquote. */);
4480 Vold_style_backquotes = Qnil;
4481 Qold_style_backquotes = intern_c_string ("old-style-backquotes");
4482 staticpro (&Qold_style_backquotes);
4484 /* Vsource_directory was initialized in init_lread. */
4486 load_descriptor_list = Qnil;
4487 staticpro (&load_descriptor_list);
4489 Qcurrent_load_list = intern_c_string ("current-load-list");
4490 staticpro (&Qcurrent_load_list);
4492 Qstandard_input = intern_c_string ("standard-input");
4493 staticpro (&Qstandard_input);
4495 Qread_char = intern_c_string ("read-char");
4496 staticpro (&Qread_char);
4498 Qget_file_char = intern_c_string ("get-file-char");
4499 staticpro (&Qget_file_char);
4501 Qget_emacs_mule_file_char = intern_c_string ("get-emacs-mule-file-char");
4502 staticpro (&Qget_emacs_mule_file_char);
4504 Qload_force_doc_strings = intern_c_string ("load-force-doc-strings");
4505 staticpro (&Qload_force_doc_strings);
4507 Qbackquote = intern_c_string ("`");
4508 staticpro (&Qbackquote);
4509 Qcomma = intern_c_string (",");
4510 staticpro (&Qcomma);
4511 Qcomma_at = intern_c_string (",@");
4512 staticpro (&Qcomma_at);
4513 Qcomma_dot = intern_c_string (",.");
4514 staticpro (&Qcomma_dot);
4516 Qinhibit_file_name_operation = intern_c_string ("inhibit-file-name-operation");
4517 staticpro (&Qinhibit_file_name_operation);
4519 Qascii_character = intern_c_string ("ascii-character");
4520 staticpro (&Qascii_character);
4522 Qfunction = intern_c_string ("function");
4523 staticpro (&Qfunction);
4525 Qload = intern_c_string ("load");
4526 staticpro (&Qload);
4528 Qload_file_name = intern_c_string ("load-file-name");
4529 staticpro (&Qload_file_name);
4531 Qeval_buffer_list = intern_c_string ("eval-buffer-list");
4532 staticpro (&Qeval_buffer_list);
4534 Qfile_truename = intern_c_string ("file-truename");
4535 staticpro (&Qfile_truename) ;
4537 Qdo_after_load_evaluation = intern_c_string ("do-after-load-evaluation");
4538 staticpro (&Qdo_after_load_evaluation) ;
4540 staticpro (&dump_path);
4542 staticpro (&read_objects);
4543 read_objects = Qnil;
4544 staticpro (&seen_list);
4545 seen_list = Qnil;
4547 Vloads_in_progress = Qnil;
4548 staticpro (&Vloads_in_progress);
4550 Qhash_table = intern_c_string ("hash-table");
4551 staticpro (&Qhash_table);
4552 Qdata = intern_c_string ("data");
4553 staticpro (&Qdata);
4554 Qtest = intern_c_string ("test");
4555 staticpro (&Qtest);
4556 Qsize = intern_c_string ("size");
4557 staticpro (&Qsize);
4558 Qweakness = intern_c_string ("weakness");
4559 staticpro (&Qweakness);
4560 Qrehash_size = intern_c_string ("rehash-size");
4561 staticpro (&Qrehash_size);
4562 Qrehash_threshold = intern_c_string ("rehash-threshold");
4563 staticpro (&Qrehash_threshold);
4566 /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d
4567 (do not change this comment) */