xfns.c (Fx_create_frame) [USE_LUCID]: Add BLOCK_INPUT around XLoadQueryFont.
[emacs.git] / src / lread.c
blobba9d5378104f462c9eca9f2669b7156302f803bf
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 #if __DJGPP__ < 2
45 #include <unistd.h> /* to get X_OK */
46 #endif
47 #include "msdos.h"
48 #endif
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
54 #ifndef X_OK
55 #define X_OK 01
56 #endif
58 #include <math.h>
60 #ifdef HAVE_SETLOCALE
61 #include <locale.h>
62 #endif /* HAVE_SETLOCALE */
64 #ifdef HAVE_FCNTL_H
65 #include <fcntl.h>
66 #endif
67 #ifndef O_RDONLY
68 #define O_RDONLY 0
69 #endif
71 #ifdef HAVE_FSEEKO
72 #define file_offset off_t
73 #define file_tell ftello
74 #else
75 #define file_offset long
76 #define file_tell ftell
77 #endif
79 #ifndef USE_CRT_DLL
80 extern int errno;
81 #endif
83 /* hash table read constants */
84 Lisp_Object Qhash_table, Qdata;
85 Lisp_Object Qtest, Qsize;
86 Lisp_Object Qweakness;
87 Lisp_Object Qrehash_size;
88 Lisp_Object Qrehash_threshold;
89 extern Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
91 Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
92 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
93 Lisp_Object Qascii_character, Qload, Qload_file_name;
94 Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
95 Lisp_Object Qinhibit_file_name_operation;
96 Lisp_Object Qeval_buffer_list, Veval_buffer_list;
97 Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */
99 /* Used instead of Qget_file_char while loading *.elc files compiled
100 by Emacs 21 or older. */
101 static Lisp_Object Qget_emacs_mule_file_char;
103 static Lisp_Object Qload_force_doc_strings;
105 extern Lisp_Object Qevent_symbol_element_mask;
106 extern Lisp_Object Qfile_exists_p;
108 /* non-zero if inside `load' */
109 int load_in_progress;
110 static Lisp_Object Qload_in_progress;
112 /* Directory in which the sources were found. */
113 Lisp_Object Vsource_directory;
115 /* Search path and suffixes for files to be loaded. */
116 Lisp_Object Vload_path, Vload_suffixes, Vload_file_rep_suffixes;
118 /* File name of user's init file. */
119 Lisp_Object Vuser_init_file;
121 /* This is the user-visible association list that maps features to
122 lists of defs in their load files. */
123 Lisp_Object Vload_history;
125 /* This is used to build the load history. */
126 Lisp_Object Vcurrent_load_list;
128 /* List of files that were preloaded. */
129 Lisp_Object Vpreloaded_file_list;
131 /* Name of file actually being read by `load'. */
132 Lisp_Object Vload_file_name;
134 /* Function to use for reading, in `load' and friends. */
135 Lisp_Object Vload_read_function;
137 /* Non-nil means read recursive structures using #n= and #n# syntax. */
138 Lisp_Object Vread_circle;
140 /* The association list of objects read with the #n=object form.
141 Each member of the list has the form (n . object), and is used to
142 look up the object for the corresponding #n# construct.
143 It must be set to nil before all top-level calls to read0. */
144 Lisp_Object read_objects;
146 /* Nonzero means load should forcibly load all dynamic doc strings. */
147 static int load_force_doc_strings;
149 /* Nonzero means read should convert strings to unibyte. */
150 static int load_convert_to_unibyte;
152 /* Nonzero means READCHAR should read bytes one by one (not character)
153 when READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char.
154 This is set to 1 by read1 temporarily while handling #@NUMBER. */
155 static int load_each_byte;
157 /* Function to use for loading an Emacs Lisp source file (not
158 compiled) instead of readevalloop. */
159 Lisp_Object Vload_source_file_function;
161 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
162 Lisp_Object Vbyte_boolean_vars;
164 /* Whether or not to add a `read-positions' property to symbols
165 read. */
166 Lisp_Object Vread_with_symbol_positions;
168 /* List of (SYMBOL . POSITION) accumulated so far. */
169 Lisp_Object Vread_symbol_positions_list;
171 /* List of descriptors now open for Fload. */
172 static Lisp_Object load_descriptor_list;
174 /* File for get_file_char to read from. Use by load. */
175 static FILE *instream;
177 /* When nonzero, read conses in pure space */
178 static int read_pure;
180 /* For use within read-from-string (this reader is non-reentrant!!) */
181 static int read_from_string_index;
182 static int read_from_string_index_byte;
183 static int read_from_string_limit;
185 /* Number of characters read in the current call to Fread or
186 Fread_from_string. */
187 static int readchar_count;
189 /* This contains the last string skipped with #@. */
190 static char *saved_doc_string;
191 /* Length of buffer allocated in saved_doc_string. */
192 static int saved_doc_string_size;
193 /* Length of actual data in saved_doc_string. */
194 static int saved_doc_string_length;
195 /* This is the file position that string came from. */
196 static file_offset saved_doc_string_position;
198 /* This contains the previous string skipped with #@.
199 We copy it from saved_doc_string when a new string
200 is put in saved_doc_string. */
201 static char *prev_saved_doc_string;
202 /* Length of buffer allocated in prev_saved_doc_string. */
203 static int prev_saved_doc_string_size;
204 /* Length of actual data in prev_saved_doc_string. */
205 static int prev_saved_doc_string_length;
206 /* This is the file position that string came from. */
207 static file_offset prev_saved_doc_string_position;
209 /* Nonzero means inside a new-style backquote
210 with no surrounding parentheses.
211 Fread initializes this to zero, so we need not specbind it
212 or worry about what happens to it when there is an error. */
213 static int new_backquote_flag;
214 static Lisp_Object Vold_style_backquotes, Qold_style_backquotes;
216 /* A list of file names for files being loaded in Fload. Used to
217 check for recursive loads. */
219 static Lisp_Object Vloads_in_progress;
221 /* Non-zero means load dangerous compiled Lisp files. */
223 int load_dangerous_libraries;
225 /* Non-zero means force printing messages when loading Lisp files. */
227 int force_load_messages;
229 /* A regular expression used to detect files compiled with Emacs. */
231 static Lisp_Object Vbytecomp_version_regexp;
233 static int read_emacs_mule_char P_ ((int, int (*) (int, Lisp_Object),
234 Lisp_Object));
236 static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
237 Lisp_Object (*) (), int,
238 Lisp_Object, Lisp_Object,
239 Lisp_Object, Lisp_Object));
240 static Lisp_Object load_unwind P_ ((Lisp_Object));
241 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
243 static void invalid_syntax P_ ((const char *, int)) NO_RETURN;
244 static void end_of_file_error P_ (()) NO_RETURN;
247 /* Functions that read one byte from the current source READCHARFUN
248 or unreads one byte. If the integer argument C is -1, it returns
249 one read byte, or -1 when there's no more byte in the source. If C
250 is 0 or positive, it unreads C, and the return value is not
251 interesting. */
253 static int readbyte_for_lambda P_ ((int, Lisp_Object));
254 static int readbyte_from_file P_ ((int, Lisp_Object));
255 static int readbyte_from_string P_ ((int, Lisp_Object));
257 /* Handle unreading and rereading of characters.
258 Write READCHAR to read a character,
259 UNREAD(c) to unread c to be read again.
261 These macros correctly read/unread multibyte characters. */
263 #define READCHAR readchar (readcharfun, NULL)
264 #define UNREAD(c) unreadchar (readcharfun, c)
266 /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
267 #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
269 /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
270 Qlambda, or a cons, we use this to keep an unread character because
271 a file stream can't handle multibyte-char unreading. The value -1
272 means that there's no unread character. */
273 static int unread_char;
275 static int
276 readchar (readcharfun, multibyte)
277 Lisp_Object readcharfun;
278 int *multibyte;
280 Lisp_Object tem;
281 register int c;
282 int (*readbyte) P_ ((int, Lisp_Object));
283 unsigned char buf[MAX_MULTIBYTE_LENGTH];
284 int i, len;
285 int emacs_mule_encoding = 0;
287 if (multibyte)
288 *multibyte = 0;
290 readchar_count++;
292 if (BUFFERP (readcharfun))
294 register struct buffer *inbuffer = XBUFFER (readcharfun);
296 int pt_byte = BUF_PT_BYTE (inbuffer);
298 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
299 return -1;
301 if (! NILP (inbuffer->enable_multibyte_characters))
303 /* Fetch the character code from the buffer. */
304 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
305 BUF_INC_POS (inbuffer, pt_byte);
306 c = STRING_CHAR (p);
307 if (multibyte)
308 *multibyte = 1;
310 else
312 c = BUF_FETCH_BYTE (inbuffer, pt_byte);
313 if (! ASCII_BYTE_P (c))
314 c = BYTE8_TO_CHAR (c);
315 pt_byte++;
317 SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
319 return c;
321 if (MARKERP (readcharfun))
323 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
325 int bytepos = marker_byte_position (readcharfun);
327 if (bytepos >= BUF_ZV_BYTE (inbuffer))
328 return -1;
330 if (! NILP (inbuffer->enable_multibyte_characters))
332 /* Fetch the character code from the buffer. */
333 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
334 BUF_INC_POS (inbuffer, bytepos);
335 c = STRING_CHAR (p);
336 if (multibyte)
337 *multibyte = 1;
339 else
341 c = BUF_FETCH_BYTE (inbuffer, bytepos);
342 if (! ASCII_BYTE_P (c))
343 c = BYTE8_TO_CHAR (c);
344 bytepos++;
347 XMARKER (readcharfun)->bytepos = bytepos;
348 XMARKER (readcharfun)->charpos++;
350 return c;
353 if (EQ (readcharfun, Qlambda))
355 readbyte = readbyte_for_lambda;
356 goto read_multibyte;
359 if (EQ (readcharfun, Qget_file_char))
361 readbyte = readbyte_from_file;
362 goto read_multibyte;
365 if (STRINGP (readcharfun))
367 if (read_from_string_index >= read_from_string_limit)
368 c = -1;
369 else if (STRING_MULTIBYTE (readcharfun))
371 if (multibyte)
372 *multibyte = 1;
373 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, readcharfun,
374 read_from_string_index,
375 read_from_string_index_byte);
377 else
379 c = SREF (readcharfun, read_from_string_index_byte);
380 read_from_string_index++;
381 read_from_string_index_byte++;
383 return c;
386 if (CONSP (readcharfun))
388 /* This is the case that read_vector is reading from a unibyte
389 string that contains a byte sequence previously skipped
390 because of #@NUMBER. The car part of readcharfun is that
391 string, and the cdr part is a value of readcharfun given to
392 read_vector. */
393 readbyte = readbyte_from_string;
394 if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char))
395 emacs_mule_encoding = 1;
396 goto read_multibyte;
399 if (EQ (readcharfun, Qget_emacs_mule_file_char))
401 readbyte = readbyte_from_file;
402 emacs_mule_encoding = 1;
403 goto read_multibyte;
406 tem = call0 (readcharfun);
408 if (NILP (tem))
409 return -1;
410 return XINT (tem);
412 read_multibyte:
413 if (unread_char >= 0)
415 c = unread_char;
416 unread_char = -1;
417 return c;
419 c = (*readbyte) (-1, readcharfun);
420 if (c < 0 || load_each_byte)
421 return c;
422 if (multibyte)
423 *multibyte = 1;
424 if (ASCII_BYTE_P (c))
425 return c;
426 if (emacs_mule_encoding)
427 return read_emacs_mule_char (c, readbyte, readcharfun);
428 i = 0;
429 buf[i++] = c;
430 len = BYTES_BY_CHAR_HEAD (c);
431 while (i < len)
433 c = (*readbyte) (-1, readcharfun);
434 if (c < 0 || ! TRAILING_CODE_P (c))
436 while (--i > 1)
437 (*readbyte) (buf[i], readcharfun);
438 return BYTE8_TO_CHAR (buf[0]);
440 buf[i++] = c;
442 return STRING_CHAR (buf);
445 /* Unread the character C in the way appropriate for the stream READCHARFUN.
446 If the stream is a user function, call it with the char as argument. */
448 static void
449 unreadchar (readcharfun, c)
450 Lisp_Object readcharfun;
451 int c;
453 readchar_count--;
454 if (c == -1)
455 /* Don't back up the pointer if we're unreading the end-of-input mark,
456 since readchar didn't advance it when we read it. */
458 else if (BUFFERP (readcharfun))
460 struct buffer *b = XBUFFER (readcharfun);
461 int bytepos = BUF_PT_BYTE (b);
463 BUF_PT (b)--;
464 if (! NILP (b->enable_multibyte_characters))
465 BUF_DEC_POS (b, bytepos);
466 else
467 bytepos--;
469 BUF_PT_BYTE (b) = bytepos;
471 else if (MARKERP (readcharfun))
473 struct buffer *b = XMARKER (readcharfun)->buffer;
474 int bytepos = XMARKER (readcharfun)->bytepos;
476 XMARKER (readcharfun)->charpos--;
477 if (! NILP (b->enable_multibyte_characters))
478 BUF_DEC_POS (b, bytepos);
479 else
480 bytepos--;
482 XMARKER (readcharfun)->bytepos = bytepos;
484 else if (STRINGP (readcharfun))
486 read_from_string_index--;
487 read_from_string_index_byte
488 = string_char_to_byte (readcharfun, read_from_string_index);
490 else if (CONSP (readcharfun))
492 unread_char = c;
494 else if (EQ (readcharfun, Qlambda))
496 unread_char = c;
498 else if (EQ (readcharfun, Qget_file_char)
499 || EQ (readcharfun, Qget_emacs_mule_file_char))
501 if (load_each_byte)
503 BLOCK_INPUT;
504 ungetc (c, instream);
505 UNBLOCK_INPUT;
507 else
508 unread_char = c;
510 else
511 call1 (readcharfun, make_number (c));
514 static int
515 readbyte_for_lambda (c, readcharfun)
516 int c;
517 Lisp_Object readcharfun;
519 return read_bytecode_char (c >= 0);
523 static int
524 readbyte_from_file (c, readcharfun)
525 int c;
526 Lisp_Object readcharfun;
528 if (c >= 0)
530 BLOCK_INPUT;
531 ungetc (c, instream);
532 UNBLOCK_INPUT;
533 return 0;
536 BLOCK_INPUT;
537 c = getc (instream);
539 #ifdef EINTR
540 /* Interrupted reads have been observed while reading over the network */
541 while (c == EOF && ferror (instream) && errno == EINTR)
543 UNBLOCK_INPUT;
544 QUIT;
545 BLOCK_INPUT;
546 clearerr (instream);
547 c = getc (instream);
549 #endif
551 UNBLOCK_INPUT;
553 return (c == EOF ? -1 : c);
556 static int
557 readbyte_from_string (c, readcharfun)
558 int c;
559 Lisp_Object readcharfun;
561 Lisp_Object string = XCAR (readcharfun);
563 if (c >= 0)
565 read_from_string_index--;
566 read_from_string_index_byte
567 = string_char_to_byte (string, read_from_string_index);
570 if (read_from_string_index >= read_from_string_limit)
571 c = -1;
572 else
573 FETCH_STRING_CHAR_ADVANCE (c, string,
574 read_from_string_index,
575 read_from_string_index_byte);
576 return c;
580 /* Read one non-ASCII character from INSTREAM. The character is
581 encoded in `emacs-mule' and the first byte is already read in
582 C. */
584 extern char emacs_mule_bytes[256];
586 static int
587 read_emacs_mule_char (c, readbyte, readcharfun)
588 int c;
589 int (*readbyte) P_ ((int, Lisp_Object));
590 Lisp_Object readcharfun;
592 /* Emacs-mule coding uses at most 4-byte for one character. */
593 unsigned char buf[4];
594 int len = emacs_mule_bytes[c];
595 struct charset *charset;
596 int i;
597 unsigned code;
599 if (len == 1)
600 /* C is not a valid leading-code of `emacs-mule'. */
601 return BYTE8_TO_CHAR (c);
603 i = 0;
604 buf[i++] = c;
605 while (i < len)
607 c = (*readbyte) (-1, readcharfun);
608 if (c < 0xA0)
610 while (--i > 1)
611 (*readbyte) (buf[i], readcharfun);
612 return BYTE8_TO_CHAR (buf[0]);
614 buf[i++] = c;
617 if (len == 2)
619 charset = emacs_mule_charset[buf[0]];
620 code = buf[1] & 0x7F;
622 else if (len == 3)
624 if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11
625 || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12)
627 charset = emacs_mule_charset[buf[1]];
628 code = buf[2] & 0x7F;
630 else
632 charset = emacs_mule_charset[buf[0]];
633 code = ((buf[1] << 8) | buf[2]) & 0x7F7F;
636 else
638 charset = emacs_mule_charset[buf[1]];
639 code = ((buf[2] << 8) | buf[3]) & 0x7F7F;
641 c = DECODE_CHAR (charset, code);
642 if (c < 0)
643 Fsignal (Qinvalid_read_syntax,
644 Fcons (build_string ("invalid multibyte form"), Qnil));
645 return c;
649 static Lisp_Object read_internal_start P_ ((Lisp_Object, Lisp_Object,
650 Lisp_Object));
651 static Lisp_Object read0 P_ ((Lisp_Object));
652 static Lisp_Object read1 P_ ((Lisp_Object, int *, int));
654 static Lisp_Object read_list P_ ((int, Lisp_Object));
655 static Lisp_Object read_vector P_ ((Lisp_Object, int));
657 static Lisp_Object substitute_object_recurse P_ ((Lisp_Object, Lisp_Object,
658 Lisp_Object));
659 static void substitute_object_in_subtree P_ ((Lisp_Object,
660 Lisp_Object));
661 static void substitute_in_interval P_ ((INTERVAL, Lisp_Object));
664 /* Get a character from the tty. */
666 /* Read input events until we get one that's acceptable for our purposes.
668 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
669 until we get a character we like, and then stuffed into
670 unread_switch_frame.
672 If ASCII_REQUIRED is non-zero, we check function key events to see
673 if the unmodified version of the symbol has a Qascii_character
674 property, and use that character, if present.
676 If ERROR_NONASCII is non-zero, we signal an error if the input we
677 get isn't an ASCII character with modifiers. If it's zero but
678 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
679 character.
681 If INPUT_METHOD is nonzero, we invoke the current input method
682 if the character warrants that.
684 If SECONDS is a number, we wait that many seconds for input, and
685 return Qnil if no input arrives within that time. */
687 Lisp_Object
688 read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
689 input_method, seconds)
690 int no_switch_frame, ascii_required, error_nonascii, input_method;
691 Lisp_Object seconds;
693 Lisp_Object val, delayed_switch_frame;
694 EMACS_TIME end_time;
696 #ifdef HAVE_WINDOW_SYSTEM
697 if (display_hourglass_p)
698 cancel_hourglass ();
699 #endif
701 delayed_switch_frame = Qnil;
703 /* Compute timeout. */
704 if (NUMBERP (seconds))
706 EMACS_TIME wait_time;
707 int sec, usec;
708 double duration = extract_float (seconds);
710 sec = (int) duration;
711 usec = (duration - sec) * 1000000;
712 EMACS_GET_TIME (end_time);
713 EMACS_SET_SECS_USECS (wait_time, sec, usec);
714 EMACS_ADD_TIME (end_time, end_time, wait_time);
717 /* Read until we get an acceptable event. */
718 retry:
720 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0,
721 NUMBERP (seconds) ? &end_time : NULL);
722 while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */
724 if (BUFFERP (val))
725 goto retry;
727 /* switch-frame events are put off until after the next ASCII
728 character. This is better than signaling an error just because
729 the last characters were typed to a separate minibuffer frame,
730 for example. Eventually, some code which can deal with
731 switch-frame events will read it and process it. */
732 if (no_switch_frame
733 && EVENT_HAS_PARAMETERS (val)
734 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame))
736 delayed_switch_frame = val;
737 goto retry;
740 if (ascii_required && !(NUMBERP (seconds) && NILP (val)))
742 /* Convert certain symbols to their ASCII equivalents. */
743 if (SYMBOLP (val))
745 Lisp_Object tem, tem1;
746 tem = Fget (val, Qevent_symbol_element_mask);
747 if (!NILP (tem))
749 tem1 = Fget (Fcar (tem), Qascii_character);
750 /* Merge this symbol's modifier bits
751 with the ASCII equivalent of its basic code. */
752 if (!NILP (tem1))
753 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
757 /* If we don't have a character now, deal with it appropriately. */
758 if (!INTEGERP (val))
760 if (error_nonascii)
762 Vunread_command_events = Fcons (val, Qnil);
763 error ("Non-character input-event");
765 else
766 goto retry;
770 if (! NILP (delayed_switch_frame))
771 unread_switch_frame = delayed_switch_frame;
773 #if 0
775 #ifdef HAVE_WINDOW_SYSTEM
776 if (display_hourglass_p)
777 start_hourglass ();
778 #endif
780 #endif
782 return val;
785 DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
786 doc: /* Read a character from the command input (keyboard or macro).
787 It is returned as a number.
788 If the character has modifiers, they are resolved and reflected to the
789 character code if possible (e.g. C-SPC -> 0).
791 If the user generates an event which is not a character (i.e. a mouse
792 click or function key event), `read-char' signals an error. As an
793 exception, switch-frame events are put off until non-character events
794 can be read.
795 If you want to read non-character events, or ignore them, call
796 `read-event' or `read-char-exclusive' instead.
798 If the optional argument PROMPT is non-nil, display that as a prompt.
799 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
800 input method is turned on in the current buffer, that input method
801 is used for reading a character.
802 If the optional argument SECONDS is non-nil, it should be a number
803 specifying the maximum number of seconds to wait for input. If no
804 input arrives in that time, return nil. SECONDS may be a
805 floating-point value. */)
806 (prompt, inherit_input_method, seconds)
807 Lisp_Object prompt, inherit_input_method, seconds;
809 Lisp_Object val;
811 if (! NILP (prompt))
812 message_with_string ("%s", prompt, 0);
813 val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
815 return (NILP (val) ? Qnil
816 : make_number (char_resolve_modifier_mask (XINT (val))));
819 DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
820 doc: /* Read an event object from the input stream.
821 If the optional argument PROMPT is non-nil, display that as a prompt.
822 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
823 input method is turned on in the current buffer, that input method
824 is used for reading a character.
825 If the optional argument SECONDS is non-nil, it should be a number
826 specifying the maximum number of seconds to wait for input. If no
827 input arrives in that time, return nil. SECONDS may be a
828 floating-point value. */)
829 (prompt, inherit_input_method, seconds)
830 Lisp_Object prompt, inherit_input_method, seconds;
832 if (! NILP (prompt))
833 message_with_string ("%s", prompt, 0);
834 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds);
837 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0,
838 doc: /* Read a character from the command input (keyboard or macro).
839 It is returned as a number. Non-character events are ignored.
840 If the character has modifiers, they are resolved and reflected to the
841 character code if possible (e.g. C-SPC -> 0).
843 If the optional argument PROMPT is non-nil, display that as a prompt.
844 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
845 input method is turned on in the current buffer, that input method
846 is used for reading a character.
847 If the optional argument SECONDS is non-nil, it should be a number
848 specifying the maximum number of seconds to wait for input. If no
849 input arrives in that time, return nil. SECONDS may be a
850 floating-point value. */)
851 (prompt, inherit_input_method, seconds)
852 Lisp_Object prompt, inherit_input_method, seconds;
854 Lisp_Object val;
856 if (! NILP (prompt))
857 message_with_string ("%s", prompt, 0);
859 val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds);
861 return (NILP (val) ? Qnil
862 : make_number (char_resolve_modifier_mask (XINT (val))));
865 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
866 doc: /* Don't use this yourself. */)
869 register Lisp_Object val;
870 BLOCK_INPUT;
871 XSETINT (val, getc (instream));
872 UNBLOCK_INPUT;
873 return val;
878 /* Value is a version number of byte compiled code if the file
879 associated with file descriptor FD is a compiled Lisp file that's
880 safe to load. Only files compiled with Emacs are safe to load.
881 Files compiled with XEmacs can lead to a crash in Fbyte_code
882 because of an incompatible change in the byte compiler. */
884 static int
885 safe_to_load_p (fd)
886 int fd;
888 char buf[512];
889 int nbytes, i;
890 int safe_p = 1;
891 int version = 1;
893 /* Read the first few bytes from the file, and look for a line
894 specifying the byte compiler version used. */
895 nbytes = emacs_read (fd, buf, sizeof buf - 1);
896 if (nbytes > 0)
898 buf[nbytes] = '\0';
900 /* Skip to the next newline, skipping over the initial `ELC'
901 with NUL bytes following it, but note the version. */
902 for (i = 0; i < nbytes && buf[i] != '\n'; ++i)
903 if (i == 4)
904 version = buf[i];
906 if (i == nbytes
907 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
908 buf + i) < 0)
909 safe_p = 0;
911 if (safe_p)
912 safe_p = version;
914 lseek (fd, 0, SEEK_SET);
915 return safe_p;
919 /* Callback for record_unwind_protect. Restore the old load list OLD,
920 after loading a file successfully. */
922 static Lisp_Object
923 record_load_unwind (old)
924 Lisp_Object old;
926 return Vloads_in_progress = old;
929 /* This handler function is used via internal_condition_case_1. */
931 static Lisp_Object
932 load_error_handler (data)
933 Lisp_Object data;
935 return Qnil;
938 static Lisp_Object
939 load_warn_old_style_backquotes (file)
940 Lisp_Object file;
942 if (!NILP (Vold_style_backquotes))
944 Lisp_Object args[2];
945 args[0] = build_string ("Loading `%s': old-style backquotes detected!");
946 args[1] = file;
947 Fmessage (2, args);
949 return Qnil;
952 DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
953 doc: /* Return the suffixes that `load' should try if a suffix is \
954 required.
955 This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
958 Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext;
959 while (CONSP (suffixes))
961 Lisp_Object exts = Vload_file_rep_suffixes;
962 suffix = XCAR (suffixes);
963 suffixes = XCDR (suffixes);
964 while (CONSP (exts))
966 ext = XCAR (exts);
967 exts = XCDR (exts);
968 lst = Fcons (concat2 (suffix, ext), lst);
971 return Fnreverse (lst);
974 DEFUN ("load", Fload, Sload, 1, 5, 0,
975 doc: /* Execute a file of Lisp code named FILE.
976 First try FILE with `.elc' appended, then try with `.el',
977 then try FILE unmodified (the exact suffixes in the exact order are
978 determined by `load-suffixes'). Environment variable references in
979 FILE are replaced with their values by calling `substitute-in-file-name'.
980 This function searches the directories in `load-path'.
982 If optional second arg NOERROR is non-nil,
983 report no error if FILE doesn't exist.
984 Print messages at start and end of loading unless
985 optional third arg NOMESSAGE is non-nil (but `force-load-messages'
986 overrides that).
987 If optional fourth arg NOSUFFIX is non-nil, don't try adding
988 suffixes `.elc' or `.el' to the specified name FILE.
989 If optional fifth arg MUST-SUFFIX is non-nil, insist on
990 the suffix `.elc' or `.el'; don't accept just FILE unless
991 it ends in one of those suffixes or includes a directory name.
993 If this function fails to find a file, it may look for different
994 representations of that file before trying another file.
995 It does so by adding the non-empty suffixes in `load-file-rep-suffixes'
996 to the file name. Emacs uses this feature mainly to find compressed
997 versions of files when Auto Compression mode is enabled.
999 The exact suffixes that this function tries out, in the exact order,
1000 are given by the value of the variable `load-file-rep-suffixes' if
1001 NOSUFFIX is non-nil and by the return value of the function
1002 `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and
1003 MUST-SUFFIX are nil, this function first tries out the latter suffixes
1004 and then the former.
1006 Loading a file records its definitions, and its `provide' and
1007 `require' calls, in an element of `load-history' whose
1008 car is the file name loaded. See `load-history'.
1010 Return t if the file exists and loads successfully. */)
1011 (file, noerror, nomessage, nosuffix, must_suffix)
1012 Lisp_Object file, noerror, nomessage, nosuffix, must_suffix;
1014 register FILE *stream;
1015 register int fd = -1;
1016 int count = SPECPDL_INDEX ();
1017 struct gcpro gcpro1, gcpro2, gcpro3;
1018 Lisp_Object found, efound, hist_file_name;
1019 /* 1 means we printed the ".el is newer" message. */
1020 int newer = 0;
1021 /* 1 means we are loading a compiled file. */
1022 int compiled = 0;
1023 Lisp_Object handler;
1024 int safe_p = 1;
1025 char *fmode = "r";
1026 Lisp_Object tmp[2];
1027 int version;
1029 #ifdef DOS_NT
1030 fmode = "rt";
1031 #endif /* DOS_NT */
1033 CHECK_STRING (file);
1035 /* If file name is magic, call the handler. */
1036 /* This shouldn't be necessary any more now that `openp' handles it right.
1037 handler = Ffind_file_name_handler (file, Qload);
1038 if (!NILP (handler))
1039 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
1041 /* Do this after the handler to avoid
1042 the need to gcpro noerror, nomessage and nosuffix.
1043 (Below here, we care only whether they are nil or not.)
1044 The presence of this call is the result of a historical accident:
1045 it used to be in every file-operation and when it got removed
1046 everywhere, it accidentally stayed here. Since then, enough people
1047 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
1048 that it seemed risky to remove. */
1049 if (! NILP (noerror))
1051 file = internal_condition_case_1 (Fsubstitute_in_file_name, file,
1052 Qt, load_error_handler);
1053 if (NILP (file))
1054 return Qnil;
1056 else
1057 file = Fsubstitute_in_file_name (file);
1060 /* Avoid weird lossage with null string as arg,
1061 since it would try to load a directory as a Lisp file */
1062 if (SCHARS (file) > 0)
1064 int size = SBYTES (file);
1066 found = Qnil;
1067 GCPRO2 (file, found);
1069 if (! NILP (must_suffix))
1071 /* Don't insist on adding a suffix if FILE already ends with one. */
1072 if (size > 3
1073 && !strcmp (SDATA (file) + size - 3, ".el"))
1074 must_suffix = Qnil;
1075 else if (size > 4
1076 && !strcmp (SDATA (file) + size - 4, ".elc"))
1077 must_suffix = Qnil;
1078 /* Don't insist on adding a suffix
1079 if the argument includes a directory name. */
1080 else if (! NILP (Ffile_name_directory (file)))
1081 must_suffix = Qnil;
1084 fd = openp (Vload_path, file,
1085 (!NILP (nosuffix) ? Qnil
1086 : !NILP (must_suffix) ? Fget_load_suffixes ()
1087 : Fappend (2, (tmp[0] = Fget_load_suffixes (),
1088 tmp[1] = Vload_file_rep_suffixes,
1089 tmp))),
1090 &found, Qnil);
1091 UNGCPRO;
1094 if (fd == -1)
1096 if (NILP (noerror))
1097 xsignal2 (Qfile_error, build_string ("Cannot open load file"), file);
1098 return Qnil;
1101 /* Tell startup.el whether or not we found the user's init file. */
1102 if (EQ (Qt, Vuser_init_file))
1103 Vuser_init_file = found;
1105 /* If FD is -2, that means openp found a magic file. */
1106 if (fd == -2)
1108 if (NILP (Fequal (found, file)))
1109 /* If FOUND is a different file name from FILE,
1110 find its handler even if we have already inhibited
1111 the `load' operation on FILE. */
1112 handler = Ffind_file_name_handler (found, Qt);
1113 else
1114 handler = Ffind_file_name_handler (found, Qload);
1115 if (! NILP (handler))
1116 return call5 (handler, Qload, found, noerror, nomessage, Qt);
1119 /* Check if we're stuck in a recursive load cycle.
1121 2000-09-21: It's not possible to just check for the file loaded
1122 being a member of Vloads_in_progress. This fails because of the
1123 way the byte compiler currently works; `provide's are not
1124 evaluated, see font-lock.el/jit-lock.el as an example. This
1125 leads to a certain amount of ``normal'' recursion.
1127 Also, just loading a file recursively is not always an error in
1128 the general case; the second load may do something different. */
1130 int count = 0;
1131 Lisp_Object tem;
1132 for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
1133 if (!NILP (Fequal (found, XCAR (tem))) && (++count > 3))
1135 if (fd >= 0)
1136 emacs_close (fd);
1137 signal_error ("Recursive load", Fcons (found, Vloads_in_progress));
1139 record_unwind_protect (record_load_unwind, Vloads_in_progress);
1140 Vloads_in_progress = Fcons (found, Vloads_in_progress);
1143 /* Get the name for load-history. */
1144 hist_file_name = (! NILP (Vpurify_flag)
1145 ? Fconcat (2, (tmp[0] = Ffile_name_directory (file),
1146 tmp[1] = Ffile_name_nondirectory (found),
1147 tmp))
1148 : found) ;
1150 version = -1;
1152 /* Check for the presence of old-style quotes and warn about them. */
1153 specbind (Qold_style_backquotes, Qnil);
1154 record_unwind_protect (load_warn_old_style_backquotes, file);
1156 if (!bcmp (SDATA (found) + SBYTES (found) - 4,
1157 ".elc", 4)
1158 || (fd >= 0 && (version = safe_to_load_p (fd)) > 0))
1159 /* Load .elc files directly, but not when they are
1160 remote and have no handler! */
1162 if (fd != -2)
1164 struct stat s1, s2;
1165 int result;
1167 GCPRO3 (file, found, hist_file_name);
1169 if (version < 0
1170 && ! (version = safe_to_load_p (fd)))
1172 safe_p = 0;
1173 if (!load_dangerous_libraries)
1175 if (fd >= 0)
1176 emacs_close (fd);
1177 error ("File `%s' was not compiled in Emacs",
1178 SDATA (found));
1180 else if (!NILP (nomessage) && !force_load_messages)
1181 message_with_string ("File `%s' not compiled in Emacs", found, 1);
1184 compiled = 1;
1186 efound = ENCODE_FILE (found);
1188 #ifdef DOS_NT
1189 fmode = "rb";
1190 #endif /* DOS_NT */
1191 stat ((char *)SDATA (efound), &s1);
1192 SSET (efound, SBYTES (efound) - 1, 0);
1193 result = stat ((char *)SDATA (efound), &s2);
1194 SSET (efound, SBYTES (efound) - 1, 'c');
1196 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
1198 /* Make the progress messages mention that source is newer. */
1199 newer = 1;
1201 /* If we won't print another message, mention this anyway. */
1202 if (!NILP (nomessage) && !force_load_messages)
1204 Lisp_Object msg_file;
1205 msg_file = Fsubstring (found, make_number (0), make_number (-1));
1206 message_with_string ("Source file `%s' newer than byte-compiled file",
1207 msg_file, 1);
1210 UNGCPRO;
1213 else
1215 /* We are loading a source file (*.el). */
1216 if (!NILP (Vload_source_file_function))
1218 Lisp_Object val;
1220 if (fd >= 0)
1221 emacs_close (fd);
1222 val = call4 (Vload_source_file_function, found, hist_file_name,
1223 NILP (noerror) ? Qnil : Qt,
1224 (NILP (nomessage) || force_load_messages) ? Qnil : Qt);
1225 return unbind_to (count, val);
1229 GCPRO3 (file, found, hist_file_name);
1231 #ifdef WINDOWSNT
1232 emacs_close (fd);
1233 efound = ENCODE_FILE (found);
1234 stream = fopen ((char *) SDATA (efound), fmode);
1235 #else /* not WINDOWSNT */
1236 stream = fdopen (fd, fmode);
1237 #endif /* not WINDOWSNT */
1238 if (stream == 0)
1240 emacs_close (fd);
1241 error ("Failure to create stdio stream for %s", SDATA (file));
1244 if (! NILP (Vpurify_flag))
1245 Vpreloaded_file_list = Fcons (Fpurecopy(file), Vpreloaded_file_list);
1247 if (NILP (nomessage) || force_load_messages)
1249 if (!safe_p)
1250 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
1251 file, 1);
1252 else if (!compiled)
1253 message_with_string ("Loading %s (source)...", file, 1);
1254 else if (newer)
1255 message_with_string ("Loading %s (compiled; note, source file is newer)...",
1256 file, 1);
1257 else /* The typical case; compiled file newer than source file. */
1258 message_with_string ("Loading %s...", file, 1);
1261 record_unwind_protect (load_unwind, make_save_value (stream, 0));
1262 record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
1263 specbind (Qload_file_name, found);
1264 specbind (Qinhibit_file_name_operation, Qnil);
1265 load_descriptor_list
1266 = Fcons (make_number (fileno (stream)), load_descriptor_list);
1267 specbind (Qload_in_progress, Qt);
1268 if (! version || version >= 22)
1269 readevalloop (Qget_file_char, stream, hist_file_name,
1270 Feval, 0, Qnil, Qnil, Qnil, Qnil);
1271 else
1273 /* We can't handle a file which was compiled with
1274 byte-compile-dynamic by older version of Emacs. */
1275 specbind (Qload_force_doc_strings, Qt);
1276 readevalloop (Qget_emacs_mule_file_char, stream, hist_file_name, Feval,
1277 0, Qnil, Qnil, Qnil, Qnil);
1279 unbind_to (count, Qnil);
1281 /* Run any eval-after-load forms for this file */
1282 if (!NILP (Ffboundp (Qdo_after_load_evaluation)))
1283 call1 (Qdo_after_load_evaluation, hist_file_name) ;
1285 UNGCPRO;
1287 xfree (saved_doc_string);
1288 saved_doc_string = 0;
1289 saved_doc_string_size = 0;
1291 xfree (prev_saved_doc_string);
1292 prev_saved_doc_string = 0;
1293 prev_saved_doc_string_size = 0;
1295 if (!noninteractive && (NILP (nomessage) || force_load_messages))
1297 if (!safe_p)
1298 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
1299 file, 1);
1300 else if (!compiled)
1301 message_with_string ("Loading %s (source)...done", file, 1);
1302 else if (newer)
1303 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
1304 file, 1);
1305 else /* The typical case; compiled file newer than source file. */
1306 message_with_string ("Loading %s...done", file, 1);
1309 return Qt;
1312 static Lisp_Object
1313 load_unwind (arg) /* used as unwind-protect function in load */
1314 Lisp_Object arg;
1316 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
1317 if (stream != NULL)
1319 BLOCK_INPUT;
1320 fclose (stream);
1321 UNBLOCK_INPUT;
1323 return Qnil;
1326 static Lisp_Object
1327 load_descriptor_unwind (oldlist)
1328 Lisp_Object oldlist;
1330 load_descriptor_list = oldlist;
1331 return Qnil;
1334 /* Close all descriptors in use for Floads.
1335 This is used when starting a subprocess. */
1337 void
1338 close_load_descs ()
1340 #ifndef WINDOWSNT
1341 Lisp_Object tail;
1342 for (tail = load_descriptor_list; CONSP (tail); tail = XCDR (tail))
1343 emacs_close (XFASTINT (XCAR (tail)));
1344 #endif
1347 static int
1348 complete_filename_p (pathname)
1349 Lisp_Object pathname;
1351 register const unsigned char *s = SDATA (pathname);
1352 return (IS_DIRECTORY_SEP (s[0])
1353 || (SCHARS (pathname) > 2
1354 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])));
1357 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
1358 doc: /* Search for FILENAME through PATH.
1359 Returns the file's name in absolute form, or nil if not found.
1360 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1361 file name when searching.
1362 If non-nil, PREDICATE is used instead of `file-readable-p'.
1363 PREDICATE can also be an integer to pass to the access(2) function,
1364 in which case file-name-handlers are ignored. */)
1365 (filename, path, suffixes, predicate)
1366 Lisp_Object filename, path, suffixes, predicate;
1368 Lisp_Object file;
1369 int fd = openp (path, filename, suffixes, &file, predicate);
1370 if (NILP (predicate) && fd > 0)
1371 close (fd);
1372 return file;
1376 /* Search for a file whose name is STR, looking in directories
1377 in the Lisp list PATH, and trying suffixes from SUFFIX.
1378 On success, returns a file descriptor. On failure, returns -1.
1380 SUFFIXES is a list of strings containing possible suffixes.
1381 The empty suffix is automatically added if the list is empty.
1383 PREDICATE non-nil means don't open the files,
1384 just look for one that satisfies the predicate. In this case,
1385 returns 1 on success. The predicate can be a lisp function or
1386 an integer to pass to `access' (in which case file-name-handlers
1387 are ignored).
1389 If STOREPTR is nonzero, it points to a slot where the name of
1390 the file actually found should be stored as a Lisp string.
1391 nil is stored there on failure.
1393 If the file we find is remote, return -2
1394 but store the found remote file name in *STOREPTR. */
1397 openp (path, str, suffixes, storeptr, predicate)
1398 Lisp_Object path, str;
1399 Lisp_Object suffixes;
1400 Lisp_Object *storeptr;
1401 Lisp_Object predicate;
1403 register int fd;
1404 int fn_size = 100;
1405 char buf[100];
1406 register char *fn = buf;
1407 int absolute = 0;
1408 int want_size;
1409 Lisp_Object filename;
1410 struct stat st;
1411 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1412 Lisp_Object string, tail, encoded_fn;
1413 int max_suffix_len = 0;
1415 CHECK_STRING (str);
1417 for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
1419 CHECK_STRING_CAR (tail);
1420 max_suffix_len = max (max_suffix_len,
1421 SBYTES (XCAR (tail)));
1424 string = filename = encoded_fn = Qnil;
1425 GCPRO6 (str, string, filename, path, suffixes, encoded_fn);
1427 if (storeptr)
1428 *storeptr = Qnil;
1430 if (complete_filename_p (str))
1431 absolute = 1;
1433 for (; CONSP (path); path = XCDR (path))
1435 filename = Fexpand_file_name (str, XCAR (path));
1436 if (!complete_filename_p (filename))
1437 /* If there are non-absolute elts in PATH (eg ".") */
1438 /* Of course, this could conceivably lose if luser sets
1439 default-directory to be something non-absolute... */
1441 filename = Fexpand_file_name (filename, current_buffer->directory);
1442 if (!complete_filename_p (filename))
1443 /* Give up on this path element! */
1444 continue;
1447 /* Calculate maximum size of any filename made from
1448 this path element/specified file name and any possible suffix. */
1449 want_size = max_suffix_len + SBYTES (filename) + 1;
1450 if (fn_size < want_size)
1451 fn = (char *) alloca (fn_size = 100 + want_size);
1453 /* Loop over suffixes. */
1454 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1455 CONSP (tail); tail = XCDR (tail))
1457 int lsuffix = SBYTES (XCAR (tail));
1458 Lisp_Object handler;
1459 int exists;
1461 /* Concatenate path element/specified name with the suffix.
1462 If the directory starts with /:, remove that. */
1463 if (SCHARS (filename) > 2
1464 && SREF (filename, 0) == '/'
1465 && SREF (filename, 1) == ':')
1467 strncpy (fn, SDATA (filename) + 2,
1468 SBYTES (filename) - 2);
1469 fn[SBYTES (filename) - 2] = 0;
1471 else
1473 strncpy (fn, SDATA (filename),
1474 SBYTES (filename));
1475 fn[SBYTES (filename)] = 0;
1478 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1479 strncat (fn, SDATA (XCAR (tail)), lsuffix);
1481 /* Check that the file exists and is not a directory. */
1482 /* We used to only check for handlers on non-absolute file names:
1483 if (absolute)
1484 handler = Qnil;
1485 else
1486 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1487 It's not clear why that was the case and it breaks things like
1488 (load "/bar.el") where the file is actually "/bar.el.gz". */
1489 string = build_string (fn);
1490 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1491 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1493 if (NILP (predicate))
1494 exists = !NILP (Ffile_readable_p (string));
1495 else
1496 exists = !NILP (call1 (predicate, string));
1497 if (exists && !NILP (Ffile_directory_p (string)))
1498 exists = 0;
1500 if (exists)
1502 /* We succeeded; return this descriptor and filename. */
1503 if (storeptr)
1504 *storeptr = string;
1505 UNGCPRO;
1506 return -2;
1509 else
1511 const char *pfn;
1513 encoded_fn = ENCODE_FILE (string);
1514 pfn = SDATA (encoded_fn);
1515 exists = (stat (pfn, &st) >= 0
1516 && (st.st_mode & S_IFMT) != S_IFDIR);
1517 if (exists)
1519 /* Check that we can access or open it. */
1520 if (NATNUMP (predicate))
1521 fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1;
1522 else
1523 fd = emacs_open (pfn, O_RDONLY, 0);
1525 if (fd >= 0)
1527 /* We succeeded; return this descriptor and filename. */
1528 if (storeptr)
1529 *storeptr = string;
1530 UNGCPRO;
1531 return fd;
1536 if (absolute)
1537 break;
1540 UNGCPRO;
1541 return -1;
1545 /* Merge the list we've accumulated of globals from the current input source
1546 into the load_history variable. The details depend on whether
1547 the source has an associated file name or not.
1549 FILENAME is the file name that we are loading from.
1550 ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */
1552 static void
1553 build_load_history (filename, entire)
1554 Lisp_Object filename;
1555 int entire;
1557 register Lisp_Object tail, prev, newelt;
1558 register Lisp_Object tem, tem2;
1559 register int foundit = 0;
1561 tail = Vload_history;
1562 prev = Qnil;
1564 while (CONSP (tail))
1566 tem = XCAR (tail);
1568 /* Find the feature's previous assoc list... */
1569 if (!NILP (Fequal (filename, Fcar (tem))))
1571 foundit = 1;
1573 /* If we're loading the entire file, remove old data. */
1574 if (entire)
1576 if (NILP (prev))
1577 Vload_history = XCDR (tail);
1578 else
1579 Fsetcdr (prev, XCDR (tail));
1582 /* Otherwise, cons on new symbols that are not already members. */
1583 else
1585 tem2 = Vcurrent_load_list;
1587 while (CONSP (tem2))
1589 newelt = XCAR (tem2);
1591 if (NILP (Fmember (newelt, tem)))
1592 Fsetcar (tail, Fcons (XCAR (tem),
1593 Fcons (newelt, XCDR (tem))));
1595 tem2 = XCDR (tem2);
1596 QUIT;
1600 else
1601 prev = tail;
1602 tail = XCDR (tail);
1603 QUIT;
1606 /* If we're loading an entire file, cons the new assoc onto the
1607 front of load-history, the most-recently-loaded position. Also
1608 do this if we didn't find an existing member for the file. */
1609 if (entire || !foundit)
1610 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1611 Vload_history);
1614 Lisp_Object
1615 unreadpure (junk) /* Used as unwind-protect function in readevalloop */
1616 Lisp_Object junk;
1618 read_pure = 0;
1619 return Qnil;
1622 static Lisp_Object
1623 readevalloop_1 (old)
1624 Lisp_Object old;
1626 load_convert_to_unibyte = ! NILP (old);
1627 return Qnil;
1630 /* Signal an `end-of-file' error, if possible with file name
1631 information. */
1633 static void
1634 end_of_file_error ()
1636 if (STRINGP (Vload_file_name))
1637 xsignal1 (Qend_of_file, Vload_file_name);
1639 xsignal0 (Qend_of_file);
1642 /* UNIBYTE specifies how to set load_convert_to_unibyte
1643 for this invocation.
1644 READFUN, if non-nil, is used instead of `read'.
1646 START, END specify region to read in current buffer (from eval-region).
1647 If the input is not from a buffer, they must be nil. */
1649 static void
1650 readevalloop (readcharfun, stream, sourcename, evalfun,
1651 printflag, unibyte, readfun, start, end)
1652 Lisp_Object readcharfun;
1653 FILE *stream;
1654 Lisp_Object sourcename;
1655 Lisp_Object (*evalfun) ();
1656 int printflag;
1657 Lisp_Object unibyte, readfun;
1658 Lisp_Object start, end;
1660 register int c;
1661 register Lisp_Object val;
1662 int count = SPECPDL_INDEX ();
1663 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1664 struct buffer *b = 0;
1665 int continue_reading_p;
1666 /* Nonzero if reading an entire buffer. */
1667 int whole_buffer = 0;
1668 /* 1 on the first time around. */
1669 int first_sexp = 1;
1671 if (MARKERP (readcharfun))
1673 if (NILP (start))
1674 start = readcharfun;
1677 if (BUFFERP (readcharfun))
1678 b = XBUFFER (readcharfun);
1679 else if (MARKERP (readcharfun))
1680 b = XMARKER (readcharfun)->buffer;
1682 /* We assume START is nil when input is not from a buffer. */
1683 if (! NILP (start) && !b)
1684 abort ();
1686 specbind (Qstandard_input, readcharfun); /* GCPROs readcharfun. */
1687 specbind (Qcurrent_load_list, Qnil);
1688 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
1689 load_convert_to_unibyte = !NILP (unibyte);
1691 GCPRO4 (sourcename, readfun, start, end);
1693 /* Try to ensure sourcename is a truename, except whilst preloading. */
1694 if (NILP (Vpurify_flag)
1695 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename))
1696 && !NILP (Ffboundp (Qfile_truename)))
1697 sourcename = call1 (Qfile_truename, sourcename) ;
1699 LOADHIST_ATTACH (sourcename);
1701 continue_reading_p = 1;
1702 while (continue_reading_p)
1704 int count1 = SPECPDL_INDEX ();
1706 if (b != 0 && NILP (b->name))
1707 error ("Reading from killed buffer");
1709 if (!NILP (start))
1711 /* Switch to the buffer we are reading from. */
1712 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1713 set_buffer_internal (b);
1715 /* Save point in it. */
1716 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1717 /* Save ZV in it. */
1718 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1719 /* Those get unbound after we read one expression. */
1721 /* Set point and ZV around stuff to be read. */
1722 Fgoto_char (start);
1723 if (!NILP (end))
1724 Fnarrow_to_region (make_number (BEGV), end);
1726 /* Just for cleanliness, convert END to a marker
1727 if it is an integer. */
1728 if (INTEGERP (end))
1729 end = Fpoint_max_marker ();
1732 /* On the first cycle, we can easily test here
1733 whether we are reading the whole buffer. */
1734 if (b && first_sexp)
1735 whole_buffer = (PT == BEG && ZV == Z);
1737 instream = stream;
1738 read_next:
1739 c = READCHAR;
1740 if (c == ';')
1742 while ((c = READCHAR) != '\n' && c != -1);
1743 goto read_next;
1745 if (c < 0)
1747 unbind_to (count1, Qnil);
1748 break;
1751 /* Ignore whitespace here, so we can detect eof. */
1752 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'
1753 || c == 0x8a0) /* NBSP */
1754 goto read_next;
1756 if (!NILP (Vpurify_flag) && c == '(')
1758 record_unwind_protect (unreadpure, Qnil);
1759 val = read_list (-1, readcharfun);
1761 else
1763 UNREAD (c);
1764 read_objects = Qnil;
1765 if (!NILP (readfun))
1767 val = call1 (readfun, readcharfun);
1769 /* If READCHARFUN has set point to ZV, we should
1770 stop reading, even if the form read sets point
1771 to a different value when evaluated. */
1772 if (BUFFERP (readcharfun))
1774 struct buffer *b = XBUFFER (readcharfun);
1775 if (BUF_PT (b) == BUF_ZV (b))
1776 continue_reading_p = 0;
1779 else if (! NILP (Vload_read_function))
1780 val = call1 (Vload_read_function, readcharfun);
1781 else
1782 val = read_internal_start (readcharfun, Qnil, Qnil);
1785 if (!NILP (start) && continue_reading_p)
1786 start = Fpoint_marker ();
1788 /* Restore saved point and BEGV. */
1789 unbind_to (count1, Qnil);
1791 /* Now eval what we just read. */
1792 val = (*evalfun) (val);
1794 if (printflag)
1796 Vvalues = Fcons (val, Vvalues);
1797 if (EQ (Vstandard_output, Qt))
1798 Fprin1 (val, Qnil);
1799 else
1800 Fprint (val, Qnil);
1803 first_sexp = 0;
1806 build_load_history (sourcename,
1807 stream || whole_buffer);
1809 UNGCPRO;
1811 unbind_to (count, Qnil);
1814 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
1815 doc: /* Execute the current buffer as Lisp code.
1816 When called from a Lisp program (i.e., not interactively), this
1817 function accepts up to five optional arguments:
1818 BUFFER is the buffer to evaluate (nil means use current buffer).
1819 PRINTFLAG controls printing of output:
1820 A value of nil means discard it; anything else is stream for print.
1821 FILENAME specifies the file name to use for `load-history'.
1822 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
1823 invocation.
1824 DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1825 functions should work normally even if PRINTFLAG is nil.
1827 This function preserves the position of point. */)
1828 (buffer, printflag, filename, unibyte, do_allow_print)
1829 Lisp_Object buffer, printflag, filename, unibyte, do_allow_print;
1831 int count = SPECPDL_INDEX ();
1832 Lisp_Object tem, buf;
1834 if (NILP (buffer))
1835 buf = Fcurrent_buffer ();
1836 else
1837 buf = Fget_buffer (buffer);
1838 if (NILP (buf))
1839 error ("No such buffer");
1841 if (NILP (printflag) && NILP (do_allow_print))
1842 tem = Qsymbolp;
1843 else
1844 tem = printflag;
1846 if (NILP (filename))
1847 filename = XBUFFER (buf)->filename;
1849 specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
1850 specbind (Qstandard_output, tem);
1851 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1852 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
1853 readevalloop (buf, 0, filename, Feval,
1854 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
1855 unbind_to (count, Qnil);
1857 return Qnil;
1860 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
1861 doc: /* Execute the region as Lisp code.
1862 When called from programs, expects two arguments,
1863 giving starting and ending indices in the current buffer
1864 of the text to be executed.
1865 Programs can pass third argument PRINTFLAG which controls output:
1866 A value of nil means discard it; anything else is stream for printing it.
1867 Also the fourth argument READ-FUNCTION, if non-nil, is used
1868 instead of `read' to read each expression. It gets one argument
1869 which is the input stream for reading characters.
1871 This function does not move point. */)
1872 (start, end, printflag, read_function)
1873 Lisp_Object start, end, printflag, read_function;
1875 int count = SPECPDL_INDEX ();
1876 Lisp_Object tem, cbuf;
1878 cbuf = Fcurrent_buffer ();
1880 if (NILP (printflag))
1881 tem = Qsymbolp;
1882 else
1883 tem = printflag;
1884 specbind (Qstandard_output, tem);
1885 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list));
1887 /* readevalloop calls functions which check the type of start and end. */
1888 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
1889 !NILP (printflag), Qnil, read_function,
1890 start, end);
1892 return unbind_to (count, Qnil);
1896 DEFUN ("read", Fread, Sread, 0, 1, 0,
1897 doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1898 If STREAM is nil, use the value of `standard-input' (which see).
1899 STREAM or the value of `standard-input' may be:
1900 a buffer (read from point and advance it)
1901 a marker (read from where it points and advance it)
1902 a function (call it with no arguments for each character,
1903 call it with a char as argument to push a char back)
1904 a string (takes text from string, starting at the beginning)
1905 t (read text line using minibuffer and use it, or read from
1906 standard input in batch mode). */)
1907 (stream)
1908 Lisp_Object stream;
1910 if (NILP (stream))
1911 stream = Vstandard_input;
1912 if (EQ (stream, Qt))
1913 stream = Qread_char;
1914 if (EQ (stream, Qread_char))
1915 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
1917 return read_internal_start (stream, Qnil, Qnil);
1920 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
1921 doc: /* Read one Lisp expression which is represented as text by STRING.
1922 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1923 START and END optionally delimit a substring of STRING from which to read;
1924 they default to 0 and (length STRING) respectively. */)
1925 (string, start, end)
1926 Lisp_Object string, start, end;
1928 Lisp_Object ret;
1929 CHECK_STRING (string);
1930 /* read_internal_start sets read_from_string_index. */
1931 ret = read_internal_start (string, start, end);
1932 return Fcons (ret, make_number (read_from_string_index));
1935 /* Function to set up the global context we need in toplevel read
1936 calls. */
1937 static Lisp_Object
1938 read_internal_start (stream, start, end)
1939 Lisp_Object stream;
1940 Lisp_Object start; /* Only used when stream is a string. */
1941 Lisp_Object end; /* Only used when stream is a string. */
1943 Lisp_Object retval;
1945 readchar_count = 0;
1946 new_backquote_flag = 0;
1947 read_objects = Qnil;
1948 if (EQ (Vread_with_symbol_positions, Qt)
1949 || EQ (Vread_with_symbol_positions, stream))
1950 Vread_symbol_positions_list = Qnil;
1952 if (STRINGP (stream)
1953 || ((CONSP (stream) && STRINGP (XCAR (stream)))))
1955 int startval, endval;
1956 Lisp_Object string;
1958 if (STRINGP (stream))
1959 string = stream;
1960 else
1961 string = XCAR (stream);
1963 if (NILP (end))
1964 endval = SCHARS (string);
1965 else
1967 CHECK_NUMBER (end);
1968 endval = XINT (end);
1969 if (endval < 0 || endval > SCHARS (string))
1970 args_out_of_range (string, end);
1973 if (NILP (start))
1974 startval = 0;
1975 else
1977 CHECK_NUMBER (start);
1978 startval = XINT (start);
1979 if (startval < 0 || startval > endval)
1980 args_out_of_range (string, start);
1982 read_from_string_index = startval;
1983 read_from_string_index_byte = string_char_to_byte (string, startval);
1984 read_from_string_limit = endval;
1987 retval = read0 (stream);
1988 if (EQ (Vread_with_symbol_positions, Qt)
1989 || EQ (Vread_with_symbol_positions, stream))
1990 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list);
1991 return retval;
1995 /* Signal Qinvalid_read_syntax error.
1996 S is error string of length N (if > 0) */
1998 static void
1999 invalid_syntax (s, n)
2000 const char *s;
2001 int n;
2003 if (!n)
2004 n = strlen (s);
2005 xsignal1 (Qinvalid_read_syntax, make_string (s, n));
2009 /* Use this for recursive reads, in contexts where internal tokens
2010 are not allowed. */
2012 static Lisp_Object
2013 read0 (readcharfun)
2014 Lisp_Object readcharfun;
2016 register Lisp_Object val;
2017 int c;
2019 val = read1 (readcharfun, &c, 0);
2020 if (!c)
2021 return val;
2023 xsignal1 (Qinvalid_read_syntax,
2024 Fmake_string (make_number (1), make_number (c)));
2027 static int read_buffer_size;
2028 static char *read_buffer;
2030 /* Read a \-escape sequence, assuming we already read the `\'.
2031 If the escape sequence forces unibyte, return eight-bit char. */
2033 static int
2034 read_escape (readcharfun, stringp)
2035 Lisp_Object readcharfun;
2036 int stringp;
2038 register int c = READCHAR;
2039 /* \u allows up to four hex digits, \U up to eight. Default to the
2040 behavior for \u, and change this value in the case that \U is seen. */
2041 int unicode_hex_count = 4;
2043 switch (c)
2045 case -1:
2046 end_of_file_error ();
2048 case 'a':
2049 return '\007';
2050 case 'b':
2051 return '\b';
2052 case 'd':
2053 return 0177;
2054 case 'e':
2055 return 033;
2056 case 'f':
2057 return '\f';
2058 case 'n':
2059 return '\n';
2060 case 'r':
2061 return '\r';
2062 case 't':
2063 return '\t';
2064 case 'v':
2065 return '\v';
2066 case '\n':
2067 return -1;
2068 case ' ':
2069 if (stringp)
2070 return -1;
2071 return ' ';
2073 case 'M':
2074 c = READCHAR;
2075 if (c != '-')
2076 error ("Invalid escape character syntax");
2077 c = READCHAR;
2078 if (c == '\\')
2079 c = read_escape (readcharfun, 0);
2080 return c | meta_modifier;
2082 case 'S':
2083 c = READCHAR;
2084 if (c != '-')
2085 error ("Invalid escape character syntax");
2086 c = READCHAR;
2087 if (c == '\\')
2088 c = read_escape (readcharfun, 0);
2089 return c | shift_modifier;
2091 case 'H':
2092 c = READCHAR;
2093 if (c != '-')
2094 error ("Invalid escape character syntax");
2095 c = READCHAR;
2096 if (c == '\\')
2097 c = read_escape (readcharfun, 0);
2098 return c | hyper_modifier;
2100 case 'A':
2101 c = READCHAR;
2102 if (c != '-')
2103 error ("Invalid escape character syntax");
2104 c = READCHAR;
2105 if (c == '\\')
2106 c = read_escape (readcharfun, 0);
2107 return c | alt_modifier;
2109 case 's':
2110 c = READCHAR;
2111 if (stringp || c != '-')
2113 UNREAD (c);
2114 return ' ';
2116 c = READCHAR;
2117 if (c == '\\')
2118 c = read_escape (readcharfun, 0);
2119 return c | super_modifier;
2121 case 'C':
2122 c = READCHAR;
2123 if (c != '-')
2124 error ("Invalid escape character syntax");
2125 case '^':
2126 c = READCHAR;
2127 if (c == '\\')
2128 c = read_escape (readcharfun, 0);
2129 if ((c & ~CHAR_MODIFIER_MASK) == '?')
2130 return 0177 | (c & CHAR_MODIFIER_MASK);
2131 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
2132 return c | ctrl_modifier;
2133 /* ASCII control chars are made from letters (both cases),
2134 as well as the non-letters within 0100...0137. */
2135 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
2136 return (c & (037 | ~0177));
2137 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
2138 return (c & (037 | ~0177));
2139 else
2140 return c | ctrl_modifier;
2142 case '0':
2143 case '1':
2144 case '2':
2145 case '3':
2146 case '4':
2147 case '5':
2148 case '6':
2149 case '7':
2150 /* An octal escape, as in ANSI C. */
2152 register int i = c - '0';
2153 register int count = 0;
2154 while (++count < 3)
2156 if ((c = READCHAR) >= '0' && c <= '7')
2158 i *= 8;
2159 i += c - '0';
2161 else
2163 UNREAD (c);
2164 break;
2168 if (i >= 0x80 && i < 0x100)
2169 i = BYTE8_TO_CHAR (i);
2170 return i;
2173 case 'x':
2174 /* A hex escape, as in ANSI C. */
2176 int i = 0;
2177 int count = 0;
2178 while (1)
2180 c = READCHAR;
2181 if (c >= '0' && c <= '9')
2183 i *= 16;
2184 i += c - '0';
2186 else if ((c >= 'a' && c <= 'f')
2187 || (c >= 'A' && c <= 'F'))
2189 i *= 16;
2190 if (c >= 'a' && c <= 'f')
2191 i += c - 'a' + 10;
2192 else
2193 i += c - 'A' + 10;
2195 else
2197 UNREAD (c);
2198 break;
2200 count++;
2203 if (count < 3 && i >= 0x80)
2204 return BYTE8_TO_CHAR (i);
2205 return i;
2208 case 'U':
2209 /* Post-Unicode-2.0: Up to eight hex chars. */
2210 unicode_hex_count = 8;
2211 case 'u':
2213 /* A Unicode escape. We only permit them in strings and characters,
2214 not arbitrarily in the source code, as in some other languages. */
2216 unsigned int i = 0;
2217 int count = 0;
2219 while (++count <= unicode_hex_count)
2221 c = READCHAR;
2222 /* isdigit and isalpha may be locale-specific, which we don't
2223 want. */
2224 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
2225 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
2226 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
2227 else
2229 error ("Non-hex digit used for Unicode escape");
2230 break;
2233 if (i > 0x10FFFF)
2234 error ("Non-Unicode character: 0x%x", i);
2235 return i;
2238 default:
2239 return c;
2243 /* Read an integer in radix RADIX using READCHARFUN to read
2244 characters. RADIX must be in the interval [2..36]; if it isn't, a
2245 read error is signaled . Value is the integer read. Signals an
2246 error if encountering invalid read syntax or if RADIX is out of
2247 range. */
2249 static Lisp_Object
2250 read_integer (readcharfun, radix)
2251 Lisp_Object readcharfun;
2252 int radix;
2254 int ndigits = 0, invalid_p, c, sign = 0;
2255 /* We use a floating point number because */
2256 double number = 0;
2258 if (radix < 2 || radix > 36)
2259 invalid_p = 1;
2260 else
2262 number = ndigits = invalid_p = 0;
2263 sign = 1;
2265 c = READCHAR;
2266 if (c == '-')
2268 c = READCHAR;
2269 sign = -1;
2271 else if (c == '+')
2272 c = READCHAR;
2274 while (c >= 0)
2276 int digit;
2278 if (c >= '0' && c <= '9')
2279 digit = c - '0';
2280 else if (c >= 'a' && c <= 'z')
2281 digit = c - 'a' + 10;
2282 else if (c >= 'A' && c <= 'Z')
2283 digit = c - 'A' + 10;
2284 else
2286 UNREAD (c);
2287 break;
2290 if (digit < 0 || digit >= radix)
2291 invalid_p = 1;
2293 number = radix * number + digit;
2294 ++ndigits;
2295 c = READCHAR;
2299 if (ndigits == 0 || invalid_p)
2301 char buf[50];
2302 sprintf (buf, "integer, radix %d", radix);
2303 invalid_syntax (buf, 0);
2306 return make_fixnum_or_float (sign * number);
2310 /* If the next token is ')' or ']' or '.', we store that character
2311 in *PCH and the return value is not interesting. Else, we store
2312 zero in *PCH and we read and return one lisp object.
2314 FIRST_IN_LIST is nonzero if this is the first element of a list. */
2316 static Lisp_Object
2317 read1 (readcharfun, pch, first_in_list)
2318 register Lisp_Object readcharfun;
2319 int *pch;
2320 int first_in_list;
2322 register int c;
2323 int uninterned_symbol = 0;
2324 int multibyte;
2326 *pch = 0;
2327 load_each_byte = 0;
2329 retry:
2331 c = READCHAR_REPORT_MULTIBYTE (&multibyte);
2332 if (c < 0)
2333 end_of_file_error ();
2335 switch (c)
2337 case '(':
2338 return read_list (0, readcharfun);
2340 case '[':
2341 return read_vector (readcharfun, 0);
2343 case ')':
2344 case ']':
2346 *pch = c;
2347 return Qnil;
2350 case '#':
2351 c = READCHAR;
2352 if (c == 's')
2354 c = READCHAR;
2355 if (c == '(')
2357 /* Accept extended format for hashtables (extensible to
2358 other types), e.g.
2359 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2360 Lisp_Object tmp = read_list (0, readcharfun);
2361 Lisp_Object head = CAR_SAFE (tmp);
2362 Lisp_Object data = Qnil;
2363 Lisp_Object val = Qnil;
2364 /* The size is 2 * number of allowed keywords to
2365 make-hash-table. */
2366 Lisp_Object params[10];
2367 Lisp_Object ht;
2368 Lisp_Object key = Qnil;
2369 int param_count = 0;
2371 if (!EQ (head, Qhash_table))
2372 error ("Invalid extended read marker at head of #s list "
2373 "(only hash-table allowed)");
2375 tmp = CDR_SAFE (tmp);
2377 /* This is repetitive but fast and simple. */
2378 params[param_count] = QCsize;
2379 params[param_count+1] = Fplist_get (tmp, Qsize);
2380 if (!NILP (params[param_count+1]))
2381 param_count+=2;
2383 params[param_count] = QCtest;
2384 params[param_count+1] = Fplist_get (tmp, Qtest);
2385 if (!NILP (params[param_count+1]))
2386 param_count+=2;
2388 params[param_count] = QCweakness;
2389 params[param_count+1] = Fplist_get (tmp, Qweakness);
2390 if (!NILP (params[param_count+1]))
2391 param_count+=2;
2393 params[param_count] = QCrehash_size;
2394 params[param_count+1] = Fplist_get (tmp, Qrehash_size);
2395 if (!NILP (params[param_count+1]))
2396 param_count+=2;
2398 params[param_count] = QCrehash_threshold;
2399 params[param_count+1] = Fplist_get (tmp, Qrehash_threshold);
2400 if (!NILP (params[param_count+1]))
2401 param_count+=2;
2403 /* This is the hashtable data. */
2404 data = Fplist_get (tmp, Qdata);
2406 /* Now use params to make a new hashtable and fill it. */
2407 ht = Fmake_hash_table (param_count, params);
2409 while (CONSP (data))
2411 key = XCAR (data);
2412 data = XCDR (data);
2413 if (!CONSP (data))
2414 error ("Odd number of elements in hashtable data");
2415 val = XCAR (data);
2416 data = XCDR (data);
2417 Fputhash (key, val, ht);
2420 return ht;
2423 if (c == '^')
2425 c = READCHAR;
2426 if (c == '[')
2428 Lisp_Object tmp;
2429 tmp = read_vector (readcharfun, 0);
2430 if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS)
2431 error ("Invalid size char-table");
2432 XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE);
2433 return tmp;
2435 else if (c == '^')
2437 c = READCHAR;
2438 if (c == '[')
2440 Lisp_Object tmp;
2441 int depth, size;
2443 tmp = read_vector (readcharfun, 0);
2444 if (!INTEGERP (AREF (tmp, 0)))
2445 error ("Invalid depth in char-table");
2446 depth = XINT (AREF (tmp, 0));
2447 if (depth < 1 || depth > 3)
2448 error ("Invalid depth in char-table");
2449 size = XVECTOR (tmp)->size - 2;
2450 if (chartab_size [depth] != size)
2451 error ("Invalid size char-table");
2452 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
2453 return tmp;
2455 invalid_syntax ("#^^", 3);
2457 invalid_syntax ("#^", 2);
2459 if (c == '&')
2461 Lisp_Object length;
2462 length = read1 (readcharfun, pch, first_in_list);
2463 c = READCHAR;
2464 if (c == '"')
2466 Lisp_Object tmp, val;
2467 int size_in_chars
2468 = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2469 / BOOL_VECTOR_BITS_PER_CHAR);
2471 UNREAD (c);
2472 tmp = read1 (readcharfun, pch, first_in_list);
2473 if (STRING_MULTIBYTE (tmp)
2474 || (size_in_chars != SCHARS (tmp)
2475 /* We used to print 1 char too many
2476 when the number of bits was a multiple of 8.
2477 Accept such input in case it came from an old
2478 version. */
2479 && ! (XFASTINT (length)
2480 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
2481 invalid_syntax ("#&...", 5);
2483 val = Fmake_bool_vector (length, Qnil);
2484 bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data,
2485 size_in_chars);
2486 /* Clear the extraneous bits in the last byte. */
2487 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
2488 XBOOL_VECTOR (val)->data[size_in_chars - 1]
2489 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2490 return val;
2492 invalid_syntax ("#&...", 5);
2494 if (c == '[')
2496 /* Accept compiled functions at read-time so that we don't have to
2497 build them using function calls. */
2498 Lisp_Object tmp;
2499 tmp = read_vector (readcharfun, 1);
2500 return Fmake_byte_code (XVECTOR (tmp)->size,
2501 XVECTOR (tmp)->contents);
2503 if (c == '(')
2505 Lisp_Object tmp;
2506 struct gcpro gcpro1;
2507 int ch;
2509 /* Read the string itself. */
2510 tmp = read1 (readcharfun, &ch, 0);
2511 if (ch != 0 || !STRINGP (tmp))
2512 invalid_syntax ("#", 1);
2513 GCPRO1 (tmp);
2514 /* Read the intervals and their properties. */
2515 while (1)
2517 Lisp_Object beg, end, plist;
2519 beg = read1 (readcharfun, &ch, 0);
2520 end = plist = Qnil;
2521 if (ch == ')')
2522 break;
2523 if (ch == 0)
2524 end = read1 (readcharfun, &ch, 0);
2525 if (ch == 0)
2526 plist = read1 (readcharfun, &ch, 0);
2527 if (ch)
2528 invalid_syntax ("Invalid string property list", 0);
2529 Fset_text_properties (beg, end, plist, tmp);
2531 UNGCPRO;
2532 return tmp;
2535 /* #@NUMBER is used to skip NUMBER following characters.
2536 That's used in .elc files to skip over doc strings
2537 and function definitions. */
2538 if (c == '@')
2540 int i, nskip = 0;
2542 load_each_byte = 1;
2543 /* Read a decimal integer. */
2544 while ((c = READCHAR) >= 0
2545 && c >= '0' && c <= '9')
2547 nskip *= 10;
2548 nskip += c - '0';
2550 if (c >= 0)
2551 UNREAD (c);
2553 if (load_force_doc_strings
2554 && (EQ (readcharfun, Qget_file_char)
2555 || EQ (readcharfun, Qget_emacs_mule_file_char)))
2557 /* If we are supposed to force doc strings into core right now,
2558 record the last string that we skipped,
2559 and record where in the file it comes from. */
2561 /* But first exchange saved_doc_string
2562 with prev_saved_doc_string, so we save two strings. */
2564 char *temp = saved_doc_string;
2565 int temp_size = saved_doc_string_size;
2566 file_offset temp_pos = saved_doc_string_position;
2567 int temp_len = saved_doc_string_length;
2569 saved_doc_string = prev_saved_doc_string;
2570 saved_doc_string_size = prev_saved_doc_string_size;
2571 saved_doc_string_position = prev_saved_doc_string_position;
2572 saved_doc_string_length = prev_saved_doc_string_length;
2574 prev_saved_doc_string = temp;
2575 prev_saved_doc_string_size = temp_size;
2576 prev_saved_doc_string_position = temp_pos;
2577 prev_saved_doc_string_length = temp_len;
2580 if (saved_doc_string_size == 0)
2582 saved_doc_string_size = nskip + 100;
2583 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
2585 if (nskip > saved_doc_string_size)
2587 saved_doc_string_size = nskip + 100;
2588 saved_doc_string = (char *) xrealloc (saved_doc_string,
2589 saved_doc_string_size);
2592 saved_doc_string_position = file_tell (instream);
2594 /* Copy that many characters into saved_doc_string. */
2595 for (i = 0; i < nskip && c >= 0; i++)
2596 saved_doc_string[i] = c = READCHAR;
2598 saved_doc_string_length = i;
2600 else
2602 /* Skip that many characters. */
2603 for (i = 0; i < nskip && c >= 0; i++)
2604 c = READCHAR;
2607 load_each_byte = 0;
2608 goto retry;
2610 if (c == '!')
2612 /* #! appears at the beginning of an executable file.
2613 Skip the first line. */
2614 while (c != '\n' && c >= 0)
2615 c = READCHAR;
2616 goto retry;
2618 if (c == '$')
2619 return Vload_file_name;
2620 if (c == '\'')
2621 return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
2622 /* #:foo is the uninterned symbol named foo. */
2623 if (c == ':')
2625 uninterned_symbol = 1;
2626 c = READCHAR;
2627 goto default_label;
2629 /* Reader forms that can reuse previously read objects. */
2630 if (c >= '0' && c <= '9')
2632 int n = 0;
2633 Lisp_Object tem;
2635 /* Read a non-negative integer. */
2636 while (c >= '0' && c <= '9')
2638 n *= 10;
2639 n += c - '0';
2640 c = READCHAR;
2642 /* #n=object returns object, but associates it with n for #n#. */
2643 if (c == '=' && !NILP (Vread_circle))
2645 /* Make a placeholder for #n# to use temporarily */
2646 Lisp_Object placeholder;
2647 Lisp_Object cell;
2649 placeholder = Fcons (Qnil, Qnil);
2650 cell = Fcons (make_number (n), placeholder);
2651 read_objects = Fcons (cell, read_objects);
2653 /* Read the object itself. */
2654 tem = read0 (readcharfun);
2656 /* Now put it everywhere the placeholder was... */
2657 substitute_object_in_subtree (tem, placeholder);
2659 /* ...and #n# will use the real value from now on. */
2660 Fsetcdr (cell, tem);
2662 return tem;
2664 /* #n# returns a previously read object. */
2665 if (c == '#' && !NILP (Vread_circle))
2667 tem = Fassq (make_number (n), read_objects);
2668 if (CONSP (tem))
2669 return XCDR (tem);
2670 /* Fall through to error message. */
2672 else if (c == 'r' || c == 'R')
2673 return read_integer (readcharfun, n);
2675 /* Fall through to error message. */
2677 else if (c == 'x' || c == 'X')
2678 return read_integer (readcharfun, 16);
2679 else if (c == 'o' || c == 'O')
2680 return read_integer (readcharfun, 8);
2681 else if (c == 'b' || c == 'B')
2682 return read_integer (readcharfun, 2);
2684 UNREAD (c);
2685 invalid_syntax ("#", 1);
2687 case ';':
2688 while ((c = READCHAR) >= 0 && c != '\n');
2689 goto retry;
2691 case '\'':
2693 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
2696 case '`':
2697 if (first_in_list)
2699 Vold_style_backquotes = Qt;
2700 goto default_label;
2702 else
2704 Lisp_Object value;
2706 new_backquote_flag++;
2707 value = read0 (readcharfun);
2708 new_backquote_flag--;
2710 return Fcons (Qbackquote, Fcons (value, Qnil));
2713 case ',':
2714 if (new_backquote_flag)
2716 Lisp_Object comma_type = Qnil;
2717 Lisp_Object value;
2718 int ch = READCHAR;
2720 if (ch == '@')
2721 comma_type = Qcomma_at;
2722 else if (ch == '.')
2723 comma_type = Qcomma_dot;
2724 else
2726 if (ch >= 0) UNREAD (ch);
2727 comma_type = Qcomma;
2730 new_backquote_flag--;
2731 value = read0 (readcharfun);
2732 new_backquote_flag++;
2733 return Fcons (comma_type, Fcons (value, Qnil));
2735 else
2737 Vold_style_backquotes = Qt;
2738 goto default_label;
2741 case '?':
2743 int modifiers;
2744 int next_char;
2745 int ok;
2747 c = READCHAR;
2748 if (c < 0)
2749 end_of_file_error ();
2751 /* Accept `single space' syntax like (list ? x) where the
2752 whitespace character is SPC or TAB.
2753 Other literal whitespace like NL, CR, and FF are not accepted,
2754 as there are well-established escape sequences for these. */
2755 if (c == ' ' || c == '\t')
2756 return make_number (c);
2758 if (c == '\\')
2759 c = read_escape (readcharfun, 0);
2760 modifiers = c & CHAR_MODIFIER_MASK;
2761 c &= ~CHAR_MODIFIER_MASK;
2762 if (CHAR_BYTE8_P (c))
2763 c = CHAR_TO_BYTE8 (c);
2764 c |= modifiers;
2766 next_char = READCHAR;
2767 if (next_char == '.')
2769 /* Only a dotted-pair dot is valid after a char constant. */
2770 int next_next_char = READCHAR;
2771 UNREAD (next_next_char);
2773 ok = (next_next_char <= 040
2774 || (next_next_char < 0200
2775 && (index ("\"';([#?", next_next_char)
2776 || (!first_in_list && next_next_char == '`')
2777 || (new_backquote_flag && next_next_char == ','))));
2779 else
2781 ok = (next_char <= 040
2782 || (next_char < 0200
2783 && (index ("\"';()[]#?", next_char)
2784 || (!first_in_list && next_char == '`')
2785 || (new_backquote_flag && next_char == ','))));
2787 UNREAD (next_char);
2788 if (ok)
2789 return make_number (c);
2791 invalid_syntax ("?", 1);
2794 case '"':
2796 char *p = read_buffer;
2797 char *end = read_buffer + read_buffer_size;
2798 register int c;
2799 /* Nonzero if we saw an escape sequence specifying
2800 a multibyte character. */
2801 int force_multibyte = 0;
2802 /* Nonzero if we saw an escape sequence specifying
2803 a single-byte character. */
2804 int force_singlebyte = 0;
2805 int cancel = 0;
2806 int nchars = 0;
2808 while ((c = READCHAR) >= 0
2809 && c != '\"')
2811 if (end - p < MAX_MULTIBYTE_LENGTH)
2813 int offset = p - read_buffer;
2814 read_buffer = (char *) xrealloc (read_buffer,
2815 read_buffer_size *= 2);
2816 p = read_buffer + offset;
2817 end = read_buffer + read_buffer_size;
2820 if (c == '\\')
2822 int modifiers;
2824 c = read_escape (readcharfun, 1);
2826 /* C is -1 if \ newline has just been seen */
2827 if (c == -1)
2829 if (p == read_buffer)
2830 cancel = 1;
2831 continue;
2834 modifiers = c & CHAR_MODIFIER_MASK;
2835 c = c & ~CHAR_MODIFIER_MASK;
2837 if (CHAR_BYTE8_P (c))
2838 force_singlebyte = 1;
2839 else if (! ASCII_CHAR_P (c))
2840 force_multibyte = 1;
2841 else /* i.e. ASCII_CHAR_P (c) */
2843 /* Allow `\C- ' and `\C-?'. */
2844 if (modifiers == CHAR_CTL)
2846 if (c == ' ')
2847 c = 0, modifiers = 0;
2848 else if (c == '?')
2849 c = 127, modifiers = 0;
2851 if (modifiers & CHAR_SHIFT)
2853 /* Shift modifier is valid only with [A-Za-z]. */
2854 if (c >= 'A' && c <= 'Z')
2855 modifiers &= ~CHAR_SHIFT;
2856 else if (c >= 'a' && c <= 'z')
2857 c -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
2860 if (modifiers & CHAR_META)
2862 /* Move the meta bit to the right place for a
2863 string. */
2864 modifiers &= ~CHAR_META;
2865 c = BYTE8_TO_CHAR (c | 0x80);
2866 force_singlebyte = 1;
2870 /* Any modifiers remaining are invalid. */
2871 if (modifiers)
2872 error ("Invalid modifier in string");
2873 p += CHAR_STRING (c, (unsigned char *) p);
2875 else
2877 p += CHAR_STRING (c, (unsigned char *) p);
2878 if (CHAR_BYTE8_P (c))
2879 force_singlebyte = 1;
2880 else if (! ASCII_CHAR_P (c))
2881 force_multibyte = 1;
2883 nchars++;
2886 if (c < 0)
2887 end_of_file_error ();
2889 /* If purifying, and string starts with \ newline,
2890 return zero instead. This is for doc strings
2891 that we are really going to find in etc/DOC.nn.nn */
2892 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
2893 return make_number (0);
2895 if (force_multibyte)
2896 /* READ_BUFFER already contains valid multibyte forms. */
2898 else if (force_singlebyte)
2900 nchars = str_as_unibyte (read_buffer, p - read_buffer);
2901 p = read_buffer + nchars;
2903 else
2904 /* Otherwise, READ_BUFFER contains only ASCII. */
2907 /* We want readchar_count to be the number of characters, not
2908 bytes. Hence we adjust for multibyte characters in the
2909 string. ... But it doesn't seem to be necessary, because
2910 READCHAR *does* read multibyte characters from buffers. */
2911 /* readchar_count -= (p - read_buffer) - nchars; */
2912 if (read_pure)
2913 return make_pure_string (read_buffer, nchars, p - read_buffer,
2914 (force_multibyte
2915 || (p - read_buffer != nchars)));
2916 return make_specified_string (read_buffer, nchars, p - read_buffer,
2917 (force_multibyte
2918 || (p - read_buffer != nchars)));
2921 case '.':
2923 int next_char = READCHAR;
2924 UNREAD (next_char);
2926 if (next_char <= 040
2927 || (next_char < 0200
2928 && (index ("\"';([#?", next_char)
2929 || (!first_in_list && next_char == '`')
2930 || (new_backquote_flag && next_char == ','))))
2932 *pch = c;
2933 return Qnil;
2936 /* Otherwise, we fall through! Note that the atom-reading loop
2937 below will now loop at least once, assuring that we will not
2938 try to UNREAD two characters in a row. */
2940 default:
2941 default_label:
2942 if (c <= 040) goto retry;
2943 if (c == 0x8a0) /* NBSP */
2944 goto retry;
2946 char *p = read_buffer;
2947 int quoted = 0;
2950 char *end = read_buffer + read_buffer_size;
2952 while (c > 040
2953 && c != 0x8a0 /* NBSP */
2954 && (c >= 0200
2955 || (!index ("\"';()[]#", c)
2956 && !(!first_in_list && c == '`')
2957 && !(new_backquote_flag && c == ','))))
2959 if (end - p < MAX_MULTIBYTE_LENGTH)
2961 int offset = p - read_buffer;
2962 read_buffer = (char *) xrealloc (read_buffer,
2963 read_buffer_size *= 2);
2964 p = read_buffer + offset;
2965 end = read_buffer + read_buffer_size;
2968 if (c == '\\')
2970 c = READCHAR;
2971 if (c == -1)
2972 end_of_file_error ();
2973 quoted = 1;
2976 if (multibyte)
2977 p += CHAR_STRING (c, p);
2978 else
2979 *p++ = c;
2980 c = READCHAR;
2983 if (p == end)
2985 int offset = p - read_buffer;
2986 read_buffer = (char *) xrealloc (read_buffer,
2987 read_buffer_size *= 2);
2988 p = read_buffer + offset;
2989 end = read_buffer + read_buffer_size;
2991 *p = 0;
2992 if (c >= 0)
2993 UNREAD (c);
2996 if (!quoted && !uninterned_symbol)
2998 register char *p1;
2999 p1 = read_buffer;
3000 if (*p1 == '+' || *p1 == '-') p1++;
3001 /* Is it an integer? */
3002 if (p1 != p)
3004 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
3005 /* Integers can have trailing decimal points. */
3006 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
3007 if (p1 == p)
3008 /* It is an integer. */
3010 if (p1[-1] == '.')
3011 p1[-1] = '\0';
3013 /* EMACS_INT n = atol (read_buffer); */
3014 char *endptr = NULL;
3015 EMACS_INT n = (errno = 0,
3016 strtol (read_buffer, &endptr, 10));
3017 if (errno == ERANGE && endptr)
3019 Lisp_Object args
3020 = Fcons (make_string (read_buffer,
3021 endptr - read_buffer),
3022 Qnil);
3023 xsignal (Qoverflow_error, args);
3025 return make_fixnum_or_float (n);
3029 if (isfloat_string (read_buffer, 0))
3031 /* Compute NaN and infinities using 0.0 in a variable,
3032 to cope with compilers that think they are smarter
3033 than we are. */
3034 double zero = 0.0;
3036 double value;
3038 /* Negate the value ourselves. This treats 0, NaNs,
3039 and infinity properly on IEEE floating point hosts,
3040 and works around a common bug where atof ("-0.0")
3041 drops the sign. */
3042 int negative = read_buffer[0] == '-';
3044 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
3045 returns 1, is if the input ends in e+INF or e+NaN. */
3046 switch (p[-1])
3048 case 'F':
3049 value = 1.0 / zero;
3050 break;
3051 case 'N':
3052 value = zero / zero;
3054 /* If that made a "negative" NaN, negate it. */
3057 int i;
3058 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
3060 u_data.d = value;
3061 u_minus_zero.d = - 0.0;
3062 for (i = 0; i < sizeof (double); i++)
3063 if (u_data.c[i] & u_minus_zero.c[i])
3065 value = - value;
3066 break;
3069 /* Now VALUE is a positive NaN. */
3070 break;
3071 default:
3072 value = atof (read_buffer + negative);
3073 break;
3076 return make_float (negative ? - value : value);
3080 Lisp_Object name, result;
3081 EMACS_INT nbytes = p - read_buffer;
3082 EMACS_INT nchars
3083 = (multibyte ? multibyte_chars_in_text (read_buffer, nbytes)
3084 : nbytes);
3086 if (uninterned_symbol && ! NILP (Vpurify_flag))
3087 name = make_pure_string (read_buffer, nchars, nbytes, multibyte);
3088 else
3089 name = make_specified_string (read_buffer, nchars, nbytes,multibyte);
3090 result = (uninterned_symbol ? Fmake_symbol (name)
3091 : Fintern (name, Qnil));
3093 if (EQ (Vread_with_symbol_positions, Qt)
3094 || EQ (Vread_with_symbol_positions, readcharfun))
3095 Vread_symbol_positions_list =
3096 /* Kind of a hack; this will probably fail if characters
3097 in the symbol name were escaped. Not really a big
3098 deal, though. */
3099 Fcons (Fcons (result,
3100 make_number (readchar_count
3101 - XFASTINT (Flength (Fsymbol_name (result))))),
3102 Vread_symbol_positions_list);
3103 return result;
3110 /* List of nodes we've seen during substitute_object_in_subtree. */
3111 static Lisp_Object seen_list;
3113 static void
3114 substitute_object_in_subtree (object, placeholder)
3115 Lisp_Object object;
3116 Lisp_Object placeholder;
3118 Lisp_Object check_object;
3120 /* We haven't seen any objects when we start. */
3121 seen_list = Qnil;
3123 /* Make all the substitutions. */
3124 check_object
3125 = substitute_object_recurse (object, placeholder, object);
3127 /* Clear seen_list because we're done with it. */
3128 seen_list = Qnil;
3130 /* The returned object here is expected to always eq the
3131 original. */
3132 if (!EQ (check_object, object))
3133 error ("Unexpected mutation error in reader");
3136 /* Feval doesn't get called from here, so no gc protection is needed. */
3137 #define SUBSTITUTE(get_val, set_val) \
3138 do { \
3139 Lisp_Object old_value = get_val; \
3140 Lisp_Object true_value \
3141 = substitute_object_recurse (object, placeholder, \
3142 old_value); \
3144 if (!EQ (old_value, true_value)) \
3146 set_val; \
3148 } while (0)
3150 static Lisp_Object
3151 substitute_object_recurse (object, placeholder, subtree)
3152 Lisp_Object object;
3153 Lisp_Object placeholder;
3154 Lisp_Object subtree;
3156 /* If we find the placeholder, return the target object. */
3157 if (EQ (placeholder, subtree))
3158 return object;
3160 /* If we've been to this node before, don't explore it again. */
3161 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
3162 return subtree;
3164 /* If this node can be the entry point to a cycle, remember that
3165 we've seen it. It can only be such an entry point if it was made
3166 by #n=, which means that we can find it as a value in
3167 read_objects. */
3168 if (!EQ (Qnil, Frassq (subtree, read_objects)))
3169 seen_list = Fcons (subtree, seen_list);
3171 /* Recurse according to subtree's type.
3172 Every branch must return a Lisp_Object. */
3173 switch (XTYPE (subtree))
3175 case Lisp_Vectorlike:
3177 int i, length = 0;
3178 if (BOOL_VECTOR_P (subtree))
3179 return subtree; /* No sub-objects anyway. */
3180 else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
3181 || COMPILEDP (subtree))
3182 length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK;
3183 else if (VECTORP (subtree))
3184 length = ASIZE (subtree);
3185 else
3186 /* An unknown pseudovector may contain non-Lisp fields, so we
3187 can't just blindly traverse all its fields. We used to call
3188 `Flength' which signaled `sequencep', so I just preserved this
3189 behavior. */
3190 wrong_type_argument (Qsequencep, subtree);
3192 for (i = 0; i < length; i++)
3193 SUBSTITUTE (AREF (subtree, i),
3194 ASET (subtree, i, true_value));
3195 return subtree;
3198 case Lisp_Cons:
3200 SUBSTITUTE (XCAR (subtree),
3201 XSETCAR (subtree, true_value));
3202 SUBSTITUTE (XCDR (subtree),
3203 XSETCDR (subtree, true_value));
3204 return subtree;
3207 case Lisp_String:
3209 /* Check for text properties in each interval.
3210 substitute_in_interval contains part of the logic. */
3212 INTERVAL root_interval = STRING_INTERVALS (subtree);
3213 Lisp_Object arg = Fcons (object, placeholder);
3215 traverse_intervals_noorder (root_interval,
3216 &substitute_in_interval, arg);
3218 return subtree;
3221 /* Other types don't recurse any further. */
3222 default:
3223 return subtree;
3227 /* Helper function for substitute_object_recurse. */
3228 static void
3229 substitute_in_interval (interval, arg)
3230 INTERVAL interval;
3231 Lisp_Object arg;
3233 Lisp_Object object = Fcar (arg);
3234 Lisp_Object placeholder = Fcdr (arg);
3236 SUBSTITUTE (interval->plist, interval->plist = true_value);
3240 #define LEAD_INT 1
3241 #define DOT_CHAR 2
3242 #define TRAIL_INT 4
3243 #define E_CHAR 8
3244 #define EXP_INT 16
3247 isfloat_string (cp, ignore_trailing)
3248 register char *cp;
3249 int ignore_trailing;
3251 register int state;
3253 char *start = cp;
3255 state = 0;
3256 if (*cp == '+' || *cp == '-')
3257 cp++;
3259 if (*cp >= '0' && *cp <= '9')
3261 state |= LEAD_INT;
3262 while (*cp >= '0' && *cp <= '9')
3263 cp++;
3265 if (*cp == '.')
3267 state |= DOT_CHAR;
3268 cp++;
3270 if (*cp >= '0' && *cp <= '9')
3272 state |= TRAIL_INT;
3273 while (*cp >= '0' && *cp <= '9')
3274 cp++;
3276 if (*cp == 'e' || *cp == 'E')
3278 state |= E_CHAR;
3279 cp++;
3280 if (*cp == '+' || *cp == '-')
3281 cp++;
3284 if (*cp >= '0' && *cp <= '9')
3286 state |= EXP_INT;
3287 while (*cp >= '0' && *cp <= '9')
3288 cp++;
3290 else if (cp == start)
3292 else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
3294 state |= EXP_INT;
3295 cp += 3;
3297 else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
3299 state |= EXP_INT;
3300 cp += 3;
3303 return ((ignore_trailing
3304 || (*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
3305 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
3306 || state == (DOT_CHAR|TRAIL_INT)
3307 || state == (LEAD_INT|E_CHAR|EXP_INT)
3308 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
3309 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
3313 static Lisp_Object
3314 read_vector (readcharfun, bytecodeflag)
3315 Lisp_Object readcharfun;
3316 int bytecodeflag;
3318 register int i;
3319 register int size;
3320 register Lisp_Object *ptr;
3321 register Lisp_Object tem, item, vector;
3322 register struct Lisp_Cons *otem;
3323 Lisp_Object len;
3325 tem = read_list (1, readcharfun);
3326 len = Flength (tem);
3327 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
3329 size = XVECTOR (vector)->size;
3330 ptr = XVECTOR (vector)->contents;
3331 for (i = 0; i < size; i++)
3333 item = Fcar (tem);
3334 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3335 bytecode object, the docstring containing the bytecode and
3336 constants values must be treated as unibyte and passed to
3337 Fread, to get the actual bytecode string and constants vector. */
3338 if (bytecodeflag && load_force_doc_strings)
3340 if (i == COMPILED_BYTECODE)
3342 if (!STRINGP (item))
3343 error ("Invalid byte code");
3345 /* Delay handling the bytecode slot until we know whether
3346 it is lazily-loaded (we can tell by whether the
3347 constants slot is nil). */
3348 ptr[COMPILED_CONSTANTS] = item;
3349 item = Qnil;
3351 else if (i == COMPILED_CONSTANTS)
3353 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
3355 if (NILP (item))
3357 /* Coerce string to unibyte (like string-as-unibyte,
3358 but without generating extra garbage and
3359 guaranteeing no change in the contents). */
3360 STRING_SET_CHARS (bytestr, SBYTES (bytestr));
3361 STRING_SET_UNIBYTE (bytestr);
3363 item = Fread (Fcons (bytestr, readcharfun));
3364 if (!CONSP (item))
3365 error ("Invalid byte code");
3367 otem = XCONS (item);
3368 bytestr = XCAR (item);
3369 item = XCDR (item);
3370 free_cons (otem);
3373 /* Now handle the bytecode slot. */
3374 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
3376 else if (i == COMPILED_DOC_STRING
3377 && STRINGP (item)
3378 && ! STRING_MULTIBYTE (item))
3380 if (EQ (readcharfun, Qget_emacs_mule_file_char))
3381 item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil);
3382 else
3383 item = Fstring_as_multibyte (item);
3386 ptr[i] = read_pure ? Fpurecopy (item) : item;
3387 otem = XCONS (tem);
3388 tem = Fcdr (tem);
3389 free_cons (otem);
3391 return vector;
3394 /* FLAG = 1 means check for ] to terminate rather than ) and .
3395 FLAG = -1 means check for starting with defun
3396 and make structure pure. */
3398 static Lisp_Object
3399 read_list (flag, readcharfun)
3400 int flag;
3401 register Lisp_Object readcharfun;
3403 /* -1 means check next element for defun,
3404 0 means don't check,
3405 1 means already checked and found defun. */
3406 int defunflag = flag < 0 ? -1 : 0;
3407 Lisp_Object val, tail;
3408 register Lisp_Object elt, tem;
3409 struct gcpro gcpro1, gcpro2;
3410 /* 0 is the normal case.
3411 1 means this list is a doc reference; replace it with the number 0.
3412 2 means this list is a doc reference; replace it with the doc string. */
3413 int doc_reference = 0;
3415 /* Initialize this to 1 if we are reading a list. */
3416 int first_in_list = flag <= 0;
3418 val = Qnil;
3419 tail = Qnil;
3421 while (1)
3423 int ch;
3424 GCPRO2 (val, tail);
3425 elt = read1 (readcharfun, &ch, first_in_list);
3426 UNGCPRO;
3428 first_in_list = 0;
3430 /* While building, if the list starts with #$, treat it specially. */
3431 if (EQ (elt, Vload_file_name)
3432 && ! NILP (elt)
3433 && !NILP (Vpurify_flag))
3435 if (NILP (Vdoc_file_name))
3436 /* We have not yet called Snarf-documentation, so assume
3437 this file is described in the DOC-MM.NN file
3438 and Snarf-documentation will fill in the right value later.
3439 For now, replace the whole list with 0. */
3440 doc_reference = 1;
3441 else
3442 /* We have already called Snarf-documentation, so make a relative
3443 file name for this file, so it can be found properly
3444 in the installed Lisp directory.
3445 We don't use Fexpand_file_name because that would make
3446 the directory absolute now. */
3447 elt = concat2 (build_string ("../lisp/"),
3448 Ffile_name_nondirectory (elt));
3450 else if (EQ (elt, Vload_file_name)
3451 && ! NILP (elt)
3452 && load_force_doc_strings)
3453 doc_reference = 2;
3455 if (ch)
3457 if (flag > 0)
3459 if (ch == ']')
3460 return val;
3461 invalid_syntax (") or . in a vector", 18);
3463 if (ch == ')')
3464 return val;
3465 if (ch == '.')
3467 GCPRO2 (val, tail);
3468 if (!NILP (tail))
3469 XSETCDR (tail, read0 (readcharfun));
3470 else
3471 val = read0 (readcharfun);
3472 read1 (readcharfun, &ch, 0);
3473 UNGCPRO;
3474 if (ch == ')')
3476 if (doc_reference == 1)
3477 return make_number (0);
3478 if (doc_reference == 2)
3480 /* Get a doc string from the file we are loading.
3481 If it's in saved_doc_string, get it from there.
3483 Here, we don't know if the string is a
3484 bytecode string or a doc string. As a
3485 bytecode string must be unibyte, we always
3486 return a unibyte string. If it is actually a
3487 doc string, caller must make it
3488 multibyte. */
3490 int pos = XINT (XCDR (val));
3491 /* Position is negative for user variables. */
3492 if (pos < 0) pos = -pos;
3493 if (pos >= saved_doc_string_position
3494 && pos < (saved_doc_string_position
3495 + saved_doc_string_length))
3497 int start = pos - saved_doc_string_position;
3498 int from, to;
3500 /* Process quoting with ^A,
3501 and find the end of the string,
3502 which is marked with ^_ (037). */
3503 for (from = start, to = start;
3504 saved_doc_string[from] != 037;)
3506 int c = saved_doc_string[from++];
3507 if (c == 1)
3509 c = saved_doc_string[from++];
3510 if (c == 1)
3511 saved_doc_string[to++] = c;
3512 else if (c == '0')
3513 saved_doc_string[to++] = 0;
3514 else if (c == '_')
3515 saved_doc_string[to++] = 037;
3517 else
3518 saved_doc_string[to++] = c;
3521 return make_unibyte_string (saved_doc_string + start,
3522 to - start);
3524 /* Look in prev_saved_doc_string the same way. */
3525 else if (pos >= prev_saved_doc_string_position
3526 && pos < (prev_saved_doc_string_position
3527 + prev_saved_doc_string_length))
3529 int start = pos - prev_saved_doc_string_position;
3530 int from, to;
3532 /* Process quoting with ^A,
3533 and find the end of the string,
3534 which is marked with ^_ (037). */
3535 for (from = start, to = start;
3536 prev_saved_doc_string[from] != 037;)
3538 int c = prev_saved_doc_string[from++];
3539 if (c == 1)
3541 c = prev_saved_doc_string[from++];
3542 if (c == 1)
3543 prev_saved_doc_string[to++] = c;
3544 else if (c == '0')
3545 prev_saved_doc_string[to++] = 0;
3546 else if (c == '_')
3547 prev_saved_doc_string[to++] = 037;
3549 else
3550 prev_saved_doc_string[to++] = c;
3553 return make_unibyte_string (prev_saved_doc_string
3554 + start,
3555 to - start);
3557 else
3558 return get_doc_string (val, 1, 0);
3561 return val;
3563 invalid_syntax (". in wrong context", 18);
3565 invalid_syntax ("] in a list", 11);
3567 tem = (read_pure && flag <= 0
3568 ? pure_cons (elt, Qnil)
3569 : Fcons (elt, Qnil));
3570 if (!NILP (tail))
3571 XSETCDR (tail, tem);
3572 else
3573 val = tem;
3574 tail = tem;
3575 if (defunflag < 0)
3576 defunflag = EQ (elt, Qdefun);
3577 else if (defunflag > 0)
3578 read_pure = 1;
3582 Lisp_Object Vobarray;
3583 Lisp_Object initial_obarray;
3585 /* oblookup stores the bucket number here, for the sake of Funintern. */
3587 int oblookup_last_bucket_number;
3589 static int hash_string ();
3591 /* Get an error if OBARRAY is not an obarray.
3592 If it is one, return it. */
3594 Lisp_Object
3595 check_obarray (obarray)
3596 Lisp_Object obarray;
3598 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3600 /* If Vobarray is now invalid, force it to be valid. */
3601 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
3602 wrong_type_argument (Qvectorp, obarray);
3604 return obarray;
3607 /* Intern the C string STR: return a symbol with that name,
3608 interned in the current obarray. */
3610 Lisp_Object
3611 intern (str)
3612 const char *str;
3614 Lisp_Object tem;
3615 int len = strlen (str);
3616 Lisp_Object obarray;
3618 obarray = Vobarray;
3619 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3620 obarray = check_obarray (obarray);
3621 tem = oblookup (obarray, str, len, len);
3622 if (SYMBOLP (tem))
3623 return tem;
3624 return Fintern (make_string (str, len), obarray);
3627 Lisp_Object
3628 intern_c_string (const char *str)
3630 Lisp_Object tem;
3631 int len = strlen (str);
3632 Lisp_Object obarray;
3634 obarray = Vobarray;
3635 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3636 obarray = check_obarray (obarray);
3637 tem = oblookup (obarray, str, len, len);
3638 if (SYMBOLP (tem))
3639 return tem;
3641 if (NILP (Vpurify_flag))
3642 /* Creating a non-pure string from a string literal not
3643 implemented yet. We could just use make_string here and live
3644 with the extra copy. */
3645 abort ();
3647 return Fintern (make_pure_c_string (str), obarray);
3650 /* Create an uninterned symbol with name STR. */
3652 Lisp_Object
3653 make_symbol (str)
3654 char *str;
3656 int len = strlen (str);
3658 return Fmake_symbol ((!NILP (Vpurify_flag)
3659 ? make_pure_string (str, len, len, 0)
3660 : make_string (str, len)));
3663 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
3664 doc: /* Return the canonical symbol whose name is STRING.
3665 If there is none, one is created by this function and returned.
3666 A second optional argument specifies the obarray to use;
3667 it defaults to the value of `obarray'. */)
3668 (string, obarray)
3669 Lisp_Object string, obarray;
3671 register Lisp_Object tem, sym, *ptr;
3673 if (NILP (obarray)) obarray = Vobarray;
3674 obarray = check_obarray (obarray);
3676 CHECK_STRING (string);
3678 tem = oblookup (obarray, SDATA (string),
3679 SCHARS (string),
3680 SBYTES (string));
3681 if (!INTEGERP (tem))
3682 return tem;
3684 if (!NILP (Vpurify_flag))
3685 string = Fpurecopy (string);
3686 sym = Fmake_symbol (string);
3688 if (EQ (obarray, initial_obarray))
3689 XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3690 else
3691 XSYMBOL (sym)->interned = SYMBOL_INTERNED;
3693 if ((SREF (string, 0) == ':')
3694 && EQ (obarray, initial_obarray))
3696 XSYMBOL (sym)->constant = 1;
3697 XSYMBOL (sym)->value = sym;
3700 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
3701 if (SYMBOLP (*ptr))
3702 XSYMBOL (sym)->next = XSYMBOL (*ptr);
3703 else
3704 XSYMBOL (sym)->next = 0;
3705 *ptr = sym;
3706 return sym;
3709 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
3710 doc: /* Return the canonical symbol named NAME, or nil if none exists.
3711 NAME may be a string or a symbol. If it is a symbol, that exact
3712 symbol is searched for.
3713 A second optional argument specifies the obarray to use;
3714 it defaults to the value of `obarray'. */)
3715 (name, obarray)
3716 Lisp_Object name, obarray;
3718 register Lisp_Object tem, string;
3720 if (NILP (obarray)) obarray = Vobarray;
3721 obarray = check_obarray (obarray);
3723 if (!SYMBOLP (name))
3725 CHECK_STRING (name);
3726 string = name;
3728 else
3729 string = SYMBOL_NAME (name);
3731 tem = oblookup (obarray, SDATA (string), SCHARS (string), SBYTES (string));
3732 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
3733 return Qnil;
3734 else
3735 return tem;
3738 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
3739 doc: /* Delete the symbol named NAME, if any, from OBARRAY.
3740 The value is t if a symbol was found and deleted, nil otherwise.
3741 NAME may be a string or a symbol. If it is a symbol, that symbol
3742 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3743 OBARRAY defaults to the value of the variable `obarray'. */)
3744 (name, obarray)
3745 Lisp_Object name, obarray;
3747 register Lisp_Object string, tem;
3748 int hash;
3750 if (NILP (obarray)) obarray = Vobarray;
3751 obarray = check_obarray (obarray);
3753 if (SYMBOLP (name))
3754 string = SYMBOL_NAME (name);
3755 else
3757 CHECK_STRING (name);
3758 string = name;
3761 tem = oblookup (obarray, SDATA (string),
3762 SCHARS (string),
3763 SBYTES (string));
3764 if (INTEGERP (tem))
3765 return Qnil;
3766 /* If arg was a symbol, don't delete anything but that symbol itself. */
3767 if (SYMBOLP (name) && !EQ (name, tem))
3768 return Qnil;
3770 /* There are plenty of other symbols which will screw up the Emacs
3771 session if we unintern them, as well as even more ways to use
3772 `setq' or `fset' or whatnot to make the Emacs session
3773 unusable. Let's not go down this silly road. --Stef */
3774 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
3775 error ("Attempt to unintern t or nil"); */
3777 XSYMBOL (tem)->interned = SYMBOL_UNINTERNED;
3778 XSYMBOL (tem)->constant = 0;
3779 XSYMBOL (tem)->indirect_variable = 0;
3781 hash = oblookup_last_bucket_number;
3783 if (EQ (XVECTOR (obarray)->contents[hash], tem))
3785 if (XSYMBOL (tem)->next)
3786 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
3787 else
3788 XSETINT (XVECTOR (obarray)->contents[hash], 0);
3790 else
3792 Lisp_Object tail, following;
3794 for (tail = XVECTOR (obarray)->contents[hash];
3795 XSYMBOL (tail)->next;
3796 tail = following)
3798 XSETSYMBOL (following, XSYMBOL (tail)->next);
3799 if (EQ (following, tem))
3801 XSYMBOL (tail)->next = XSYMBOL (following)->next;
3802 break;
3807 return Qt;
3810 /* Return the symbol in OBARRAY whose names matches the string
3811 of SIZE characters (SIZE_BYTE bytes) at PTR.
3812 If there is no such symbol in OBARRAY, return nil.
3814 Also store the bucket number in oblookup_last_bucket_number. */
3816 Lisp_Object
3817 oblookup (obarray, ptr, size, size_byte)
3818 Lisp_Object obarray;
3819 register const char *ptr;
3820 int size, size_byte;
3822 int hash;
3823 int obsize;
3824 register Lisp_Object tail;
3825 Lisp_Object bucket, tem;
3827 if (!VECTORP (obarray)
3828 || (obsize = XVECTOR (obarray)->size) == 0)
3830 obarray = check_obarray (obarray);
3831 obsize = XVECTOR (obarray)->size;
3833 /* This is sometimes needed in the middle of GC. */
3834 obsize &= ~ARRAY_MARK_FLAG;
3835 hash = hash_string (ptr, size_byte) % obsize;
3836 bucket = XVECTOR (obarray)->contents[hash];
3837 oblookup_last_bucket_number = hash;
3838 if (EQ (bucket, make_number (0)))
3840 else if (!SYMBOLP (bucket))
3841 error ("Bad data in guts of obarray"); /* Like CADR error message */
3842 else
3843 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
3845 if (SBYTES (SYMBOL_NAME (tail)) == size_byte
3846 && SCHARS (SYMBOL_NAME (tail)) == size
3847 && !bcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
3848 return tail;
3849 else if (XSYMBOL (tail)->next == 0)
3850 break;
3852 XSETINT (tem, hash);
3853 return tem;
3856 static int
3857 hash_string (ptr, len)
3858 const unsigned char *ptr;
3859 int len;
3861 register const unsigned char *p = ptr;
3862 register const unsigned char *end = p + len;
3863 register unsigned char c;
3864 register int hash = 0;
3866 while (p != end)
3868 c = *p++;
3869 if (c >= 0140) c -= 40;
3870 hash = ((hash<<3) + (hash>>28) + c);
3872 return hash & 07777777777;
3875 void
3876 map_obarray (obarray, fn, arg)
3877 Lisp_Object obarray;
3878 void (*fn) P_ ((Lisp_Object, Lisp_Object));
3879 Lisp_Object arg;
3881 register int i;
3882 register Lisp_Object tail;
3883 CHECK_VECTOR (obarray);
3884 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
3886 tail = XVECTOR (obarray)->contents[i];
3887 if (SYMBOLP (tail))
3888 while (1)
3890 (*fn) (tail, arg);
3891 if (XSYMBOL (tail)->next == 0)
3892 break;
3893 XSETSYMBOL (tail, XSYMBOL (tail)->next);
3898 void
3899 mapatoms_1 (sym, function)
3900 Lisp_Object sym, function;
3902 call1 (function, sym);
3905 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
3906 doc: /* Call FUNCTION on every symbol in OBARRAY.
3907 OBARRAY defaults to the value of `obarray'. */)
3908 (function, obarray)
3909 Lisp_Object function, obarray;
3911 if (NILP (obarray)) obarray = Vobarray;
3912 obarray = check_obarray (obarray);
3914 map_obarray (obarray, mapatoms_1, function);
3915 return Qnil;
3918 #define OBARRAY_SIZE 1511
3920 void
3921 init_obarray ()
3923 Lisp_Object oblength;
3924 int hash;
3925 Lisp_Object *tem;
3927 XSETFASTINT (oblength, OBARRAY_SIZE);
3929 Qnil = Fmake_symbol (make_pure_c_string ("nil"));
3930 Vobarray = Fmake_vector (oblength, make_number (0));
3931 initial_obarray = Vobarray;
3932 staticpro (&initial_obarray);
3933 /* Intern nil in the obarray */
3934 XSYMBOL (Qnil)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3935 XSYMBOL (Qnil)->constant = 1;
3937 /* These locals are to kludge around a pyramid compiler bug. */
3938 hash = hash_string ("nil", 3);
3939 /* Separate statement here to avoid VAXC bug. */
3940 hash %= OBARRAY_SIZE;
3941 tem = &XVECTOR (Vobarray)->contents[hash];
3942 *tem = Qnil;
3944 Qunbound = Fmake_symbol (make_pure_c_string ("unbound"));
3945 XSYMBOL (Qnil)->function = Qunbound;
3946 XSYMBOL (Qunbound)->value = Qunbound;
3947 XSYMBOL (Qunbound)->function = Qunbound;
3949 Qt = intern_c_string ("t");
3950 XSYMBOL (Qnil)->value = Qnil;
3951 XSYMBOL (Qnil)->plist = Qnil;
3952 XSYMBOL (Qt)->value = Qt;
3953 XSYMBOL (Qt)->constant = 1;
3955 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3956 Vpurify_flag = Qt;
3958 Qvariable_documentation = intern_c_string ("variable-documentation");
3959 staticpro (&Qvariable_documentation);
3961 read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
3962 read_buffer = (char *) xmalloc (read_buffer_size);
3965 void
3966 defsubr (sname)
3967 struct Lisp_Subr *sname;
3969 Lisp_Object sym;
3970 sym = intern_c_string (sname->symbol_name);
3971 XSETPVECTYPE (sname, PVEC_SUBR);
3972 XSETSUBR (XSYMBOL (sym)->function, sname);
3975 #ifdef NOTDEF /* use fset in subr.el now */
3976 void
3977 defalias (sname, string)
3978 struct Lisp_Subr *sname;
3979 char *string;
3981 Lisp_Object sym;
3982 sym = intern (string);
3983 XSETSUBR (XSYMBOL (sym)->function, sname);
3985 #endif /* NOTDEF */
3987 /* Define an "integer variable"; a symbol whose value is forwarded
3988 to a C variable of type int. Sample call:
3989 DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
3990 void
3991 defvar_int (const char *namestring, EMACS_INT *address)
3993 Lisp_Object sym, val;
3994 sym = intern_c_string (namestring);
3995 val = allocate_misc ();
3996 XMISCTYPE (val) = Lisp_Misc_Intfwd;
3997 XINTFWD (val)->intvar = address;
3998 SET_SYMBOL_VALUE (sym, val);
4001 /* Similar but define a variable whose value is t if address contains 1,
4002 nil if address contains 0. */
4003 void
4004 defvar_bool (const char *namestring, int *address)
4006 Lisp_Object sym, val;
4007 sym = intern_c_string (namestring);
4008 val = allocate_misc ();
4009 XMISCTYPE (val) = Lisp_Misc_Boolfwd;
4010 XBOOLFWD (val)->boolvar = address;
4011 SET_SYMBOL_VALUE (sym, val);
4012 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
4015 /* Similar but define a variable whose value is the Lisp Object stored
4016 at address. Two versions: with and without gc-marking of the C
4017 variable. The nopro version is used when that variable will be
4018 gc-marked for some other reason, since marking the same slot twice
4019 can cause trouble with strings. */
4020 void
4021 defvar_lisp_nopro (const char *namestring, Lisp_Object *address)
4023 Lisp_Object sym, val;
4024 sym = intern_c_string (namestring);
4025 val = allocate_misc ();
4026 XMISCTYPE (val) = Lisp_Misc_Objfwd;
4027 XOBJFWD (val)->objvar = address;
4028 SET_SYMBOL_VALUE (sym, val);
4031 void
4032 defvar_lisp (const char *namestring, Lisp_Object *address)
4034 defvar_lisp_nopro (namestring, address);
4035 staticpro (address);
4038 /* Similar but define a variable whose value is the Lisp Object stored
4039 at a particular offset in the current kboard object. */
4041 void
4042 defvar_kboard (const char *namestring, int offset)
4044 Lisp_Object sym, val;
4045 sym = intern_c_string (namestring);
4046 val = allocate_misc ();
4047 XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd;
4048 XKBOARD_OBJFWD (val)->offset = offset;
4049 SET_SYMBOL_VALUE (sym, val);
4052 /* Record the value of load-path used at the start of dumping
4053 so we can see if the site changed it later during dumping. */
4054 static Lisp_Object dump_path;
4056 void
4057 init_lread ()
4059 char *normal;
4060 int turn_off_warning = 0;
4062 /* Compute the default load-path. */
4063 #ifdef CANNOT_DUMP
4064 normal = PATH_LOADSEARCH;
4065 Vload_path = decode_env_path (0, normal);
4066 #else
4067 if (NILP (Vpurify_flag))
4068 normal = PATH_LOADSEARCH;
4069 else
4070 normal = PATH_DUMPLOADSEARCH;
4072 /* In a dumped Emacs, we normally have to reset the value of
4073 Vload_path from PATH_LOADSEARCH, since the value that was dumped
4074 uses ../lisp, instead of the path of the installed elisp
4075 libraries. However, if it appears that Vload_path was changed
4076 from the default before dumping, don't override that value. */
4077 if (initialized)
4079 if (! NILP (Fequal (dump_path, Vload_path)))
4081 Vload_path = decode_env_path (0, normal);
4082 if (!NILP (Vinstallation_directory))
4084 Lisp_Object tem, tem1, sitelisp;
4086 /* Remove site-lisp dirs from path temporarily and store
4087 them in sitelisp, then conc them on at the end so
4088 they're always first in path. */
4089 sitelisp = Qnil;
4090 while (1)
4092 tem = Fcar (Vload_path);
4093 tem1 = Fstring_match (build_string ("site-lisp"),
4094 tem, Qnil);
4095 if (!NILP (tem1))
4097 Vload_path = Fcdr (Vload_path);
4098 sitelisp = Fcons (tem, sitelisp);
4100 else
4101 break;
4104 /* Add to the path the lisp subdir of the
4105 installation dir, if it exists. */
4106 tem = Fexpand_file_name (build_string ("lisp"),
4107 Vinstallation_directory);
4108 tem1 = Ffile_exists_p (tem);
4109 if (!NILP (tem1))
4111 if (NILP (Fmember (tem, Vload_path)))
4113 turn_off_warning = 1;
4114 Vload_path = Fcons (tem, Vload_path);
4117 else
4118 /* That dir doesn't exist, so add the build-time
4119 Lisp dirs instead. */
4120 Vload_path = nconc2 (Vload_path, dump_path);
4122 /* Add leim under the installation dir, if it exists. */
4123 tem = Fexpand_file_name (build_string ("leim"),
4124 Vinstallation_directory);
4125 tem1 = Ffile_exists_p (tem);
4126 if (!NILP (tem1))
4128 if (NILP (Fmember (tem, Vload_path)))
4129 Vload_path = Fcons (tem, Vload_path);
4132 /* Add site-lisp under the installation dir, if it exists. */
4133 tem = Fexpand_file_name (build_string ("site-lisp"),
4134 Vinstallation_directory);
4135 tem1 = Ffile_exists_p (tem);
4136 if (!NILP (tem1))
4138 if (NILP (Fmember (tem, Vload_path)))
4139 Vload_path = Fcons (tem, Vload_path);
4142 /* If Emacs was not built in the source directory,
4143 and it is run from where it was built, add to load-path
4144 the lisp, leim and site-lisp dirs under that directory. */
4146 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
4148 Lisp_Object tem2;
4150 tem = Fexpand_file_name (build_string ("src/Makefile"),
4151 Vinstallation_directory);
4152 tem1 = Ffile_exists_p (tem);
4154 /* Don't be fooled if they moved the entire source tree
4155 AFTER dumping Emacs. If the build directory is indeed
4156 different from the source dir, src/Makefile.in and
4157 src/Makefile will not be found together. */
4158 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
4159 Vinstallation_directory);
4160 tem2 = Ffile_exists_p (tem);
4161 if (!NILP (tem1) && NILP (tem2))
4163 tem = Fexpand_file_name (build_string ("lisp"),
4164 Vsource_directory);
4166 if (NILP (Fmember (tem, Vload_path)))
4167 Vload_path = Fcons (tem, Vload_path);
4169 tem = Fexpand_file_name (build_string ("leim"),
4170 Vsource_directory);
4172 if (NILP (Fmember (tem, Vload_path)))
4173 Vload_path = Fcons (tem, Vload_path);
4175 tem = Fexpand_file_name (build_string ("site-lisp"),
4176 Vsource_directory);
4178 if (NILP (Fmember (tem, Vload_path)))
4179 Vload_path = Fcons (tem, Vload_path);
4182 if (!NILP (sitelisp))
4183 Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path);
4187 else
4189 /* NORMAL refers to the lisp dir in the source directory. */
4190 /* We used to add ../lisp at the front here, but
4191 that caused trouble because it was copied from dump_path
4192 into Vload_path, above, when Vinstallation_directory was non-nil.
4193 It should be unnecessary. */
4194 Vload_path = decode_env_path (0, normal);
4195 dump_path = Vload_path;
4197 #endif
4199 #if (!(defined (WINDOWSNT) || (defined (HAVE_NS))))
4200 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
4201 almost never correct, thereby causing a warning to be printed out that
4202 confuses users. Since PATH_LOADSEARCH is always overridden by the
4203 EMACSLOADPATH environment variable below, disable the warning on NT. */
4205 /* Warn if dirs in the *standard* path don't exist. */
4206 if (!turn_off_warning)
4208 Lisp_Object path_tail;
4210 for (path_tail = Vload_path;
4211 !NILP (path_tail);
4212 path_tail = XCDR (path_tail))
4214 Lisp_Object dirfile;
4215 dirfile = Fcar (path_tail);
4216 if (STRINGP (dirfile))
4218 dirfile = Fdirectory_file_name (dirfile);
4219 if (access (SDATA (dirfile), 0) < 0)
4220 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4221 XCAR (path_tail));
4225 #endif /* !(WINDOWSNT || HAVE_NS) */
4227 /* If the EMACSLOADPATH environment variable is set, use its value.
4228 This doesn't apply if we're dumping. */
4229 #ifndef CANNOT_DUMP
4230 if (NILP (Vpurify_flag)
4231 && egetenv ("EMACSLOADPATH"))
4232 #endif
4233 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4235 Vvalues = Qnil;
4237 load_in_progress = 0;
4238 Vload_file_name = Qnil;
4240 load_descriptor_list = Qnil;
4242 Vstandard_input = Qt;
4243 Vloads_in_progress = Qnil;
4246 /* Print a warning, using format string FORMAT, that directory DIRNAME
4247 does not exist. Print it on stderr and put it in *Messages*. */
4249 void
4250 dir_warning (format, dirname)
4251 char *format;
4252 Lisp_Object dirname;
4254 char *buffer
4255 = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);
4257 fprintf (stderr, format, SDATA (dirname));
4258 sprintf (buffer, format, SDATA (dirname));
4259 /* Don't log the warning before we've initialized!! */
4260 if (initialized)
4261 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
4264 void
4265 syms_of_lread ()
4267 defsubr (&Sread);
4268 defsubr (&Sread_from_string);
4269 defsubr (&Sintern);
4270 defsubr (&Sintern_soft);
4271 defsubr (&Sunintern);
4272 defsubr (&Sget_load_suffixes);
4273 defsubr (&Sload);
4274 defsubr (&Seval_buffer);
4275 defsubr (&Seval_region);
4276 defsubr (&Sread_char);
4277 defsubr (&Sread_char_exclusive);
4278 defsubr (&Sread_event);
4279 defsubr (&Sget_file_char);
4280 defsubr (&Smapatoms);
4281 defsubr (&Slocate_file_internal);
4283 DEFVAR_LISP ("obarray", &Vobarray,
4284 doc: /* Symbol table for use by `intern' and `read'.
4285 It is a vector whose length ought to be prime for best results.
4286 The vector's contents don't make sense if examined from Lisp programs;
4287 to find all the symbols in an obarray, use `mapatoms'. */);
4289 DEFVAR_LISP ("values", &Vvalues,
4290 doc: /* List of values of all expressions which were read, evaluated and printed.
4291 Order is reverse chronological. */);
4293 DEFVAR_LISP ("standard-input", &Vstandard_input,
4294 doc: /* Stream for read to get input from.
4295 See documentation of `read' for possible values. */);
4296 Vstandard_input = Qt;
4298 DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions,
4299 doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4301 If this variable is a buffer, then only forms read from that buffer
4302 will be added to `read-symbol-positions-list'.
4303 If this variable is t, then all read forms will be added.
4304 The effect of all other values other than nil are not currently
4305 defined, although they may be in the future.
4307 The positions are relative to the last call to `read' or
4308 `read-from-string'. It is probably a bad idea to set this variable at
4309 the toplevel; bind it instead. */);
4310 Vread_with_symbol_positions = Qnil;
4312 DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list,
4313 doc: /* A list mapping read symbols to their positions.
4314 This variable is modified during calls to `read' or
4315 `read-from-string', but only when `read-with-symbol-positions' is
4316 non-nil.
4318 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4319 CHAR-POSITION is an integer giving the offset of that occurrence of the
4320 symbol from the position where `read' or `read-from-string' started.
4322 Note that a symbol will appear multiple times in this list, if it was
4323 read multiple times. The list is in the same order as the symbols
4324 were read in. */);
4325 Vread_symbol_positions_list = Qnil;
4327 DEFVAR_LISP ("read-circle", &Vread_circle,
4328 doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4329 Vread_circle = Qt;
4331 DEFVAR_LISP ("load-path", &Vload_path,
4332 doc: /* *List of directories to search for files to load.
4333 Each element is a string (directory name) or nil (try default directory).
4334 Initialized based on EMACSLOADPATH environment variable, if any,
4335 otherwise to default specified by file `epaths.h' when Emacs was built. */);
4337 DEFVAR_LISP ("load-suffixes", &Vload_suffixes,
4338 doc: /* List of suffixes for (compiled or source) Emacs Lisp files.
4339 This list should not include the empty string.
4340 `load' and related functions try to append these suffixes, in order,
4341 to the specified file name if a Lisp suffix is allowed or required. */);
4342 Vload_suffixes = Fcons (make_pure_c_string (".elc"),
4343 Fcons (make_pure_c_string (".el"), Qnil));
4344 DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes,
4345 doc: /* List of suffixes that indicate representations of \
4346 the same file.
4347 This list should normally start with the empty string.
4349 Enabling Auto Compression mode appends the suffixes in
4350 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4351 mode removes them again. `load' and related functions use this list to
4352 determine whether they should look for compressed versions of a file
4353 and, if so, which suffixes they should try to append to the file name
4354 in order to do so. However, if you want to customize which suffixes
4355 the loading functions recognize as compression suffixes, you should
4356 customize `jka-compr-load-suffixes' rather than the present variable. */);
4357 Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil);
4359 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
4360 doc: /* Non-nil if inside of `load'. */);
4361 Qload_in_progress = intern_c_string ("load-in-progress");
4362 staticpro (&Qload_in_progress);
4364 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
4365 doc: /* An alist of expressions to be evalled when particular files are loaded.
4366 Each element looks like (REGEXP-OR-FEATURE FORMS...).
4368 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4369 a symbol \(a feature name).
4371 When `load' is run and the file-name argument matches an element's
4372 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4373 REGEXP-OR-FEATURE, the FORMS in the element are executed.
4375 An error in FORMS does not undo the load, but does prevent execution of
4376 the rest of the FORMS. */);
4377 Vafter_load_alist = Qnil;
4379 DEFVAR_LISP ("load-history", &Vload_history,
4380 doc: /* Alist mapping loaded file names to symbols and features.
4381 Each alist element should be a list (FILE-NAME ENTRIES...), where
4382 FILE-NAME is the name of a file that has been loaded into Emacs.
4383 The file name is absolute and true (i.e. it doesn't contain symlinks).
4384 As an exception, one of the alist elements may have FILE-NAME nil,
4385 for symbols and features not associated with any file.
4387 The remaining ENTRIES in the alist element describe the functions and
4388 variables defined in that file, the features provided, and the
4389 features required. Each entry has the form `(provide . FEATURE)',
4390 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4391 `(defface . SYMBOL)', or `(t . SYMBOL)'. In addition, an entry `(t
4392 . SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
4393 SYMBOL was an autoload before this file redefined it as a function.
4395 During preloading, the file name recorded is relative to the main Lisp
4396 directory. These file names are converted to absolute at startup. */);
4397 Vload_history = Qnil;
4399 DEFVAR_LISP ("load-file-name", &Vload_file_name,
4400 doc: /* Full name of file being loaded by `load'. */);
4401 Vload_file_name = Qnil;
4403 DEFVAR_LISP ("user-init-file", &Vuser_init_file,
4404 doc: /* File name, including directory, of user's initialization file.
4405 If the file loaded had extension `.elc', and the corresponding source file
4406 exists, this variable contains the name of source file, suitable for use
4407 by functions like `custom-save-all' which edit the init file.
4408 While Emacs loads and evaluates the init file, value is the real name
4409 of the file, regardless of whether or not it has the `.elc' extension. */);
4410 Vuser_init_file = Qnil;
4412 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
4413 doc: /* Used for internal purposes by `load'. */);
4414 Vcurrent_load_list = Qnil;
4416 DEFVAR_LISP ("load-read-function", &Vload_read_function,
4417 doc: /* Function used by `load' and `eval-region' for reading expressions.
4418 The default is nil, which means use the function `read'. */);
4419 Vload_read_function = Qnil;
4421 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
4422 doc: /* Function called in `load' for loading an Emacs Lisp source file.
4423 This function is for doing code conversion before reading the source file.
4424 If nil, loading is done without any code conversion.
4425 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
4426 FULLNAME is the full name of FILE.
4427 See `load' for the meaning of the remaining arguments. */);
4428 Vload_source_file_function = Qnil;
4430 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
4431 doc: /* Non-nil means `load' should force-load all dynamic doc strings.
4432 This is useful when the file being loaded is a temporary copy. */);
4433 load_force_doc_strings = 0;
4435 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
4436 doc: /* Non-nil means `read' converts strings to unibyte whenever possible.
4437 This is normally bound by `load' and `eval-buffer' to control `read',
4438 and is not meant for users to change. */);
4439 load_convert_to_unibyte = 0;
4441 DEFVAR_LISP ("source-directory", &Vsource_directory,
4442 doc: /* Directory in which Emacs sources were found when Emacs was built.
4443 You cannot count on them to still be there! */);
4444 Vsource_directory
4445 = Fexpand_file_name (build_string ("../"),
4446 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
4448 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
4449 doc: /* List of files that were preloaded (when dumping Emacs). */);
4450 Vpreloaded_file_list = Qnil;
4452 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
4453 doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4454 Vbyte_boolean_vars = Qnil;
4456 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries,
4457 doc: /* Non-nil means load dangerous compiled Lisp files.
4458 Some versions of XEmacs use different byte codes than Emacs. These
4459 incompatible byte codes can make Emacs crash when it tries to execute
4460 them. */);
4461 load_dangerous_libraries = 0;
4463 DEFVAR_BOOL ("force-load-messages", &force_load_messages,
4464 doc: /* Non-nil means force printing messages when loading Lisp files.
4465 This overrides the value of the NOMESSAGE argument to `load'. */);
4466 force_load_messages = 0;
4468 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp,
4469 doc: /* Regular expression matching safe to load compiled Lisp files.
4470 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4471 from the file, and matches them against this regular expression.
4472 When the regular expression matches, the file is considered to be safe
4473 to load. See also `load-dangerous-libraries'. */);
4474 Vbytecomp_version_regexp
4475 = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4477 DEFVAR_LISP ("eval-buffer-list", &Veval_buffer_list,
4478 doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4479 Veval_buffer_list = Qnil;
4481 DEFVAR_LISP ("old-style-backquotes", &Vold_style_backquotes,
4482 doc: /* Set to non-nil when `read' encounters an old-style backquote. */);
4483 Vold_style_backquotes = Qnil;
4484 Qold_style_backquotes = intern_c_string ("old-style-backquotes");
4485 staticpro (&Qold_style_backquotes);
4487 /* Vsource_directory was initialized in init_lread. */
4489 load_descriptor_list = Qnil;
4490 staticpro (&load_descriptor_list);
4492 Qcurrent_load_list = intern_c_string ("current-load-list");
4493 staticpro (&Qcurrent_load_list);
4495 Qstandard_input = intern_c_string ("standard-input");
4496 staticpro (&Qstandard_input);
4498 Qread_char = intern_c_string ("read-char");
4499 staticpro (&Qread_char);
4501 Qget_file_char = intern_c_string ("get-file-char");
4502 staticpro (&Qget_file_char);
4504 Qget_emacs_mule_file_char = intern_c_string ("get-emacs-mule-file-char");
4505 staticpro (&Qget_emacs_mule_file_char);
4507 Qload_force_doc_strings = intern_c_string ("load-force-doc-strings");
4508 staticpro (&Qload_force_doc_strings);
4510 Qbackquote = intern_c_string ("`");
4511 staticpro (&Qbackquote);
4512 Qcomma = intern_c_string (",");
4513 staticpro (&Qcomma);
4514 Qcomma_at = intern_c_string (",@");
4515 staticpro (&Qcomma_at);
4516 Qcomma_dot = intern_c_string (",.");
4517 staticpro (&Qcomma_dot);
4519 Qinhibit_file_name_operation = intern_c_string ("inhibit-file-name-operation");
4520 staticpro (&Qinhibit_file_name_operation);
4522 Qascii_character = intern_c_string ("ascii-character");
4523 staticpro (&Qascii_character);
4525 Qfunction = intern_c_string ("function");
4526 staticpro (&Qfunction);
4528 Qload = intern_c_string ("load");
4529 staticpro (&Qload);
4531 Qload_file_name = intern_c_string ("load-file-name");
4532 staticpro (&Qload_file_name);
4534 Qeval_buffer_list = intern_c_string ("eval-buffer-list");
4535 staticpro (&Qeval_buffer_list);
4537 Qfile_truename = intern_c_string ("file-truename");
4538 staticpro (&Qfile_truename) ;
4540 Qdo_after_load_evaluation = intern_c_string ("do-after-load-evaluation");
4541 staticpro (&Qdo_after_load_evaluation) ;
4543 staticpro (&dump_path);
4545 staticpro (&read_objects);
4546 read_objects = Qnil;
4547 staticpro (&seen_list);
4548 seen_list = Qnil;
4550 Vloads_in_progress = Qnil;
4551 staticpro (&Vloads_in_progress);
4553 Qhash_table = intern_c_string ("hash-table");
4554 staticpro (&Qhash_table);
4555 Qdata = intern_c_string ("data");
4556 staticpro (&Qdata);
4557 Qtest = intern_c_string ("test");
4558 staticpro (&Qtest);
4559 Qsize = intern_c_string ("size");
4560 staticpro (&Qsize);
4561 Qweakness = intern_c_string ("weakness");
4562 staticpro (&Qweakness);
4563 Qrehash_size = intern_c_string ("rehash-size");
4564 staticpro (&Qrehash_size);
4565 Qrehash_threshold = intern_c_string ("rehash-threshold");
4566 staticpro (&Qrehash_threshold);
4569 /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d
4570 (do not change this comment) */