Fix crash condition when an X server connection is broken. (Reported by Vincent Bernat.)
[emacs.git] / src / lread.c
blob5b5ea478a163e1568b3db8ca68b58e43b4b22e60
1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995, 1997, 1998,
3 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <config.h>
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <sys/file.h>
28 #include <errno.h>
29 #include "lisp.h"
30 #include "intervals.h"
31 #include "buffer.h"
32 #include "charset.h"
33 #include <epaths.h>
34 #include "commands.h"
35 #include "keyboard.h"
36 #include "frame.h"
37 #include "termhooks.h"
38 #include "coding.h"
40 #ifdef lint
41 #include <sys/inode.h>
42 #endif /* lint */
44 #ifdef MSDOS
45 #if __DJGPP__ < 2
46 #include <unistd.h> /* to get X_OK */
47 #endif
48 #include "msdos.h"
49 #endif
51 #ifdef HAVE_UNISTD_H
52 #include <unistd.h>
53 #endif
55 #ifndef X_OK
56 #define X_OK 01
57 #endif
59 #include <math.h>
61 #ifdef HAVE_SETLOCALE
62 #include <locale.h>
63 #endif /* HAVE_SETLOCALE */
65 #ifdef HAVE_FCNTL_H
66 #include <fcntl.h>
67 #endif
68 #ifndef O_RDONLY
69 #define O_RDONLY 0
70 #endif
72 #ifdef HAVE_FSEEKO
73 #define file_offset off_t
74 #define file_tell ftello
75 #else
76 #define file_offset long
77 #define file_tell ftell
78 #endif
80 #ifndef USE_CRT_DLL
81 extern int errno;
82 #endif
84 Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
85 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
86 Lisp_Object Qascii_character, Qload, Qload_file_name;
87 Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
88 Lisp_Object Qinhibit_file_name_operation;
90 extern Lisp_Object Qevent_symbol_element_mask;
91 extern Lisp_Object Qfile_exists_p;
93 /* non-zero if inside `load' */
94 int load_in_progress;
96 /* Directory in which the sources were found. */
97 Lisp_Object Vsource_directory;
99 /* Search path and suffixes for files to be loaded. */
100 Lisp_Object Vload_path, Vload_suffixes, default_suffixes;
102 /* File name of user's init file. */
103 Lisp_Object Vuser_init_file;
105 /* This is the user-visible association list that maps features to
106 lists of defs in their load files. */
107 Lisp_Object Vload_history;
109 /* This is used to build the load history. */
110 Lisp_Object Vcurrent_load_list;
112 /* List of files that were preloaded. */
113 Lisp_Object Vpreloaded_file_list;
115 /* Name of file actually being read by `load'. */
116 Lisp_Object Vload_file_name;
118 /* Function to use for reading, in `load' and friends. */
119 Lisp_Object Vload_read_function;
121 /* The association list of objects read with the #n=object form.
122 Each member of the list has the form (n . object), and is used to
123 look up the object for the corresponding #n# construct.
124 It must be set to nil before all top-level calls to read0. */
125 Lisp_Object read_objects;
127 /* Nonzero means load should forcibly load all dynamic doc strings. */
128 static int load_force_doc_strings;
130 /* Nonzero means read should convert strings to unibyte. */
131 static int load_convert_to_unibyte;
133 /* Function to use for loading an Emacs lisp source file (not
134 compiled) instead of readevalloop. */
135 Lisp_Object Vload_source_file_function;
137 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
138 Lisp_Object Vbyte_boolean_vars;
140 /* Whether or not to add a `read-positions' property to symbols
141 read. */
142 Lisp_Object Vread_with_symbol_positions;
144 /* List of (SYMBOL . POSITION) accumulated so far. */
145 Lisp_Object Vread_symbol_positions_list;
147 /* List of descriptors now open for Fload. */
148 static Lisp_Object load_descriptor_list;
150 /* File for get_file_char to read from. Use by load. */
151 static FILE *instream;
153 /* When nonzero, read conses in pure space */
154 static int read_pure;
156 /* For use within read-from-string (this reader is non-reentrant!!) */
157 static int read_from_string_index;
158 static int read_from_string_index_byte;
159 static int read_from_string_limit;
161 /* Number of bytes left to read in the buffer character
162 that `readchar' has already advanced over. */
163 static int readchar_backlog;
164 /* Number of characters read in the current call to Fread or
165 Fread_from_string. */
166 static int readchar_count;
168 /* This contains the last string skipped with #@. */
169 static char *saved_doc_string;
170 /* Length of buffer allocated in saved_doc_string. */
171 static int saved_doc_string_size;
172 /* Length of actual data in saved_doc_string. */
173 static int saved_doc_string_length;
174 /* This is the file position that string came from. */
175 static file_offset saved_doc_string_position;
177 /* This contains the previous string skipped with #@.
178 We copy it from saved_doc_string when a new string
179 is put in saved_doc_string. */
180 static char *prev_saved_doc_string;
181 /* Length of buffer allocated in prev_saved_doc_string. */
182 static int prev_saved_doc_string_size;
183 /* Length of actual data in prev_saved_doc_string. */
184 static int prev_saved_doc_string_length;
185 /* This is the file position that string came from. */
186 static file_offset prev_saved_doc_string_position;
188 /* Nonzero means inside a new-style backquote
189 with no surrounding parentheses.
190 Fread initializes this to zero, so we need not specbind it
191 or worry about what happens to it when there is an error. */
192 static int new_backquote_flag;
194 /* A list of file names for files being loaded in Fload. Used to
195 check for recursive loads. */
197 static Lisp_Object Vloads_in_progress;
199 /* Non-zero means load dangerous compiled Lisp files. */
201 int load_dangerous_libraries;
203 /* A regular expression used to detect files compiled with Emacs. */
205 static Lisp_Object Vbytecomp_version_regexp;
207 static void to_multibyte P_ ((char **, char **, int *));
208 static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
209 Lisp_Object (*) (), int,
210 Lisp_Object, Lisp_Object));
211 static Lisp_Object load_unwind P_ ((Lisp_Object));
212 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
215 /* Handle unreading and rereading of characters.
216 Write READCHAR to read a character,
217 UNREAD(c) to unread c to be read again.
219 The READCHAR and UNREAD macros are meant for reading/unreading a
220 byte code; they do not handle multibyte characters. The caller
221 should manage them if necessary.
223 [ Actually that seems to be a lie; READCHAR will definitely read
224 multibyte characters from buffer sources, at least. Is the
225 comment just out of date?
226 -- Colin Walters <walters@gnu.org>, 22 May 2002 16:36:50 -0400 ]
229 #define READCHAR readchar (readcharfun)
230 #define UNREAD(c) unreadchar (readcharfun, c)
232 static int
233 readchar (readcharfun)
234 Lisp_Object readcharfun;
236 Lisp_Object tem;
237 register int c;
239 readchar_count++;
241 if (BUFFERP (readcharfun))
243 register struct buffer *inbuffer = XBUFFER (readcharfun);
245 int pt_byte = BUF_PT_BYTE (inbuffer);
246 int orig_pt_byte = pt_byte;
248 if (readchar_backlog > 0)
249 /* We get the address of the byte just passed,
250 which is the last byte of the character.
251 The other bytes in this character are consecutive with it,
252 because the gap can't be in the middle of a character. */
253 return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1)
254 - --readchar_backlog);
256 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
257 return -1;
259 readchar_backlog = -1;
261 if (! NILP (inbuffer->enable_multibyte_characters))
263 /* Fetch the character code from the buffer. */
264 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
265 BUF_INC_POS (inbuffer, pt_byte);
266 c = STRING_CHAR (p, pt_byte - orig_pt_byte);
268 else
270 c = BUF_FETCH_BYTE (inbuffer, pt_byte);
271 pt_byte++;
273 SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
275 return c;
277 if (MARKERP (readcharfun))
279 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
281 int bytepos = marker_byte_position (readcharfun);
282 int orig_bytepos = bytepos;
284 if (readchar_backlog > 0)
285 /* We get the address of the byte just passed,
286 which is the last byte of the character.
287 The other bytes in this character are consecutive with it,
288 because the gap can't be in the middle of a character. */
289 return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1)
290 - --readchar_backlog);
292 if (bytepos >= BUF_ZV_BYTE (inbuffer))
293 return -1;
295 readchar_backlog = -1;
297 if (! NILP (inbuffer->enable_multibyte_characters))
299 /* Fetch the character code from the buffer. */
300 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
301 BUF_INC_POS (inbuffer, bytepos);
302 c = STRING_CHAR (p, bytepos - orig_bytepos);
304 else
306 c = BUF_FETCH_BYTE (inbuffer, bytepos);
307 bytepos++;
310 XMARKER (readcharfun)->bytepos = bytepos;
311 XMARKER (readcharfun)->charpos++;
313 return c;
316 if (EQ (readcharfun, Qlambda))
317 return read_bytecode_char (0);
319 if (EQ (readcharfun, Qget_file_char))
321 c = getc (instream);
322 #ifdef EINTR
323 /* Interrupted reads have been observed while reading over the network */
324 while (c == EOF && ferror (instream) && errno == EINTR)
326 QUIT;
327 clearerr (instream);
328 c = getc (instream);
330 #endif
331 return c;
334 if (STRINGP (readcharfun))
336 if (read_from_string_index >= read_from_string_limit)
337 c = -1;
338 else
339 FETCH_STRING_CHAR_ADVANCE (c, readcharfun,
340 read_from_string_index,
341 read_from_string_index_byte);
343 return c;
346 tem = call0 (readcharfun);
348 if (NILP (tem))
349 return -1;
350 return XINT (tem);
353 /* Unread the character C in the way appropriate for the stream READCHARFUN.
354 If the stream is a user function, call it with the char as argument. */
356 static void
357 unreadchar (readcharfun, c)
358 Lisp_Object readcharfun;
359 int c;
361 readchar_count--;
362 if (c == -1)
363 /* Don't back up the pointer if we're unreading the end-of-input mark,
364 since readchar didn't advance it when we read it. */
366 else if (BUFFERP (readcharfun))
368 struct buffer *b = XBUFFER (readcharfun);
369 int bytepos = BUF_PT_BYTE (b);
371 if (readchar_backlog >= 0)
372 readchar_backlog++;
373 else
375 BUF_PT (b)--;
376 if (! NILP (b->enable_multibyte_characters))
377 BUF_DEC_POS (b, bytepos);
378 else
379 bytepos--;
381 BUF_PT_BYTE (b) = bytepos;
384 else if (MARKERP (readcharfun))
386 struct buffer *b = XMARKER (readcharfun)->buffer;
387 int bytepos = XMARKER (readcharfun)->bytepos;
389 if (readchar_backlog >= 0)
390 readchar_backlog++;
391 else
393 XMARKER (readcharfun)->charpos--;
394 if (! NILP (b->enable_multibyte_characters))
395 BUF_DEC_POS (b, bytepos);
396 else
397 bytepos--;
399 XMARKER (readcharfun)->bytepos = bytepos;
402 else if (STRINGP (readcharfun))
404 read_from_string_index--;
405 read_from_string_index_byte
406 = string_char_to_byte (readcharfun, read_from_string_index);
408 else if (EQ (readcharfun, Qlambda))
409 read_bytecode_char (1);
410 else if (EQ (readcharfun, Qget_file_char))
411 ungetc (c, instream);
412 else
413 call1 (readcharfun, make_number (c));
416 static Lisp_Object read_internal_start P_ ((Lisp_Object, Lisp_Object,
417 Lisp_Object));
418 static Lisp_Object read0 P_ ((Lisp_Object));
419 static Lisp_Object read1 P_ ((Lisp_Object, int *, int));
421 static Lisp_Object read_list P_ ((int, Lisp_Object));
422 static Lisp_Object read_vector P_ ((Lisp_Object, int));
423 static int read_multibyte P_ ((int, Lisp_Object));
425 static Lisp_Object substitute_object_recurse P_ ((Lisp_Object, Lisp_Object,
426 Lisp_Object));
427 static void substitute_object_in_subtree P_ ((Lisp_Object,
428 Lisp_Object));
429 static void substitute_in_interval P_ ((INTERVAL, Lisp_Object));
432 /* Get a character from the tty. */
434 extern Lisp_Object read_char ();
436 /* Read input events until we get one that's acceptable for our purposes.
438 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
439 until we get a character we like, and then stuffed into
440 unread_switch_frame.
442 If ASCII_REQUIRED is non-zero, we check function key events to see
443 if the unmodified version of the symbol has a Qascii_character
444 property, and use that character, if present.
446 If ERROR_NONASCII is non-zero, we signal an error if the input we
447 get isn't an ASCII character with modifiers. If it's zero but
448 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
449 character.
451 If INPUT_METHOD is nonzero, we invoke the current input method
452 if the character warrants that. */
454 Lisp_Object
455 read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
456 input_method)
457 int no_switch_frame, ascii_required, error_nonascii, input_method;
459 register Lisp_Object val, delayed_switch_frame;
461 #ifdef HAVE_WINDOW_SYSTEM
462 if (display_hourglass_p)
463 cancel_hourglass ();
464 #endif
466 delayed_switch_frame = Qnil;
468 /* Read until we get an acceptable event. */
469 retry:
470 val = read_char (0, 0, 0,
471 (input_method ? Qnil : Qt),
474 if (BUFFERP (val))
475 goto retry;
477 /* switch-frame events are put off until after the next ASCII
478 character. This is better than signaling an error just because
479 the last characters were typed to a separate minibuffer frame,
480 for example. Eventually, some code which can deal with
481 switch-frame events will read it and process it. */
482 if (no_switch_frame
483 && EVENT_HAS_PARAMETERS (val)
484 && EQ (EVENT_HEAD (val), Qswitch_frame))
486 delayed_switch_frame = val;
487 goto retry;
490 if (ascii_required)
492 /* Convert certain symbols to their ASCII equivalents. */
493 if (SYMBOLP (val))
495 Lisp_Object tem, tem1;
496 tem = Fget (val, Qevent_symbol_element_mask);
497 if (!NILP (tem))
499 tem1 = Fget (Fcar (tem), Qascii_character);
500 /* Merge this symbol's modifier bits
501 with the ASCII equivalent of its basic code. */
502 if (!NILP (tem1))
503 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
507 /* If we don't have a character now, deal with it appropriately. */
508 if (!INTEGERP (val))
510 if (error_nonascii)
512 Vunread_command_events = Fcons (val, Qnil);
513 error ("Non-character input-event");
515 else
516 goto retry;
520 if (! NILP (delayed_switch_frame))
521 unread_switch_frame = delayed_switch_frame;
523 #if 0
525 #ifdef HAVE_WINDOW_SYSTEM
526 if (display_hourglass_p)
527 start_hourglass ();
528 #endif
530 #endif
532 return val;
535 DEFUN ("read-char", Fread_char, Sread_char, 0, 2, 0,
536 doc: /* Read a character from the command input (keyboard or macro).
537 It is returned as a number.
538 If the user generates an event which is not a character (i.e. a mouse
539 click or function key event), `read-char' signals an error. As an
540 exception, switch-frame events are put off until non-ASCII events can
541 be read.
542 If you want to read non-character events, or ignore them, call
543 `read-event' or `read-char-exclusive' instead.
545 If the optional argument PROMPT is non-nil, display that as a prompt.
546 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
547 input method is turned on in the current buffer, that input method
548 is used for reading a character. */)
549 (prompt, inherit_input_method)
550 Lisp_Object prompt, inherit_input_method;
552 if (! NILP (prompt))
553 message_with_string ("%s", prompt, 0);
554 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method));
557 DEFUN ("read-event", Fread_event, Sread_event, 0, 2, 0,
558 doc: /* Read an event object from the input stream.
559 If the optional argument PROMPT is non-nil, display that as a prompt.
560 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
561 input method is turned on in the current buffer, that input method
562 is used for reading a character. */)
563 (prompt, inherit_input_method)
564 Lisp_Object prompt, inherit_input_method;
566 if (! NILP (prompt))
567 message_with_string ("%s", prompt, 0);
568 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method));
571 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 2, 0,
572 doc: /* Read a character from the command input (keyboard or macro).
573 It is returned as a number. Non-character events are ignored.
575 If the optional argument PROMPT is non-nil, display that as a prompt.
576 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
577 input method is turned on in the current buffer, that input method
578 is used for reading a character. */)
579 (prompt, inherit_input_method)
580 Lisp_Object prompt, inherit_input_method;
582 if (! NILP (prompt))
583 message_with_string ("%s", prompt, 0);
584 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method));
587 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
588 doc: /* Don't use this yourself. */)
591 register Lisp_Object val;
592 XSETINT (val, getc (instream));
593 return val;
598 /* Value is non-zero if the file asswociated with file descriptor FD
599 is a compiled Lisp file that's safe to load. Only files compiled
600 with Emacs are safe to load. Files compiled with XEmacs can lead
601 to a crash in Fbyte_code because of an incompatible change in the
602 byte compiler. */
604 static int
605 safe_to_load_p (fd)
606 int fd;
608 char buf[512];
609 int nbytes, i;
610 int safe_p = 1;
612 /* Read the first few bytes from the file, and look for a line
613 specifying the byte compiler version used. */
614 nbytes = emacs_read (fd, buf, sizeof buf - 1);
615 if (nbytes > 0)
617 buf[nbytes] = '\0';
619 /* Skip to the next newline, skipping over the initial `ELC'
620 with NUL bytes following it. */
621 for (i = 0; i < nbytes && buf[i] != '\n'; ++i)
624 if (i < nbytes
625 && fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
626 buf + i) < 0)
627 safe_p = 0;
630 lseek (fd, 0, SEEK_SET);
631 return safe_p;
635 /* Callback for record_unwind_protect. Restore the old load list OLD,
636 after loading a file successfully. */
638 static Lisp_Object
639 record_load_unwind (old)
640 Lisp_Object old;
642 return Vloads_in_progress = old;
645 /* This handler function is used via internal_condition_case_1. */
647 static Lisp_Object
648 load_error_handler (data)
649 Lisp_Object data;
651 return Qnil;
654 DEFUN ("load", Fload, Sload, 1, 5, 0,
655 doc: /* Execute a file of Lisp code named FILE.
656 First try FILE with `.elc' appended, then try with `.el',
657 then try FILE unmodified (the exact suffixes are determined by
658 `load-suffixes'). Environment variable references in FILE
659 are replaced with their values by calling `substitute-in-file-name'.
660 This function searches the directories in `load-path'.
661 If optional second arg NOERROR is non-nil,
662 report no error if FILE doesn't exist.
663 Print messages at start and end of loading unless
664 optional third arg NOMESSAGE is non-nil.
665 If optional fourth arg NOSUFFIX is non-nil, don't try adding
666 suffixes `.elc' or `.el' to the specified name FILE.
667 If optional fifth arg MUST-SUFFIX is non-nil, insist on
668 the suffix `.elc' or `.el'; don't accept just FILE unless
669 it ends in one of those suffixes or includes a directory name.
670 Return t if file exists. */)
671 (file, noerror, nomessage, nosuffix, must_suffix)
672 Lisp_Object file, noerror, nomessage, nosuffix, must_suffix;
674 register FILE *stream;
675 register int fd = -1;
676 register Lisp_Object lispstream;
677 int count = SPECPDL_INDEX ();
678 Lisp_Object temp;
679 struct gcpro gcpro1;
680 Lisp_Object found, efound;
681 /* 1 means we printed the ".el is newer" message. */
682 int newer = 0;
683 /* 1 means we are loading a compiled file. */
684 int compiled = 0;
685 Lisp_Object handler;
686 int safe_p = 1;
687 char *fmode = "r";
688 #ifdef DOS_NT
689 fmode = "rt";
690 #endif /* DOS_NT */
692 CHECK_STRING (file);
694 /* If file name is magic, call the handler. */
695 /* This shouldn't be necessary any more now that `openp' handles it right.
696 handler = Ffind_file_name_handler (file, Qload);
697 if (!NILP (handler))
698 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
700 /* Do this after the handler to avoid
701 the need to gcpro noerror, nomessage and nosuffix.
702 (Below here, we care only whether they are nil or not.)
703 The presence of this call is the result of a historical accident:
704 it used to be in every file-operations and when it got removed
705 everywhere, it accidentally stayed here. Since then, enough people
706 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
707 that it seemed risky to remove. */
708 if (! NILP (noerror))
710 file = internal_condition_case_1 (Fsubstitute_in_file_name, file,
711 Qt, load_error_handler);
712 if (NILP (file))
713 return Qnil;
715 else
716 file = Fsubstitute_in_file_name (file);
719 /* Avoid weird lossage with null string as arg,
720 since it would try to load a directory as a Lisp file */
721 if (SCHARS (file) > 0)
723 int size = SBYTES (file);
724 Lisp_Object tmp[2];
726 GCPRO1 (file);
728 if (! NILP (must_suffix))
730 /* Don't insist on adding a suffix if FILE already ends with one. */
731 if (size > 3
732 && !strcmp (SDATA (file) + size - 3, ".el"))
733 must_suffix = Qnil;
734 else if (size > 4
735 && !strcmp (SDATA (file) + size - 4, ".elc"))
736 must_suffix = Qnil;
737 /* Don't insist on adding a suffix
738 if the argument includes a directory name. */
739 else if (! NILP (Ffile_name_directory (file)))
740 must_suffix = Qnil;
743 fd = openp (Vload_path, file,
744 (!NILP (nosuffix) ? Qnil
745 : !NILP (must_suffix) ? Vload_suffixes
746 : Fappend (2, (tmp[0] = Vload_suffixes,
747 tmp[1] = default_suffixes,
748 tmp))),
749 &found, Qnil);
750 UNGCPRO;
753 if (fd == -1)
755 if (NILP (noerror))
756 Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"),
757 Fcons (file, Qnil)));
758 else
759 return Qnil;
762 /* Tell startup.el whether or not we found the user's init file. */
763 if (EQ (Qt, Vuser_init_file))
764 Vuser_init_file = found;
766 /* If FD is -2, that means openp found a magic file. */
767 if (fd == -2)
769 if (NILP (Fequal (found, file)))
770 /* If FOUND is a different file name from FILE,
771 find its handler even if we have already inhibited
772 the `load' operation on FILE. */
773 handler = Ffind_file_name_handler (found, Qt);
774 else
775 handler = Ffind_file_name_handler (found, Qload);
776 if (! NILP (handler))
777 return call5 (handler, Qload, found, noerror, nomessage, Qt);
780 /* Check if we're stuck in a recursive load cycle.
782 2000-09-21: It's not possible to just check for the file loaded
783 being a member of Vloads_in_progress. This fails because of the
784 way the byte compiler currently works; `provide's are not
785 evaluted, see font-lock.el/jit-lock.el as an example. This
786 leads to a certain amount of ``normal'' recursion.
788 Also, just loading a file recursively is not always an error in
789 the general case; the second load may do something different. */
791 int count = 0;
792 Lisp_Object tem;
793 for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
794 if (!NILP (Fequal (found, XCAR (tem))))
795 count++;
796 if (count > 3)
797 Fsignal (Qerror, Fcons (build_string ("Recursive load"),
798 Fcons (found, Vloads_in_progress)));
799 record_unwind_protect (record_load_unwind, Vloads_in_progress);
800 Vloads_in_progress = Fcons (found, Vloads_in_progress);
803 if (!bcmp (SDATA (found) + SBYTES (found) - 4,
804 ".elc", 4))
805 /* Load .elc files directly, but not when they are
806 remote and have no handler! */
808 if (fd != -2)
810 struct stat s1, s2;
811 int result;
813 if (!safe_to_load_p (fd))
815 safe_p = 0;
816 if (!load_dangerous_libraries)
818 if (fd >= 0)
819 emacs_close (fd);
820 error ("File `%s' was not compiled in Emacs",
821 SDATA (found));
823 else if (!NILP (nomessage))
824 message_with_string ("File `%s' not compiled in Emacs", found, 1);
827 compiled = 1;
829 GCPRO1 (efound);
830 efound = ENCODE_FILE (found);
832 #ifdef DOS_NT
833 fmode = "rb";
834 #endif /* DOS_NT */
835 stat ((char *)SDATA (efound), &s1);
836 SSET (efound, SBYTES (efound) - 1, 0);
837 result = stat ((char *)SDATA (efound), &s2);
838 SSET (efound, SBYTES (efound) - 1, 'c');
839 UNGCPRO;
841 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
843 /* Make the progress messages mention that source is newer. */
844 newer = 1;
846 /* If we won't print another message, mention this anyway. */
847 if (!NILP (nomessage))
849 Lisp_Object file;
850 file = Fsubstring (found, make_number (0), make_number (-1));
851 message_with_string ("Source file `%s' newer than byte-compiled file",
852 file, 1);
857 else
859 /* We are loading a source file (*.el). */
860 if (!NILP (Vload_source_file_function))
862 Lisp_Object val;
864 if (fd >= 0)
865 emacs_close (fd);
866 val = call4 (Vload_source_file_function, found, file,
867 NILP (noerror) ? Qnil : Qt,
868 NILP (nomessage) ? Qnil : Qt);
869 return unbind_to (count, val);
873 #ifdef WINDOWSNT
874 emacs_close (fd);
875 GCPRO1 (efound);
876 efound = ENCODE_FILE (found);
877 stream = fopen ((char *) SDATA (efound), fmode);
878 UNGCPRO;
879 #else /* not WINDOWSNT */
880 stream = fdopen (fd, fmode);
881 #endif /* not WINDOWSNT */
882 if (stream == 0)
884 emacs_close (fd);
885 error ("Failure to create stdio stream for %s", SDATA (file));
888 if (! NILP (Vpurify_flag))
889 Vpreloaded_file_list = Fcons (file, Vpreloaded_file_list);
891 if (NILP (nomessage))
893 if (!safe_p)
894 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
895 file, 1);
896 else if (!compiled)
897 message_with_string ("Loading %s (source)...", file, 1);
898 else if (newer)
899 message_with_string ("Loading %s (compiled; note, source file is newer)...",
900 file, 1);
901 else /* The typical case; compiled file newer than source file. */
902 message_with_string ("Loading %s...", file, 1);
905 GCPRO1 (file);
906 lispstream = Fcons (Qnil, Qnil);
907 XSETCARFASTINT (lispstream, (EMACS_UINT)stream >> 16);
908 XSETCDRFASTINT (lispstream, (EMACS_UINT)stream & 0xffff);
909 record_unwind_protect (load_unwind, lispstream);
910 record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
911 specbind (Qload_file_name, found);
912 specbind (Qinhibit_file_name_operation, Qnil);
913 load_descriptor_list
914 = Fcons (make_number (fileno (stream)), load_descriptor_list);
915 load_in_progress++;
916 readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil);
917 unbind_to (count, Qnil);
919 /* Run any load-hooks for this file. */
920 temp = Fassoc (file, Vafter_load_alist);
921 if (!NILP (temp))
922 Fprogn (Fcdr (temp));
923 UNGCPRO;
925 if (saved_doc_string)
926 free (saved_doc_string);
927 saved_doc_string = 0;
928 saved_doc_string_size = 0;
930 if (prev_saved_doc_string)
931 xfree (prev_saved_doc_string);
932 prev_saved_doc_string = 0;
933 prev_saved_doc_string_size = 0;
935 if (!noninteractive && NILP (nomessage))
937 if (!safe_p)
938 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
939 file, 1);
940 else if (!compiled)
941 message_with_string ("Loading %s (source)...done", file, 1);
942 else if (newer)
943 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
944 file, 1);
945 else /* The typical case; compiled file newer than source file. */
946 message_with_string ("Loading %s...done", file, 1);
949 if (!NILP (Fequal (build_string ("obsolete"),
950 Ffile_name_nondirectory
951 (Fdirectory_file_name (Ffile_name_directory (found))))))
952 message_with_string ("Package %s is obsolete", file, 1);
954 return Qt;
957 static Lisp_Object
958 load_unwind (stream) /* used as unwind-protect function in load */
959 Lisp_Object stream;
961 fclose ((FILE *) (XFASTINT (XCAR (stream)) << 16
962 | XFASTINT (XCDR (stream))));
963 if (--load_in_progress < 0) load_in_progress = 0;
964 return Qnil;
967 static Lisp_Object
968 load_descriptor_unwind (oldlist)
969 Lisp_Object oldlist;
971 load_descriptor_list = oldlist;
972 return Qnil;
975 /* Close all descriptors in use for Floads.
976 This is used when starting a subprocess. */
978 void
979 close_load_descs ()
981 #ifndef WINDOWSNT
982 Lisp_Object tail;
983 for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail))
984 emacs_close (XFASTINT (XCAR (tail)));
985 #endif
988 static int
989 complete_filename_p (pathname)
990 Lisp_Object pathname;
992 register const unsigned char *s = SDATA (pathname);
993 return (IS_DIRECTORY_SEP (s[0])
994 || (SCHARS (pathname) > 2
995 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
996 #ifdef ALTOS
997 || *s == '@'
998 #endif
999 #ifdef VMS
1000 || index (s, ':')
1001 #endif /* VMS */
1005 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
1006 doc: /* Search for FILENAME through PATH.
1007 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1008 file name when searching.
1009 If non-nil, PREDICATE is used instead of `file-readable-p'.
1010 PREDICATE can also be an integer to pass to the access(2) function,
1011 in which case file-name-handlers are ignored. */)
1012 (filename, path, suffixes, predicate)
1013 Lisp_Object filename, path, suffixes, predicate;
1015 Lisp_Object file;
1016 int fd = openp (path, filename, suffixes, &file, predicate);
1017 if (NILP (predicate) && fd > 0)
1018 close (fd);
1019 return file;
1023 /* Search for a file whose name is STR, looking in directories
1024 in the Lisp list PATH, and trying suffixes from SUFFIX.
1025 On success, returns a file descriptor. On failure, returns -1.
1027 SUFFIXES is a list of strings containing possible suffixes.
1028 The empty suffix is automatically added iff the list is empty.
1030 PREDICATE non-nil means don't open the files,
1031 just look for one that satisfies the predicate. In this case,
1032 returns 1 on success. The predicate can be a lisp function or
1033 an integer to pass to `access' (in which case file-name-handlers
1034 are ignored).
1036 If STOREPTR is nonzero, it points to a slot where the name of
1037 the file actually found should be stored as a Lisp string.
1038 nil is stored there on failure.
1040 If the file we find is remote, return -2
1041 but store the found remote file name in *STOREPTR. */
1044 openp (path, str, suffixes, storeptr, predicate)
1045 Lisp_Object path, str;
1046 Lisp_Object suffixes;
1047 Lisp_Object *storeptr;
1048 Lisp_Object predicate;
1050 register int fd;
1051 int fn_size = 100;
1052 char buf[100];
1053 register char *fn = buf;
1054 int absolute = 0;
1055 int want_size;
1056 Lisp_Object filename;
1057 struct stat st;
1058 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1059 Lisp_Object string, tail, encoded_fn;
1060 int max_suffix_len = 0;
1062 CHECK_STRING (str);
1064 for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
1066 CHECK_STRING_CAR (tail);
1067 max_suffix_len = max (max_suffix_len,
1068 SBYTES (XCAR (tail)));
1071 string = filename = Qnil;
1072 GCPRO6 (str, string, filename, path, suffixes, encoded_fn);
1074 if (storeptr)
1075 *storeptr = Qnil;
1077 if (complete_filename_p (str))
1078 absolute = 1;
1080 for (; CONSP (path); path = XCDR (path))
1082 filename = Fexpand_file_name (str, XCAR (path));
1083 if (!complete_filename_p (filename))
1084 /* If there are non-absolute elts in PATH (eg ".") */
1085 /* Of course, this could conceivably lose if luser sets
1086 default-directory to be something non-absolute... */
1088 filename = Fexpand_file_name (filename, current_buffer->directory);
1089 if (!complete_filename_p (filename))
1090 /* Give up on this path element! */
1091 continue;
1094 /* Calculate maximum size of any filename made from
1095 this path element/specified file name and any possible suffix. */
1096 want_size = max_suffix_len + SBYTES (filename) + 1;
1097 if (fn_size < want_size)
1098 fn = (char *) alloca (fn_size = 100 + want_size);
1100 /* Loop over suffixes. */
1101 for (tail = NILP (suffixes) ? default_suffixes : suffixes;
1102 CONSP (tail); tail = XCDR (tail))
1104 int lsuffix = SBYTES (XCAR (tail));
1105 Lisp_Object handler;
1106 int exists;
1108 /* Concatenate path element/specified name with the suffix.
1109 If the directory starts with /:, remove that. */
1110 if (SCHARS (filename) > 2
1111 && SREF (filename, 0) == '/'
1112 && SREF (filename, 1) == ':')
1114 strncpy (fn, SDATA (filename) + 2,
1115 SBYTES (filename) - 2);
1116 fn[SBYTES (filename) - 2] = 0;
1118 else
1120 strncpy (fn, SDATA (filename),
1121 SBYTES (filename));
1122 fn[SBYTES (filename)] = 0;
1125 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1126 strncat (fn, SDATA (XCAR (tail)), lsuffix);
1128 /* Check that the file exists and is not a directory. */
1129 /* We used to only check for handlers on non-absolute file names:
1130 if (absolute)
1131 handler = Qnil;
1132 else
1133 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1134 It's not clear why that was the case and it breaks things like
1135 (load "/bar.el") where the file is actually "/bar.el.gz". */
1136 string = build_string (fn);
1137 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1138 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1140 if (NILP (predicate))
1141 exists = !NILP (Ffile_readable_p (string));
1142 else
1143 exists = !NILP (call1 (predicate, string));
1144 if (exists && !NILP (Ffile_directory_p (string)))
1145 exists = 0;
1147 if (exists)
1149 /* We succeeded; return this descriptor and filename. */
1150 if (storeptr)
1151 *storeptr = string;
1152 UNGCPRO;
1153 return -2;
1156 else
1158 const char *pfn;
1160 encoded_fn = ENCODE_FILE (string);
1161 pfn = SDATA (encoded_fn);
1162 exists = (stat (pfn, &st) >= 0
1163 && (st.st_mode & S_IFMT) != S_IFDIR);
1164 if (exists)
1166 /* Check that we can access or open it. */
1167 if (NATNUMP (predicate))
1168 fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1;
1169 else
1170 fd = emacs_open (pfn, O_RDONLY, 0);
1172 if (fd >= 0)
1174 /* We succeeded; return this descriptor and filename. */
1175 if (storeptr)
1176 *storeptr = string;
1177 UNGCPRO;
1178 return fd;
1183 if (absolute)
1184 break;
1187 UNGCPRO;
1188 return -1;
1192 /* Merge the list we've accumulated of globals from the current input source
1193 into the load_history variable. The details depend on whether
1194 the source has an associated file name or not. */
1196 static void
1197 build_load_history (stream, source)
1198 FILE *stream;
1199 Lisp_Object source;
1201 register Lisp_Object tail, prev, newelt;
1202 register Lisp_Object tem, tem2;
1203 register int foundit, loading;
1205 loading = stream || !NARROWED;
1207 tail = Vload_history;
1208 prev = Qnil;
1209 foundit = 0;
1210 while (CONSP (tail))
1212 tem = XCAR (tail);
1214 /* Find the feature's previous assoc list... */
1215 if (!NILP (Fequal (source, Fcar (tem))))
1217 foundit = 1;
1219 /* If we're loading, remove it. */
1220 if (loading)
1222 if (NILP (prev))
1223 Vload_history = XCDR (tail);
1224 else
1225 Fsetcdr (prev, XCDR (tail));
1228 /* Otherwise, cons on new symbols that are not already members. */
1229 else
1231 tem2 = Vcurrent_load_list;
1233 while (CONSP (tem2))
1235 newelt = XCAR (tem2);
1237 if (NILP (Fmember (newelt, tem)))
1238 Fsetcar (tail, Fcons (XCAR (tem),
1239 Fcons (newelt, XCDR (tem))));
1241 tem2 = XCDR (tem2);
1242 QUIT;
1246 else
1247 prev = tail;
1248 tail = XCDR (tail);
1249 QUIT;
1252 /* If we're loading, cons the new assoc onto the front of load-history,
1253 the most-recently-loaded position. Also do this if we didn't find
1254 an existing member for the current source. */
1255 if (loading || !foundit)
1256 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
1257 Vload_history);
1260 Lisp_Object
1261 unreadpure (junk) /* Used as unwind-protect function in readevalloop */
1262 Lisp_Object junk;
1264 read_pure = 0;
1265 return Qnil;
1268 static Lisp_Object
1269 readevalloop_1 (old)
1270 Lisp_Object old;
1272 load_convert_to_unibyte = ! NILP (old);
1273 return Qnil;
1276 /* Signal an `end-of-file' error, if possible with file name
1277 information. */
1279 static void
1280 end_of_file_error ()
1282 Lisp_Object data;
1284 if (STRINGP (Vload_file_name))
1285 data = Fcons (Vload_file_name, Qnil);
1286 else
1287 data = Qnil;
1289 Fsignal (Qend_of_file, data);
1292 /* UNIBYTE specifies how to set load_convert_to_unibyte
1293 for this invocation.
1294 READFUN, if non-nil, is used instead of `read'. */
1296 static void
1297 readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, readfun)
1298 Lisp_Object readcharfun;
1299 FILE *stream;
1300 Lisp_Object sourcename;
1301 Lisp_Object (*evalfun) ();
1302 int printflag;
1303 Lisp_Object unibyte, readfun;
1305 register int c;
1306 register Lisp_Object val;
1307 int count = SPECPDL_INDEX ();
1308 struct gcpro gcpro1;
1309 struct buffer *b = 0;
1310 int continue_reading_p;
1312 if (BUFFERP (readcharfun))
1313 b = XBUFFER (readcharfun);
1314 else if (MARKERP (readcharfun))
1315 b = XMARKER (readcharfun)->buffer;
1317 specbind (Qstandard_input, readcharfun);
1318 specbind (Qcurrent_load_list, Qnil);
1319 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
1320 load_convert_to_unibyte = !NILP (unibyte);
1322 readchar_backlog = -1;
1324 GCPRO1 (sourcename);
1326 LOADHIST_ATTACH (sourcename);
1328 continue_reading_p = 1;
1329 while (continue_reading_p)
1331 if (b != 0 && NILP (b->name))
1332 error ("Reading from killed buffer");
1334 instream = stream;
1335 c = READCHAR;
1336 if (c == ';')
1338 while ((c = READCHAR) != '\n' && c != -1);
1339 continue;
1341 if (c < 0) break;
1343 /* Ignore whitespace here, so we can detect eof. */
1344 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
1345 continue;
1347 if (!NILP (Vpurify_flag) && c == '(')
1349 int count1 = SPECPDL_INDEX ();
1350 record_unwind_protect (unreadpure, Qnil);
1351 val = read_list (-1, readcharfun);
1352 unbind_to (count1, Qnil);
1354 else
1356 UNREAD (c);
1357 read_objects = Qnil;
1358 if (!NILP (readfun))
1360 val = call1 (readfun, readcharfun);
1362 /* If READCHARFUN has set point to ZV, we should
1363 stop reading, even if the form read sets point
1364 to a different value when evaluated. */
1365 if (BUFFERP (readcharfun))
1367 struct buffer *b = XBUFFER (readcharfun);
1368 if (BUF_PT (b) == BUF_ZV (b))
1369 continue_reading_p = 0;
1372 else if (! NILP (Vload_read_function))
1373 val = call1 (Vload_read_function, readcharfun);
1374 else
1375 val = read_internal_start (readcharfun, Qnil, Qnil);
1378 val = (*evalfun) (val);
1380 if (printflag)
1382 Vvalues = Fcons (val, Vvalues);
1383 if (EQ (Vstandard_output, Qt))
1384 Fprin1 (val, Qnil);
1385 else
1386 Fprint (val, Qnil);
1390 build_load_history (stream, sourcename);
1391 UNGCPRO;
1393 unbind_to (count, Qnil);
1396 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
1397 doc: /* Execute the current buffer as Lisp code.
1398 Programs can pass two arguments, BUFFER and PRINTFLAG.
1399 BUFFER is the buffer to evaluate (nil means use current buffer).
1400 PRINTFLAG controls printing of output:
1401 nil means discard it; anything else is stream for print.
1403 If the optional third argument FILENAME is non-nil,
1404 it specifies the file name to use for `load-history'.
1405 The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'
1406 for this invocation.
1408 The optional fifth argument DO-ALLOW-PRINT, if non-nil, specifies that
1409 `print' and related functions should work normally even if PRINTFLAG is nil.
1411 This function preserves the position of point. */)
1412 (buffer, printflag, filename, unibyte, do_allow_print)
1413 Lisp_Object buffer, printflag, filename, unibyte, do_allow_print;
1415 int count = SPECPDL_INDEX ();
1416 Lisp_Object tem, buf;
1418 if (NILP (buffer))
1419 buf = Fcurrent_buffer ();
1420 else
1421 buf = Fget_buffer (buffer);
1422 if (NILP (buf))
1423 error ("No such buffer");
1425 if (NILP (printflag) && NILP (do_allow_print))
1426 tem = Qsymbolp;
1427 else
1428 tem = printflag;
1430 if (NILP (filename))
1431 filename = XBUFFER (buf)->filename;
1433 specbind (Qstandard_output, tem);
1434 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1435 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
1436 readevalloop (buf, 0, filename, Feval, !NILP (printflag), unibyte, Qnil);
1437 unbind_to (count, Qnil);
1439 return Qnil;
1442 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
1443 doc: /* Execute the region as Lisp code.
1444 When called from programs, expects two arguments,
1445 giving starting and ending indices in the current buffer
1446 of the text to be executed.
1447 Programs can pass third argument PRINTFLAG which controls output:
1448 nil means discard it; anything else is stream for printing it.
1449 Also the fourth argument READ-FUNCTION, if non-nil, is used
1450 instead of `read' to read each expression. It gets one argument
1451 which is the input stream for reading characters.
1453 This function does not move point. */)
1454 (start, end, printflag, read_function)
1455 Lisp_Object start, end, printflag, read_function;
1457 int count = SPECPDL_INDEX ();
1458 Lisp_Object tem, cbuf;
1460 cbuf = Fcurrent_buffer ();
1462 if (NILP (printflag))
1463 tem = Qsymbolp;
1464 else
1465 tem = printflag;
1466 specbind (Qstandard_output, tem);
1468 if (NILP (printflag))
1469 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1470 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1472 /* This both uses start and checks its type. */
1473 Fgoto_char (start);
1474 Fnarrow_to_region (make_number (BEGV), end);
1475 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
1476 !NILP (printflag), Qnil, read_function);
1478 return unbind_to (count, Qnil);
1482 DEFUN ("read", Fread, Sread, 0, 1, 0,
1483 doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1484 If STREAM is nil, use the value of `standard-input' (which see).
1485 STREAM or the value of `standard-input' may be:
1486 a buffer (read from point and advance it)
1487 a marker (read from where it points and advance it)
1488 a function (call it with no arguments for each character,
1489 call it with a char as argument to push a char back)
1490 a string (takes text from string, starting at the beginning)
1491 t (read text line using minibuffer and use it, or read from
1492 standard input in batch mode). */)
1493 (stream)
1494 Lisp_Object stream;
1496 if (NILP (stream))
1497 stream = Vstandard_input;
1498 if (EQ (stream, Qt))
1499 stream = Qread_char;
1500 if (EQ (stream, Qread_char))
1501 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
1503 return read_internal_start (stream, Qnil, Qnil);
1506 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
1507 doc: /* Read one Lisp expression which is represented as text by STRING.
1508 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1509 START and END optionally delimit a substring of STRING from which to read;
1510 they default to 0 and (length STRING) respectively. */)
1511 (string, start, end)
1512 Lisp_Object string, start, end;
1514 Lisp_Object ret;
1515 CHECK_STRING (string);
1516 /* read_internal_start sets read_from_string_index. */
1517 ret = read_internal_start (string, start, end);
1518 return Fcons (ret, make_number (read_from_string_index));
1521 /* Function to set up the global context we need in toplevel read
1522 calls. */
1523 static Lisp_Object
1524 read_internal_start (stream, start, end)
1525 Lisp_Object stream;
1526 Lisp_Object start; /* Only used when stream is a string. */
1527 Lisp_Object end; /* Only used when stream is a string. */
1529 Lisp_Object retval;
1531 readchar_backlog = -1;
1532 readchar_count = 0;
1533 new_backquote_flag = 0;
1534 read_objects = Qnil;
1535 if (EQ (Vread_with_symbol_positions, Qt)
1536 || EQ (Vread_with_symbol_positions, stream))
1537 Vread_symbol_positions_list = Qnil;
1539 if (STRINGP (stream))
1541 int startval, endval;
1542 if (NILP (end))
1543 endval = SCHARS (stream);
1544 else
1546 CHECK_NUMBER (end);
1547 endval = XINT (end);
1548 if (endval < 0 || endval > SCHARS (stream))
1549 args_out_of_range (stream, end);
1552 if (NILP (start))
1553 startval = 0;
1554 else
1556 CHECK_NUMBER (start);
1557 startval = XINT (start);
1558 if (startval < 0 || startval > endval)
1559 args_out_of_range (stream, start);
1561 read_from_string_index = startval;
1562 read_from_string_index_byte = string_char_to_byte (stream, startval);
1563 read_from_string_limit = endval;
1566 retval = read0 (stream);
1567 if (EQ (Vread_with_symbol_positions, Qt)
1568 || EQ (Vread_with_symbol_positions, stream))
1569 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list);
1570 return retval;
1573 /* Use this for recursive reads, in contexts where internal tokens
1574 are not allowed. */
1576 static Lisp_Object
1577 read0 (readcharfun)
1578 Lisp_Object readcharfun;
1580 register Lisp_Object val;
1581 int c;
1583 val = read1 (readcharfun, &c, 0);
1584 if (c)
1585 Fsignal (Qinvalid_read_syntax, Fcons (Fmake_string (make_number (1),
1586 make_number (c)),
1587 Qnil));
1589 return val;
1592 static int read_buffer_size;
1593 static char *read_buffer;
1595 /* Read multibyte form and return it as a character. C is a first
1596 byte of multibyte form, and rest of them are read from
1597 READCHARFUN. */
1599 static int
1600 read_multibyte (c, readcharfun)
1601 register int c;
1602 Lisp_Object readcharfun;
1604 /* We need the actual character code of this multibyte
1605 characters. */
1606 unsigned char str[MAX_MULTIBYTE_LENGTH];
1607 int len = 0;
1608 int bytes;
1610 if (c < 0)
1611 return c;
1613 str[len++] = c;
1614 while ((c = READCHAR) >= 0xA0
1615 && len < MAX_MULTIBYTE_LENGTH)
1617 str[len++] = c;
1618 readchar_count--;
1620 UNREAD (c);
1621 if (UNIBYTE_STR_AS_MULTIBYTE_P (str, len, bytes))
1622 return STRING_CHAR (str, len);
1623 /* The byte sequence is not valid as multibyte. Unread all bytes
1624 but the first one, and return the first byte. */
1625 while (--len > 0)
1626 UNREAD (str[len]);
1627 return str[0];
1630 /* Read a \-escape sequence, assuming we already read the `\'.
1631 If the escape sequence forces unibyte, store 1 into *BYTEREP.
1632 If the escape sequence forces multibyte, store 2 into *BYTEREP.
1633 Otherwise store 0 into *BYTEREP. */
1635 static int
1636 read_escape (readcharfun, stringp, byterep)
1637 Lisp_Object readcharfun;
1638 int stringp;
1639 int *byterep;
1641 register int c = READCHAR;
1643 *byterep = 0;
1645 switch (c)
1647 case -1:
1648 end_of_file_error ();
1650 case 'a':
1651 return '\007';
1652 case 'b':
1653 return '\b';
1654 case 'd':
1655 return 0177;
1656 case 'e':
1657 return 033;
1658 case 'f':
1659 return '\f';
1660 case 'n':
1661 return '\n';
1662 case 'r':
1663 return '\r';
1664 case 't':
1665 return '\t';
1666 case 'v':
1667 return '\v';
1668 case '\n':
1669 return -1;
1670 case ' ':
1671 if (stringp)
1672 return -1;
1673 return ' ';
1675 case 'M':
1676 c = READCHAR;
1677 if (c != '-')
1678 error ("Invalid escape character syntax");
1679 c = READCHAR;
1680 if (c == '\\')
1681 c = read_escape (readcharfun, 0, byterep);
1682 return c | meta_modifier;
1684 case 'S':
1685 c = READCHAR;
1686 if (c != '-')
1687 error ("Invalid escape character syntax");
1688 c = READCHAR;
1689 if (c == '\\')
1690 c = read_escape (readcharfun, 0, byterep);
1691 return c | shift_modifier;
1693 case 'H':
1694 c = READCHAR;
1695 if (c != '-')
1696 error ("Invalid escape character syntax");
1697 c = READCHAR;
1698 if (c == '\\')
1699 c = read_escape (readcharfun, 0, byterep);
1700 return c | hyper_modifier;
1702 case 'A':
1703 c = READCHAR;
1704 if (c != '-')
1705 error ("Invalid escape character syntax");
1706 c = READCHAR;
1707 if (c == '\\')
1708 c = read_escape (readcharfun, 0, byterep);
1709 return c | alt_modifier;
1711 case 's':
1712 if (stringp)
1713 return ' ';
1714 c = READCHAR;
1715 if (c != '-') {
1716 UNREAD (c);
1717 return ' ';
1719 c = READCHAR;
1720 if (c == '\\')
1721 c = read_escape (readcharfun, 0, byterep);
1722 return c | super_modifier;
1724 case 'C':
1725 c = READCHAR;
1726 if (c != '-')
1727 error ("Invalid escape character syntax");
1728 case '^':
1729 c = READCHAR;
1730 if (c == '\\')
1731 c = read_escape (readcharfun, 0, byterep);
1732 if ((c & ~CHAR_MODIFIER_MASK) == '?')
1733 return 0177 | (c & CHAR_MODIFIER_MASK);
1734 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
1735 return c | ctrl_modifier;
1736 /* ASCII control chars are made from letters (both cases),
1737 as well as the non-letters within 0100...0137. */
1738 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
1739 return (c & (037 | ~0177));
1740 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
1741 return (c & (037 | ~0177));
1742 else
1743 return c | ctrl_modifier;
1745 case '0':
1746 case '1':
1747 case '2':
1748 case '3':
1749 case '4':
1750 case '5':
1751 case '6':
1752 case '7':
1753 /* An octal escape, as in ANSI C. */
1755 register int i = c - '0';
1756 register int count = 0;
1757 while (++count < 3)
1759 if ((c = READCHAR) >= '0' && c <= '7')
1761 i *= 8;
1762 i += c - '0';
1764 else
1766 UNREAD (c);
1767 break;
1771 *byterep = 1;
1772 return i;
1775 case 'x':
1776 /* A hex escape, as in ANSI C. */
1778 int i = 0;
1779 while (1)
1781 c = READCHAR;
1782 if (c >= '0' && c <= '9')
1784 i *= 16;
1785 i += c - '0';
1787 else if ((c >= 'a' && c <= 'f')
1788 || (c >= 'A' && c <= 'F'))
1790 i *= 16;
1791 if (c >= 'a' && c <= 'f')
1792 i += c - 'a' + 10;
1793 else
1794 i += c - 'A' + 10;
1796 else
1798 UNREAD (c);
1799 break;
1803 *byterep = 2;
1804 return i;
1807 default:
1808 if (BASE_LEADING_CODE_P (c))
1809 c = read_multibyte (c, readcharfun);
1810 return c;
1815 /* Read an integer in radix RADIX using READCHARFUN to read
1816 characters. RADIX must be in the interval [2..36]; if it isn't, a
1817 read error is signaled . Value is the integer read. Signals an
1818 error if encountering invalid read syntax or if RADIX is out of
1819 range. */
1821 static Lisp_Object
1822 read_integer (readcharfun, radix)
1823 Lisp_Object readcharfun;
1824 int radix;
1826 int ndigits = 0, invalid_p, c, sign = 0;
1827 EMACS_INT number = 0;
1829 if (radix < 2 || radix > 36)
1830 invalid_p = 1;
1831 else
1833 number = ndigits = invalid_p = 0;
1834 sign = 1;
1836 c = READCHAR;
1837 if (c == '-')
1839 c = READCHAR;
1840 sign = -1;
1842 else if (c == '+')
1843 c = READCHAR;
1845 while (c >= 0)
1847 int digit;
1849 if (c >= '0' && c <= '9')
1850 digit = c - '0';
1851 else if (c >= 'a' && c <= 'z')
1852 digit = c - 'a' + 10;
1853 else if (c >= 'A' && c <= 'Z')
1854 digit = c - 'A' + 10;
1855 else
1857 UNREAD (c);
1858 break;
1861 if (digit < 0 || digit >= radix)
1862 invalid_p = 1;
1864 number = radix * number + digit;
1865 ++ndigits;
1866 c = READCHAR;
1870 if (ndigits == 0 || invalid_p)
1872 char buf[50];
1873 sprintf (buf, "integer, radix %d", radix);
1874 Fsignal (Qinvalid_read_syntax, Fcons (build_string (buf), Qnil));
1877 return make_number (sign * number);
1881 /* Convert unibyte text in read_buffer to multibyte.
1883 Initially, *P is a pointer after the end of the unibyte text, and
1884 the pointer *END points after the end of read_buffer.
1886 If read_buffer doesn't have enough room to hold the result
1887 of the conversion, reallocate it and adjust *P and *END.
1889 At the end, make *P point after the result of the conversion, and
1890 return in *NCHARS the number of characters in the converted
1891 text. */
1893 static void
1894 to_multibyte (p, end, nchars)
1895 char **p, **end;
1896 int *nchars;
1898 int nbytes;
1900 parse_str_as_multibyte (read_buffer, *p - read_buffer, &nbytes, nchars);
1901 if (read_buffer_size < 2 * nbytes)
1903 int offset = *p - read_buffer;
1904 read_buffer_size = 2 * max (read_buffer_size, nbytes);
1905 read_buffer = (char *) xrealloc (read_buffer, read_buffer_size);
1906 *p = read_buffer + offset;
1907 *end = read_buffer + read_buffer_size;
1910 if (nbytes != *nchars)
1911 nbytes = str_as_multibyte (read_buffer, read_buffer_size,
1912 *p - read_buffer, nchars);
1914 *p = read_buffer + nbytes;
1918 /* If the next token is ')' or ']' or '.', we store that character
1919 in *PCH and the return value is not interesting. Else, we store
1920 zero in *PCH and we read and return one lisp object.
1922 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1924 static Lisp_Object
1925 read1 (readcharfun, pch, first_in_list)
1926 register Lisp_Object readcharfun;
1927 int *pch;
1928 int first_in_list;
1930 register int c;
1931 int uninterned_symbol = 0;
1933 *pch = 0;
1935 retry:
1937 c = READCHAR;
1938 if (c < 0)
1939 end_of_file_error ();
1941 switch (c)
1943 case '(':
1944 return read_list (0, readcharfun);
1946 case '[':
1947 return read_vector (readcharfun, 0);
1949 case ')':
1950 case ']':
1952 *pch = c;
1953 return Qnil;
1956 case '#':
1957 c = READCHAR;
1958 if (c == '^')
1960 c = READCHAR;
1961 if (c == '[')
1963 Lisp_Object tmp;
1964 tmp = read_vector (readcharfun, 0);
1965 if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS
1966 || XVECTOR (tmp)->size > CHAR_TABLE_STANDARD_SLOTS + 10)
1967 error ("Invalid size char-table");
1968 XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp));
1969 XCHAR_TABLE (tmp)->top = Qt;
1970 return tmp;
1972 else if (c == '^')
1974 c = READCHAR;
1975 if (c == '[')
1977 Lisp_Object tmp;
1978 tmp = read_vector (readcharfun, 0);
1979 if (XVECTOR (tmp)->size != SUB_CHAR_TABLE_STANDARD_SLOTS)
1980 error ("Invalid size char-table");
1981 XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp));
1982 XCHAR_TABLE (tmp)->top = Qnil;
1983 return tmp;
1985 Fsignal (Qinvalid_read_syntax,
1986 Fcons (make_string ("#^^", 3), Qnil));
1988 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#^", 2), Qnil));
1990 if (c == '&')
1992 Lisp_Object length;
1993 length = read1 (readcharfun, pch, first_in_list);
1994 c = READCHAR;
1995 if (c == '"')
1997 Lisp_Object tmp, val;
1998 int size_in_chars
1999 = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2000 / BOOL_VECTOR_BITS_PER_CHAR);
2002 UNREAD (c);
2003 tmp = read1 (readcharfun, pch, first_in_list);
2004 if (size_in_chars != SCHARS (tmp)
2005 /* We used to print 1 char too many
2006 when the number of bits was a multiple of 8.
2007 Accept such input in case it came from an old version. */
2008 && ! (XFASTINT (length)
2009 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR))
2010 Fsignal (Qinvalid_read_syntax,
2011 Fcons (make_string ("#&...", 5), Qnil));
2013 val = Fmake_bool_vector (length, Qnil);
2014 bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data,
2015 size_in_chars);
2016 /* Clear the extraneous bits in the last byte. */
2017 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
2018 XBOOL_VECTOR (val)->data[size_in_chars - 1]
2019 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2020 return val;
2022 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#&...", 5),
2023 Qnil));
2025 if (c == '[')
2027 /* Accept compiled functions at read-time so that we don't have to
2028 build them using function calls. */
2029 Lisp_Object tmp;
2030 tmp = read_vector (readcharfun, 1);
2031 return Fmake_byte_code (XVECTOR (tmp)->size,
2032 XVECTOR (tmp)->contents);
2034 if (c == '(')
2036 Lisp_Object tmp;
2037 struct gcpro gcpro1;
2038 int ch;
2040 /* Read the string itself. */
2041 tmp = read1 (readcharfun, &ch, 0);
2042 if (ch != 0 || !STRINGP (tmp))
2043 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
2044 GCPRO1 (tmp);
2045 /* Read the intervals and their properties. */
2046 while (1)
2048 Lisp_Object beg, end, plist;
2050 beg = read1 (readcharfun, &ch, 0);
2051 end = plist = Qnil;
2052 if (ch == ')')
2053 break;
2054 if (ch == 0)
2055 end = read1 (readcharfun, &ch, 0);
2056 if (ch == 0)
2057 plist = read1 (readcharfun, &ch, 0);
2058 if (ch)
2059 Fsignal (Qinvalid_read_syntax,
2060 Fcons (build_string ("invalid string property list"),
2061 Qnil));
2062 Fset_text_properties (beg, end, plist, tmp);
2064 UNGCPRO;
2065 return tmp;
2068 /* #@NUMBER is used to skip NUMBER following characters.
2069 That's used in .elc files to skip over doc strings
2070 and function definitions. */
2071 if (c == '@')
2073 int i, nskip = 0;
2075 /* Read a decimal integer. */
2076 while ((c = READCHAR) >= 0
2077 && c >= '0' && c <= '9')
2079 nskip *= 10;
2080 nskip += c - '0';
2082 if (c >= 0)
2083 UNREAD (c);
2085 if (load_force_doc_strings && EQ (readcharfun, Qget_file_char))
2087 /* If we are supposed to force doc strings into core right now,
2088 record the last string that we skipped,
2089 and record where in the file it comes from. */
2091 /* But first exchange saved_doc_string
2092 with prev_saved_doc_string, so we save two strings. */
2094 char *temp = saved_doc_string;
2095 int temp_size = saved_doc_string_size;
2096 file_offset temp_pos = saved_doc_string_position;
2097 int temp_len = saved_doc_string_length;
2099 saved_doc_string = prev_saved_doc_string;
2100 saved_doc_string_size = prev_saved_doc_string_size;
2101 saved_doc_string_position = prev_saved_doc_string_position;
2102 saved_doc_string_length = prev_saved_doc_string_length;
2104 prev_saved_doc_string = temp;
2105 prev_saved_doc_string_size = temp_size;
2106 prev_saved_doc_string_position = temp_pos;
2107 prev_saved_doc_string_length = temp_len;
2110 if (saved_doc_string_size == 0)
2112 saved_doc_string_size = nskip + 100;
2113 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
2115 if (nskip > saved_doc_string_size)
2117 saved_doc_string_size = nskip + 100;
2118 saved_doc_string = (char *) xrealloc (saved_doc_string,
2119 saved_doc_string_size);
2122 saved_doc_string_position = file_tell (instream);
2124 /* Copy that many characters into saved_doc_string. */
2125 for (i = 0; i < nskip && c >= 0; i++)
2126 saved_doc_string[i] = c = READCHAR;
2128 saved_doc_string_length = i;
2130 else
2132 /* Skip that many characters. */
2133 for (i = 0; i < nskip && c >= 0; i++)
2134 c = READCHAR;
2137 goto retry;
2139 if (c == '!')
2141 /* #! appears at the beginning of an executable file.
2142 Skip the first line. */
2143 while (c != '\n' && c >= 0)
2144 c = READCHAR;
2145 goto retry;
2147 if (c == '$')
2148 return Vload_file_name;
2149 if (c == '\'')
2150 return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
2151 /* #:foo is the uninterned symbol named foo. */
2152 if (c == ':')
2154 uninterned_symbol = 1;
2155 c = READCHAR;
2156 goto default_label;
2158 /* Reader forms that can reuse previously read objects. */
2159 if (c >= '0' && c <= '9')
2161 int n = 0;
2162 Lisp_Object tem;
2164 /* Read a non-negative integer. */
2165 while (c >= '0' && c <= '9')
2167 n *= 10;
2168 n += c - '0';
2169 c = READCHAR;
2171 /* #n=object returns object, but associates it with n for #n#. */
2172 if (c == '=')
2174 /* Make a placeholder for #n# to use temporarily */
2175 Lisp_Object placeholder;
2176 Lisp_Object cell;
2178 placeholder = Fcons(Qnil, Qnil);
2179 cell = Fcons (make_number (n), placeholder);
2180 read_objects = Fcons (cell, read_objects);
2182 /* Read the object itself. */
2183 tem = read0 (readcharfun);
2185 /* Now put it everywhere the placeholder was... */
2186 substitute_object_in_subtree (tem, placeholder);
2188 /* ...and #n# will use the real value from now on. */
2189 Fsetcdr (cell, tem);
2191 return tem;
2193 /* #n# returns a previously read object. */
2194 if (c == '#')
2196 tem = Fassq (make_number (n), read_objects);
2197 if (CONSP (tem))
2198 return XCDR (tem);
2199 /* Fall through to error message. */
2201 else if (c == 'r' || c == 'R')
2202 return read_integer (readcharfun, n);
2204 /* Fall through to error message. */
2206 else if (c == 'x' || c == 'X')
2207 return read_integer (readcharfun, 16);
2208 else if (c == 'o' || c == 'O')
2209 return read_integer (readcharfun, 8);
2210 else if (c == 'b' || c == 'B')
2211 return read_integer (readcharfun, 2);
2213 UNREAD (c);
2214 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
2216 case ';':
2217 while ((c = READCHAR) >= 0 && c != '\n');
2218 goto retry;
2220 case '\'':
2222 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
2225 case '`':
2226 if (first_in_list)
2227 goto default_label;
2228 else
2230 Lisp_Object value;
2232 new_backquote_flag++;
2233 value = read0 (readcharfun);
2234 new_backquote_flag--;
2236 return Fcons (Qbackquote, Fcons (value, Qnil));
2239 case ',':
2240 if (new_backquote_flag)
2242 Lisp_Object comma_type = Qnil;
2243 Lisp_Object value;
2244 int ch = READCHAR;
2246 if (ch == '@')
2247 comma_type = Qcomma_at;
2248 else if (ch == '.')
2249 comma_type = Qcomma_dot;
2250 else
2252 if (ch >= 0) UNREAD (ch);
2253 comma_type = Qcomma;
2256 new_backquote_flag--;
2257 value = read0 (readcharfun);
2258 new_backquote_flag++;
2259 return Fcons (comma_type, Fcons (value, Qnil));
2261 else
2262 goto default_label;
2264 case '?':
2266 int discard;
2267 int next_char;
2268 int ok;
2270 c = READCHAR;
2271 if (c < 0)
2272 end_of_file_error ();
2274 /* Accept `single space' syntax like (list ? x) where the
2275 whitespace character is SPC or TAB.
2276 Other literal whitespace like NL, CR, and FF are not accepted,
2277 as there are well-established escape sequences for these. */
2278 if (c == ' ' || c == '\t')
2279 return make_number (c);
2281 if (c == '\\')
2282 c = read_escape (readcharfun, 0, &discard);
2283 else if (BASE_LEADING_CODE_P (c))
2284 c = read_multibyte (c, readcharfun);
2286 next_char = READCHAR;
2287 if (next_char == '.')
2289 /* Only a dotted-pair dot is valid after a char constant. */
2290 int next_next_char = READCHAR;
2291 UNREAD (next_next_char);
2293 ok = (next_next_char <= 040
2294 || (next_next_char < 0200
2295 && (index ("\"';([#?", next_next_char)
2296 || (!first_in_list && next_next_char == '`')
2297 || (new_backquote_flag && next_next_char == ','))));
2299 else
2301 ok = (next_char <= 040
2302 || (next_char < 0200
2303 && (index ("\"';()[]#?", next_char)
2304 || (!first_in_list && next_char == '`')
2305 || (new_backquote_flag && next_char == ','))));
2307 UNREAD (next_char);
2308 if (!ok)
2309 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("?", 1), Qnil));
2311 return make_number (c);
2314 case '"':
2316 char *p = read_buffer;
2317 char *end = read_buffer + read_buffer_size;
2318 register int c;
2319 /* 1 if we saw an escape sequence specifying
2320 a multibyte character, or a multibyte character. */
2321 int force_multibyte = 0;
2322 /* 1 if we saw an escape sequence specifying
2323 a single-byte character. */
2324 int force_singlebyte = 0;
2325 /* 1 if read_buffer contains multibyte text now. */
2326 int is_multibyte = 0;
2327 int cancel = 0;
2328 int nchars = 0;
2330 while ((c = READCHAR) >= 0
2331 && c != '\"')
2333 if (end - p < MAX_MULTIBYTE_LENGTH)
2335 int offset = p - read_buffer;
2336 read_buffer = (char *) xrealloc (read_buffer,
2337 read_buffer_size *= 2);
2338 p = read_buffer + offset;
2339 end = read_buffer + read_buffer_size;
2342 if (c == '\\')
2344 int byterep;
2346 c = read_escape (readcharfun, 1, &byterep);
2348 /* C is -1 if \ newline has just been seen */
2349 if (c == -1)
2351 if (p == read_buffer)
2352 cancel = 1;
2353 continue;
2356 if (byterep == 1)
2357 force_singlebyte = 1;
2358 else if (byterep == 2)
2359 force_multibyte = 1;
2362 /* A character that must be multibyte forces multibyte. */
2363 if (! SINGLE_BYTE_CHAR_P (c & ~CHAR_MODIFIER_MASK))
2364 force_multibyte = 1;
2366 /* If we just discovered the need to be multibyte,
2367 convert the text accumulated thus far. */
2368 if (force_multibyte && ! is_multibyte)
2370 is_multibyte = 1;
2371 to_multibyte (&p, &end, &nchars);
2374 /* Allow `\C- ' and `\C-?'. */
2375 if (c == (CHAR_CTL | ' '))
2376 c = 0;
2377 else if (c == (CHAR_CTL | '?'))
2378 c = 127;
2380 if (c & CHAR_SHIFT)
2382 /* Shift modifier is valid only with [A-Za-z]. */
2383 if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
2384 c &= ~CHAR_SHIFT;
2385 else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
2386 c = (c & ~CHAR_SHIFT) - ('a' - 'A');
2389 if (c & CHAR_META)
2390 /* Move the meta bit to the right place for a string. */
2391 c = (c & ~CHAR_META) | 0x80;
2392 if (c & CHAR_MODIFIER_MASK)
2393 error ("Invalid modifier in string");
2395 if (is_multibyte)
2396 p += CHAR_STRING (c, p);
2397 else
2398 *p++ = c;
2400 nchars++;
2403 if (c < 0)
2404 end_of_file_error ();
2406 /* If purifying, and string starts with \ newline,
2407 return zero instead. This is for doc strings
2408 that we are really going to find in etc/DOC.nn.nn */
2409 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
2410 return make_number (0);
2412 if (is_multibyte || force_singlebyte)
2414 else if (load_convert_to_unibyte)
2416 Lisp_Object string;
2417 to_multibyte (&p, &end, &nchars);
2418 if (p - read_buffer != nchars)
2420 string = make_multibyte_string (read_buffer, nchars,
2421 p - read_buffer);
2422 return Fstring_make_unibyte (string);
2424 /* We can make a unibyte string directly. */
2425 is_multibyte = 0;
2427 else if (EQ (readcharfun, Qget_file_char)
2428 || EQ (readcharfun, Qlambda))
2430 /* Nowadays, reading directly from a file is used only for
2431 compiled Emacs Lisp files, and those always use the
2432 Emacs internal encoding. Meanwhile, Qlambda is used
2433 for reading dynamic byte code (compiled with
2434 byte-compile-dynamic = t). So make the string multibyte
2435 if the string contains any multibyte sequences.
2436 (to_multibyte is a no-op if not.) */
2437 to_multibyte (&p, &end, &nchars);
2438 is_multibyte = (p - read_buffer) != nchars;
2440 else
2441 /* In all other cases, if we read these bytes as
2442 separate characters, treat them as separate characters now. */
2445 /* We want readchar_count to be the number of characters, not
2446 bytes. Hence we adjust for multibyte characters in the
2447 string. ... But it doesn't seem to be necessary, because
2448 READCHAR *does* read multibyte characters from buffers. */
2449 /* readchar_count -= (p - read_buffer) - nchars; */
2450 if (read_pure)
2451 return make_pure_string (read_buffer, nchars, p - read_buffer,
2452 is_multibyte);
2453 return make_specified_string (read_buffer, nchars, p - read_buffer,
2454 is_multibyte);
2457 case '.':
2459 int next_char = READCHAR;
2460 UNREAD (next_char);
2462 if (next_char <= 040
2463 || (next_char < 0200
2464 && (index ("\"';([#?", next_char)
2465 || (!first_in_list && next_char == '`')
2466 || (new_backquote_flag && next_char == ','))))
2468 *pch = c;
2469 return Qnil;
2472 /* Otherwise, we fall through! Note that the atom-reading loop
2473 below will now loop at least once, assuring that we will not
2474 try to UNREAD two characters in a row. */
2476 default:
2477 default_label:
2478 if (c <= 040) goto retry;
2480 char *p = read_buffer;
2481 int quoted = 0;
2484 char *end = read_buffer + read_buffer_size;
2486 while (c > 040
2487 && (c >= 0200
2488 || (!index ("\"';()[]#", c)
2489 && !(!first_in_list && c == '`')
2490 && !(new_backquote_flag && c == ','))))
2492 if (end - p < MAX_MULTIBYTE_LENGTH)
2494 int offset = p - read_buffer;
2495 read_buffer = (char *) xrealloc (read_buffer,
2496 read_buffer_size *= 2);
2497 p = read_buffer + offset;
2498 end = read_buffer + read_buffer_size;
2501 if (c == '\\')
2503 c = READCHAR;
2504 if (c == -1)
2505 end_of_file_error ();
2506 quoted = 1;
2509 if (! SINGLE_BYTE_CHAR_P (c))
2510 p += CHAR_STRING (c, p);
2511 else
2512 *p++ = c;
2514 c = READCHAR;
2517 if (p == end)
2519 int offset = p - read_buffer;
2520 read_buffer = (char *) xrealloc (read_buffer,
2521 read_buffer_size *= 2);
2522 p = read_buffer + offset;
2523 end = read_buffer + read_buffer_size;
2525 *p = 0;
2526 if (c >= 0)
2527 UNREAD (c);
2530 if (!quoted && !uninterned_symbol)
2532 register char *p1;
2533 register Lisp_Object val;
2534 p1 = read_buffer;
2535 if (*p1 == '+' || *p1 == '-') p1++;
2536 /* Is it an integer? */
2537 if (p1 != p)
2539 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
2540 /* Integers can have trailing decimal points. */
2541 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
2542 if (p1 == p)
2543 /* It is an integer. */
2545 if (p1[-1] == '.')
2546 p1[-1] = '\0';
2547 if (sizeof (int) == sizeof (EMACS_INT))
2548 XSETINT (val, atoi (read_buffer));
2549 else if (sizeof (long) == sizeof (EMACS_INT))
2550 XSETINT (val, atol (read_buffer));
2551 else
2552 abort ();
2553 return val;
2556 if (isfloat_string (read_buffer))
2558 /* Compute NaN and infinities using 0.0 in a variable,
2559 to cope with compilers that think they are smarter
2560 than we are. */
2561 double zero = 0.0;
2563 double value;
2565 /* Negate the value ourselves. This treats 0, NaNs,
2566 and infinity properly on IEEE floating point hosts,
2567 and works around a common bug where atof ("-0.0")
2568 drops the sign. */
2569 int negative = read_buffer[0] == '-';
2571 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2572 returns 1, is if the input ends in e+INF or e+NaN. */
2573 switch (p[-1])
2575 case 'F':
2576 value = 1.0 / zero;
2577 break;
2578 case 'N':
2579 value = zero / zero;
2580 break;
2581 default:
2582 value = atof (read_buffer + negative);
2583 break;
2586 return make_float (negative ? - value : value);
2590 Lisp_Object result = uninterned_symbol ? make_symbol (read_buffer)
2591 : intern (read_buffer);
2592 if (EQ (Vread_with_symbol_positions, Qt)
2593 || EQ (Vread_with_symbol_positions, readcharfun))
2594 Vread_symbol_positions_list =
2595 /* Kind of a hack; this will probably fail if characters
2596 in the symbol name were escaped. Not really a big
2597 deal, though. */
2598 Fcons (Fcons (result,
2599 make_number (readchar_count
2600 - XFASTINT (Flength (Fsymbol_name (result))))),
2601 Vread_symbol_positions_list);
2602 return result;
2609 /* List of nodes we've seen during substitute_object_in_subtree. */
2610 static Lisp_Object seen_list;
2612 static void
2613 substitute_object_in_subtree (object, placeholder)
2614 Lisp_Object object;
2615 Lisp_Object placeholder;
2617 Lisp_Object check_object;
2619 /* We haven't seen any objects when we start. */
2620 seen_list = Qnil;
2622 /* Make all the substitutions. */
2623 check_object
2624 = substitute_object_recurse (object, placeholder, object);
2626 /* Clear seen_list because we're done with it. */
2627 seen_list = Qnil;
2629 /* The returned object here is expected to always eq the
2630 original. */
2631 if (!EQ (check_object, object))
2632 error ("Unexpected mutation error in reader");
2635 /* Feval doesn't get called from here, so no gc protection is needed. */
2636 #define SUBSTITUTE(get_val, set_val) \
2638 Lisp_Object old_value = get_val; \
2639 Lisp_Object true_value \
2640 = substitute_object_recurse (object, placeholder,\
2641 old_value); \
2643 if (!EQ (old_value, true_value)) \
2645 set_val; \
2649 static Lisp_Object
2650 substitute_object_recurse (object, placeholder, subtree)
2651 Lisp_Object object;
2652 Lisp_Object placeholder;
2653 Lisp_Object subtree;
2655 /* If we find the placeholder, return the target object. */
2656 if (EQ (placeholder, subtree))
2657 return object;
2659 /* If we've been to this node before, don't explore it again. */
2660 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
2661 return subtree;
2663 /* If this node can be the entry point to a cycle, remember that
2664 we've seen it. It can only be such an entry point if it was made
2665 by #n=, which means that we can find it as a value in
2666 read_objects. */
2667 if (!EQ (Qnil, Frassq (subtree, read_objects)))
2668 seen_list = Fcons (subtree, seen_list);
2670 /* Recurse according to subtree's type.
2671 Every branch must return a Lisp_Object. */
2672 switch (XTYPE (subtree))
2674 case Lisp_Vectorlike:
2676 int i;
2677 int length = XINT (Flength(subtree));
2678 for (i = 0; i < length; i++)
2680 Lisp_Object idx = make_number (i);
2681 SUBSTITUTE (Faref (subtree, idx),
2682 Faset (subtree, idx, true_value));
2684 return subtree;
2687 case Lisp_Cons:
2689 SUBSTITUTE (Fcar_safe (subtree),
2690 Fsetcar (subtree, true_value));
2691 SUBSTITUTE (Fcdr_safe (subtree),
2692 Fsetcdr (subtree, true_value));
2693 return subtree;
2696 case Lisp_String:
2698 /* Check for text properties in each interval.
2699 substitute_in_interval contains part of the logic. */
2701 INTERVAL root_interval = STRING_INTERVALS (subtree);
2702 Lisp_Object arg = Fcons (object, placeholder);
2704 traverse_intervals_noorder (root_interval,
2705 &substitute_in_interval, arg);
2707 return subtree;
2710 /* Other types don't recurse any further. */
2711 default:
2712 return subtree;
2716 /* Helper function for substitute_object_recurse. */
2717 static void
2718 substitute_in_interval (interval, arg)
2719 INTERVAL interval;
2720 Lisp_Object arg;
2722 Lisp_Object object = Fcar (arg);
2723 Lisp_Object placeholder = Fcdr (arg);
2725 SUBSTITUTE(interval->plist, interval->plist = true_value);
2729 #define LEAD_INT 1
2730 #define DOT_CHAR 2
2731 #define TRAIL_INT 4
2732 #define E_CHAR 8
2733 #define EXP_INT 16
2736 isfloat_string (cp)
2737 register char *cp;
2739 register int state;
2741 char *start = cp;
2743 state = 0;
2744 if (*cp == '+' || *cp == '-')
2745 cp++;
2747 if (*cp >= '0' && *cp <= '9')
2749 state |= LEAD_INT;
2750 while (*cp >= '0' && *cp <= '9')
2751 cp++;
2753 if (*cp == '.')
2755 state |= DOT_CHAR;
2756 cp++;
2758 if (*cp >= '0' && *cp <= '9')
2760 state |= TRAIL_INT;
2761 while (*cp >= '0' && *cp <= '9')
2762 cp++;
2764 if (*cp == 'e' || *cp == 'E')
2766 state |= E_CHAR;
2767 cp++;
2768 if (*cp == '+' || *cp == '-')
2769 cp++;
2772 if (*cp >= '0' && *cp <= '9')
2774 state |= EXP_INT;
2775 while (*cp >= '0' && *cp <= '9')
2776 cp++;
2778 else if (cp == start)
2780 else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
2782 state |= EXP_INT;
2783 cp += 3;
2785 else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
2787 state |= EXP_INT;
2788 cp += 3;
2791 return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
2792 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
2793 || state == (DOT_CHAR|TRAIL_INT)
2794 || state == (LEAD_INT|E_CHAR|EXP_INT)
2795 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
2796 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
2800 static Lisp_Object
2801 read_vector (readcharfun, bytecodeflag)
2802 Lisp_Object readcharfun;
2803 int bytecodeflag;
2805 register int i;
2806 register int size;
2807 register Lisp_Object *ptr;
2808 register Lisp_Object tem, item, vector;
2809 register struct Lisp_Cons *otem;
2810 Lisp_Object len;
2812 tem = read_list (1, readcharfun);
2813 len = Flength (tem);
2814 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
2816 size = XVECTOR (vector)->size;
2817 ptr = XVECTOR (vector)->contents;
2818 for (i = 0; i < size; i++)
2820 item = Fcar (tem);
2821 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2822 bytecode object, the docstring containing the bytecode and
2823 constants values must be treated as unibyte and passed to
2824 Fread, to get the actual bytecode string and constants vector. */
2825 if (bytecodeflag && load_force_doc_strings)
2827 if (i == COMPILED_BYTECODE)
2829 if (!STRINGP (item))
2830 error ("invalid byte code");
2832 /* Delay handling the bytecode slot until we know whether
2833 it is lazily-loaded (we can tell by whether the
2834 constants slot is nil). */
2835 ptr[COMPILED_CONSTANTS] = item;
2836 item = Qnil;
2838 else if (i == COMPILED_CONSTANTS)
2840 Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
2842 if (NILP (item))
2844 /* Coerce string to unibyte (like string-as-unibyte,
2845 but without generating extra garbage and
2846 guaranteeing no change in the contents). */
2847 STRING_SET_CHARS (bytestr, SBYTES (bytestr));
2848 STRING_SET_UNIBYTE (bytestr);
2850 item = Fread (bytestr);
2851 if (!CONSP (item))
2852 error ("invalid byte code");
2854 otem = XCONS (item);
2855 bytestr = XCAR (item);
2856 item = XCDR (item);
2857 free_cons (otem);
2860 /* Now handle the bytecode slot. */
2861 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
2864 ptr[i] = read_pure ? Fpurecopy (item) : item;
2865 otem = XCONS (tem);
2866 tem = Fcdr (tem);
2867 free_cons (otem);
2869 return vector;
2872 /* FLAG = 1 means check for ] to terminate rather than ) and .
2873 FLAG = -1 means check for starting with defun
2874 and make structure pure. */
2876 static Lisp_Object
2877 read_list (flag, readcharfun)
2878 int flag;
2879 register Lisp_Object readcharfun;
2881 /* -1 means check next element for defun,
2882 0 means don't check,
2883 1 means already checked and found defun. */
2884 int defunflag = flag < 0 ? -1 : 0;
2885 Lisp_Object val, tail;
2886 register Lisp_Object elt, tem;
2887 struct gcpro gcpro1, gcpro2;
2888 /* 0 is the normal case.
2889 1 means this list is a doc reference; replace it with the number 0.
2890 2 means this list is a doc reference; replace it with the doc string. */
2891 int doc_reference = 0;
2893 /* Initialize this to 1 if we are reading a list. */
2894 int first_in_list = flag <= 0;
2896 val = Qnil;
2897 tail = Qnil;
2899 while (1)
2901 int ch;
2902 GCPRO2 (val, tail);
2903 elt = read1 (readcharfun, &ch, first_in_list);
2904 UNGCPRO;
2906 first_in_list = 0;
2908 /* While building, if the list starts with #$, treat it specially. */
2909 if (EQ (elt, Vload_file_name)
2910 && ! NILP (elt)
2911 && !NILP (Vpurify_flag))
2913 if (NILP (Vdoc_file_name))
2914 /* We have not yet called Snarf-documentation, so assume
2915 this file is described in the DOC-MM.NN file
2916 and Snarf-documentation will fill in the right value later.
2917 For now, replace the whole list with 0. */
2918 doc_reference = 1;
2919 else
2920 /* We have already called Snarf-documentation, so make a relative
2921 file name for this file, so it can be found properly
2922 in the installed Lisp directory.
2923 We don't use Fexpand_file_name because that would make
2924 the directory absolute now. */
2925 elt = concat2 (build_string ("../lisp/"),
2926 Ffile_name_nondirectory (elt));
2928 else if (EQ (elt, Vload_file_name)
2929 && ! NILP (elt)
2930 && load_force_doc_strings)
2931 doc_reference = 2;
2933 if (ch)
2935 if (flag > 0)
2937 if (ch == ']')
2938 return val;
2939 Fsignal (Qinvalid_read_syntax,
2940 Fcons (make_string (") or . in a vector", 18), Qnil));
2942 if (ch == ')')
2943 return val;
2944 if (ch == '.')
2946 GCPRO2 (val, tail);
2947 if (!NILP (tail))
2948 XSETCDR (tail, read0 (readcharfun));
2949 else
2950 val = read0 (readcharfun);
2951 read1 (readcharfun, &ch, 0);
2952 UNGCPRO;
2953 if (ch == ')')
2955 if (doc_reference == 1)
2956 return make_number (0);
2957 if (doc_reference == 2)
2959 /* Get a doc string from the file we are loading.
2960 If it's in saved_doc_string, get it from there. */
2961 int pos = XINT (XCDR (val));
2962 /* Position is negative for user variables. */
2963 if (pos < 0) pos = -pos;
2964 if (pos >= saved_doc_string_position
2965 && pos < (saved_doc_string_position
2966 + saved_doc_string_length))
2968 int start = pos - saved_doc_string_position;
2969 int from, to;
2971 /* Process quoting with ^A,
2972 and find the end of the string,
2973 which is marked with ^_ (037). */
2974 for (from = start, to = start;
2975 saved_doc_string[from] != 037;)
2977 int c = saved_doc_string[from++];
2978 if (c == 1)
2980 c = saved_doc_string[from++];
2981 if (c == 1)
2982 saved_doc_string[to++] = c;
2983 else if (c == '0')
2984 saved_doc_string[to++] = 0;
2985 else if (c == '_')
2986 saved_doc_string[to++] = 037;
2988 else
2989 saved_doc_string[to++] = c;
2992 return make_string (saved_doc_string + start,
2993 to - start);
2995 /* Look in prev_saved_doc_string the same way. */
2996 else if (pos >= prev_saved_doc_string_position
2997 && pos < (prev_saved_doc_string_position
2998 + prev_saved_doc_string_length))
3000 int start = pos - prev_saved_doc_string_position;
3001 int from, to;
3003 /* Process quoting with ^A,
3004 and find the end of the string,
3005 which is marked with ^_ (037). */
3006 for (from = start, to = start;
3007 prev_saved_doc_string[from] != 037;)
3009 int c = prev_saved_doc_string[from++];
3010 if (c == 1)
3012 c = prev_saved_doc_string[from++];
3013 if (c == 1)
3014 prev_saved_doc_string[to++] = c;
3015 else if (c == '0')
3016 prev_saved_doc_string[to++] = 0;
3017 else if (c == '_')
3018 prev_saved_doc_string[to++] = 037;
3020 else
3021 prev_saved_doc_string[to++] = c;
3024 return make_string (prev_saved_doc_string + start,
3025 to - start);
3027 else
3028 return get_doc_string (val, 0, 0);
3031 return val;
3033 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil));
3035 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil));
3037 tem = (read_pure && flag <= 0
3038 ? pure_cons (elt, Qnil)
3039 : Fcons (elt, Qnil));
3040 if (!NILP (tail))
3041 XSETCDR (tail, tem);
3042 else
3043 val = tem;
3044 tail = tem;
3045 if (defunflag < 0)
3046 defunflag = EQ (elt, Qdefun);
3047 else if (defunflag > 0)
3048 read_pure = 1;
3052 Lisp_Object Vobarray;
3053 Lisp_Object initial_obarray;
3055 /* oblookup stores the bucket number here, for the sake of Funintern. */
3057 int oblookup_last_bucket_number;
3059 static int hash_string ();
3061 /* Get an error if OBARRAY is not an obarray.
3062 If it is one, return it. */
3064 Lisp_Object
3065 check_obarray (obarray)
3066 Lisp_Object obarray;
3068 while (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3070 /* If Vobarray is now invalid, force it to be valid. */
3071 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
3073 obarray = wrong_type_argument (Qvectorp, obarray);
3075 return obarray;
3078 /* Intern the C string STR: return a symbol with that name,
3079 interned in the current obarray. */
3081 Lisp_Object
3082 intern (str)
3083 const char *str;
3085 Lisp_Object tem;
3086 int len = strlen (str);
3087 Lisp_Object obarray;
3089 obarray = Vobarray;
3090 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
3091 obarray = check_obarray (obarray);
3092 tem = oblookup (obarray, str, len, len);
3093 if (SYMBOLP (tem))
3094 return tem;
3095 return Fintern (make_string (str, len), obarray);
3098 /* Create an uninterned symbol with name STR. */
3100 Lisp_Object
3101 make_symbol (str)
3102 char *str;
3104 int len = strlen (str);
3106 return Fmake_symbol ((!NILP (Vpurify_flag)
3107 ? make_pure_string (str, len, len, 0)
3108 : make_string (str, len)));
3111 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
3112 doc: /* Return the canonical symbol whose name is STRING.
3113 If there is none, one is created by this function and returned.
3114 A second optional argument specifies the obarray to use;
3115 it defaults to the value of `obarray'. */)
3116 (string, obarray)
3117 Lisp_Object string, obarray;
3119 register Lisp_Object tem, sym, *ptr;
3121 if (NILP (obarray)) obarray = Vobarray;
3122 obarray = check_obarray (obarray);
3124 CHECK_STRING (string);
3126 tem = oblookup (obarray, SDATA (string),
3127 SCHARS (string),
3128 SBYTES (string));
3129 if (!INTEGERP (tem))
3130 return tem;
3132 if (!NILP (Vpurify_flag))
3133 string = Fpurecopy (string);
3134 sym = Fmake_symbol (string);
3136 if (EQ (obarray, initial_obarray))
3137 XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3138 else
3139 XSYMBOL (sym)->interned = SYMBOL_INTERNED;
3141 if ((SREF (string, 0) == ':')
3142 && EQ (obarray, initial_obarray))
3144 XSYMBOL (sym)->constant = 1;
3145 XSYMBOL (sym)->value = sym;
3148 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
3149 if (SYMBOLP (*ptr))
3150 XSYMBOL (sym)->next = XSYMBOL (*ptr);
3151 else
3152 XSYMBOL (sym)->next = 0;
3153 *ptr = sym;
3154 return sym;
3157 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
3158 doc: /* Return the canonical symbol named NAME, or nil if none exists.
3159 NAME may be a string or a symbol. If it is a symbol, that exact
3160 symbol is searched for.
3161 A second optional argument specifies the obarray to use;
3162 it defaults to the value of `obarray'. */)
3163 (name, obarray)
3164 Lisp_Object name, obarray;
3166 register Lisp_Object tem, string;
3168 if (NILP (obarray)) obarray = Vobarray;
3169 obarray = check_obarray (obarray);
3171 if (!SYMBOLP (name))
3173 CHECK_STRING (name);
3174 string = name;
3176 else
3177 string = SYMBOL_NAME (name);
3179 tem = oblookup (obarray, SDATA (string), SCHARS (string), SBYTES (string));
3180 if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem)))
3181 return Qnil;
3182 else
3183 return tem;
3186 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
3187 doc: /* Delete the symbol named NAME, if any, from OBARRAY.
3188 The value is t if a symbol was found and deleted, nil otherwise.
3189 NAME may be a string or a symbol. If it is a symbol, that symbol
3190 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3191 OBARRAY defaults to the value of the variable `obarray'. */)
3192 (name, obarray)
3193 Lisp_Object name, obarray;
3195 register Lisp_Object string, tem;
3196 int hash;
3198 if (NILP (obarray)) obarray = Vobarray;
3199 obarray = check_obarray (obarray);
3201 if (SYMBOLP (name))
3202 string = SYMBOL_NAME (name);
3203 else
3205 CHECK_STRING (name);
3206 string = name;
3209 tem = oblookup (obarray, SDATA (string),
3210 SCHARS (string),
3211 SBYTES (string));
3212 if (INTEGERP (tem))
3213 return Qnil;
3214 /* If arg was a symbol, don't delete anything but that symbol itself. */
3215 if (SYMBOLP (name) && !EQ (name, tem))
3216 return Qnil;
3218 XSYMBOL (tem)->interned = SYMBOL_UNINTERNED;
3219 XSYMBOL (tem)->constant = 0;
3220 XSYMBOL (tem)->indirect_variable = 0;
3222 hash = oblookup_last_bucket_number;
3224 if (EQ (XVECTOR (obarray)->contents[hash], tem))
3226 if (XSYMBOL (tem)->next)
3227 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
3228 else
3229 XSETINT (XVECTOR (obarray)->contents[hash], 0);
3231 else
3233 Lisp_Object tail, following;
3235 for (tail = XVECTOR (obarray)->contents[hash];
3236 XSYMBOL (tail)->next;
3237 tail = following)
3239 XSETSYMBOL (following, XSYMBOL (tail)->next);
3240 if (EQ (following, tem))
3242 XSYMBOL (tail)->next = XSYMBOL (following)->next;
3243 break;
3248 return Qt;
3251 /* Return the symbol in OBARRAY whose names matches the string
3252 of SIZE characters (SIZE_BYTE bytes) at PTR.
3253 If there is no such symbol in OBARRAY, return nil.
3255 Also store the bucket number in oblookup_last_bucket_number. */
3257 Lisp_Object
3258 oblookup (obarray, ptr, size, size_byte)
3259 Lisp_Object obarray;
3260 register const char *ptr;
3261 int size, size_byte;
3263 int hash;
3264 int obsize;
3265 register Lisp_Object tail;
3266 Lisp_Object bucket, tem;
3268 if (!VECTORP (obarray)
3269 || (obsize = XVECTOR (obarray)->size) == 0)
3271 obarray = check_obarray (obarray);
3272 obsize = XVECTOR (obarray)->size;
3274 /* This is sometimes needed in the middle of GC. */
3275 obsize &= ~ARRAY_MARK_FLAG;
3276 /* Combining next two lines breaks VMS C 2.3. */
3277 hash = hash_string (ptr, size_byte);
3278 hash %= obsize;
3279 bucket = XVECTOR (obarray)->contents[hash];
3280 oblookup_last_bucket_number = hash;
3281 if (EQ (bucket, make_number (0)))
3283 else if (!SYMBOLP (bucket))
3284 error ("Bad data in guts of obarray"); /* Like CADR error message */
3285 else
3286 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
3288 if (SBYTES (SYMBOL_NAME (tail)) == size_byte
3289 && SCHARS (SYMBOL_NAME (tail)) == size
3290 && !bcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
3291 return tail;
3292 else if (XSYMBOL (tail)->next == 0)
3293 break;
3295 XSETINT (tem, hash);
3296 return tem;
3299 static int
3300 hash_string (ptr, len)
3301 const unsigned char *ptr;
3302 int len;
3304 register const unsigned char *p = ptr;
3305 register const unsigned char *end = p + len;
3306 register unsigned char c;
3307 register int hash = 0;
3309 while (p != end)
3311 c = *p++;
3312 if (c >= 0140) c -= 40;
3313 hash = ((hash<<3) + (hash>>28) + c);
3315 return hash & 07777777777;
3318 void
3319 map_obarray (obarray, fn, arg)
3320 Lisp_Object obarray;
3321 void (*fn) P_ ((Lisp_Object, Lisp_Object));
3322 Lisp_Object arg;
3324 register int i;
3325 register Lisp_Object tail;
3326 CHECK_VECTOR (obarray);
3327 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
3329 tail = XVECTOR (obarray)->contents[i];
3330 if (SYMBOLP (tail))
3331 while (1)
3333 (*fn) (tail, arg);
3334 if (XSYMBOL (tail)->next == 0)
3335 break;
3336 XSETSYMBOL (tail, XSYMBOL (tail)->next);
3341 void
3342 mapatoms_1 (sym, function)
3343 Lisp_Object sym, function;
3345 call1 (function, sym);
3348 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
3349 doc: /* Call FUNCTION on every symbol in OBARRAY.
3350 OBARRAY defaults to the value of `obarray'. */)
3351 (function, obarray)
3352 Lisp_Object function, obarray;
3354 if (NILP (obarray)) obarray = Vobarray;
3355 obarray = check_obarray (obarray);
3357 map_obarray (obarray, mapatoms_1, function);
3358 return Qnil;
3361 #define OBARRAY_SIZE 1511
3363 void
3364 init_obarray ()
3366 Lisp_Object oblength;
3367 int hash;
3368 Lisp_Object *tem;
3370 XSETFASTINT (oblength, OBARRAY_SIZE);
3372 Qnil = Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
3373 Vobarray = Fmake_vector (oblength, make_number (0));
3374 initial_obarray = Vobarray;
3375 staticpro (&initial_obarray);
3376 /* Intern nil in the obarray */
3377 XSYMBOL (Qnil)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
3378 XSYMBOL (Qnil)->constant = 1;
3380 /* These locals are to kludge around a pyramid compiler bug. */
3381 hash = hash_string ("nil", 3);
3382 /* Separate statement here to avoid VAXC bug. */
3383 hash %= OBARRAY_SIZE;
3384 tem = &XVECTOR (Vobarray)->contents[hash];
3385 *tem = Qnil;
3387 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
3388 XSYMBOL (Qnil)->function = Qunbound;
3389 XSYMBOL (Qunbound)->value = Qunbound;
3390 XSYMBOL (Qunbound)->function = Qunbound;
3392 Qt = intern ("t");
3393 XSYMBOL (Qnil)->value = Qnil;
3394 XSYMBOL (Qnil)->plist = Qnil;
3395 XSYMBOL (Qt)->value = Qt;
3396 XSYMBOL (Qt)->constant = 1;
3398 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3399 Vpurify_flag = Qt;
3401 Qvariable_documentation = intern ("variable-documentation");
3402 staticpro (&Qvariable_documentation);
3404 read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
3405 read_buffer = (char *) xmalloc (read_buffer_size);
3408 void
3409 defsubr (sname)
3410 struct Lisp_Subr *sname;
3412 Lisp_Object sym;
3413 sym = intern (sname->symbol_name);
3414 XSETSUBR (XSYMBOL (sym)->function, sname);
3417 #ifdef NOTDEF /* use fset in subr.el now */
3418 void
3419 defalias (sname, string)
3420 struct Lisp_Subr *sname;
3421 char *string;
3423 Lisp_Object sym;
3424 sym = intern (string);
3425 XSETSUBR (XSYMBOL (sym)->function, sname);
3427 #endif /* NOTDEF */
3429 /* Define an "integer variable"; a symbol whose value is forwarded
3430 to a C variable of type int. Sample call: */
3431 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3432 void
3433 defvar_int (namestring, address)
3434 char *namestring;
3435 EMACS_INT *address;
3437 Lisp_Object sym, val;
3438 sym = intern (namestring);
3439 val = allocate_misc ();
3440 XMISCTYPE (val) = Lisp_Misc_Intfwd;
3441 XINTFWD (val)->intvar = address;
3442 SET_SYMBOL_VALUE (sym, val);
3445 /* Similar but define a variable whose value is t if address contains 1,
3446 nil if address contains 0 */
3447 void
3448 defvar_bool (namestring, address)
3449 char *namestring;
3450 int *address;
3452 Lisp_Object sym, val;
3453 sym = intern (namestring);
3454 val = allocate_misc ();
3455 XMISCTYPE (val) = Lisp_Misc_Boolfwd;
3456 XBOOLFWD (val)->boolvar = address;
3457 SET_SYMBOL_VALUE (sym, val);
3458 Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
3461 /* Similar but define a variable whose value is the Lisp Object stored
3462 at address. Two versions: with and without gc-marking of the C
3463 variable. The nopro version is used when that variable will be
3464 gc-marked for some other reason, since marking the same slot twice
3465 can cause trouble with strings. */
3466 void
3467 defvar_lisp_nopro (namestring, address)
3468 char *namestring;
3469 Lisp_Object *address;
3471 Lisp_Object sym, val;
3472 sym = intern (namestring);
3473 val = allocate_misc ();
3474 XMISCTYPE (val) = Lisp_Misc_Objfwd;
3475 XOBJFWD (val)->objvar = address;
3476 SET_SYMBOL_VALUE (sym, val);
3479 void
3480 defvar_lisp (namestring, address)
3481 char *namestring;
3482 Lisp_Object *address;
3484 defvar_lisp_nopro (namestring, address);
3485 staticpro (address);
3488 /* Similar but define a variable whose value is the Lisp Object stored in
3489 the current buffer. address is the address of the slot in the buffer
3490 that is current now. */
3492 void
3493 defvar_per_buffer (namestring, address, type, doc)
3494 char *namestring;
3495 Lisp_Object *address;
3496 Lisp_Object type;
3497 char *doc;
3499 Lisp_Object sym, val;
3500 int offset;
3502 sym = intern (namestring);
3503 val = allocate_misc ();
3504 offset = (char *)address - (char *)current_buffer;
3506 XMISCTYPE (val) = Lisp_Misc_Buffer_Objfwd;
3507 XBUFFER_OBJFWD (val)->offset = offset;
3508 SET_SYMBOL_VALUE (sym, val);
3509 PER_BUFFER_SYMBOL (offset) = sym;
3510 PER_BUFFER_TYPE (offset) = type;
3512 if (PER_BUFFER_IDX (offset) == 0)
3513 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3514 slot of buffer_local_flags */
3515 abort ();
3519 /* Similar but define a variable whose value is the Lisp Object stored
3520 at a particular offset in the current kboard object. */
3522 void
3523 defvar_kboard (namestring, offset)
3524 char *namestring;
3525 int offset;
3527 Lisp_Object sym, val;
3528 sym = intern (namestring);
3529 val = allocate_misc ();
3530 XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd;
3531 XKBOARD_OBJFWD (val)->offset = offset;
3532 SET_SYMBOL_VALUE (sym, val);
3535 /* Record the value of load-path used at the start of dumping
3536 so we can see if the site changed it later during dumping. */
3537 static Lisp_Object dump_path;
3539 void
3540 init_lread ()
3542 char *normal;
3543 int turn_off_warning = 0;
3545 /* Compute the default load-path. */
3546 #ifdef CANNOT_DUMP
3547 normal = PATH_LOADSEARCH;
3548 Vload_path = decode_env_path (0, normal);
3549 #else
3550 if (NILP (Vpurify_flag))
3551 normal = PATH_LOADSEARCH;
3552 else
3553 normal = PATH_DUMPLOADSEARCH;
3555 /* In a dumped Emacs, we normally have to reset the value of
3556 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3557 uses ../lisp, instead of the path of the installed elisp
3558 libraries. However, if it appears that Vload_path was changed
3559 from the default before dumping, don't override that value. */
3560 if (initialized)
3562 if (! NILP (Fequal (dump_path, Vload_path)))
3564 Vload_path = decode_env_path (0, normal);
3565 if (!NILP (Vinstallation_directory))
3567 Lisp_Object tem, tem1, sitelisp;
3569 /* Remove site-lisp dirs from path temporarily and store
3570 them in sitelisp, then conc them on at the end so
3571 they're always first in path. */
3572 sitelisp = Qnil;
3573 while (1)
3575 tem = Fcar (Vload_path);
3576 tem1 = Fstring_match (build_string ("site-lisp"),
3577 tem, Qnil);
3578 if (!NILP (tem1))
3580 Vload_path = Fcdr (Vload_path);
3581 sitelisp = Fcons (tem, sitelisp);
3583 else
3584 break;
3587 /* Add to the path the lisp subdir of the
3588 installation dir, if it exists. */
3589 tem = Fexpand_file_name (build_string ("lisp"),
3590 Vinstallation_directory);
3591 tem1 = Ffile_exists_p (tem);
3592 if (!NILP (tem1))
3594 if (NILP (Fmember (tem, Vload_path)))
3596 turn_off_warning = 1;
3597 Vload_path = Fcons (tem, Vload_path);
3600 else
3601 /* That dir doesn't exist, so add the build-time
3602 Lisp dirs instead. */
3603 Vload_path = nconc2 (Vload_path, dump_path);
3605 /* Add leim under the installation dir, if it exists. */
3606 tem = Fexpand_file_name (build_string ("leim"),
3607 Vinstallation_directory);
3608 tem1 = Ffile_exists_p (tem);
3609 if (!NILP (tem1))
3611 if (NILP (Fmember (tem, Vload_path)))
3612 Vload_path = Fcons (tem, Vload_path);
3615 /* Add site-list under the installation dir, if it exists. */
3616 tem = Fexpand_file_name (build_string ("site-lisp"),
3617 Vinstallation_directory);
3618 tem1 = Ffile_exists_p (tem);
3619 if (!NILP (tem1))
3621 if (NILP (Fmember (tem, Vload_path)))
3622 Vload_path = Fcons (tem, Vload_path);
3625 /* If Emacs was not built in the source directory,
3626 and it is run from where it was built, add to load-path
3627 the lisp, leim and site-lisp dirs under that directory. */
3629 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
3631 Lisp_Object tem2;
3633 tem = Fexpand_file_name (build_string ("src/Makefile"),
3634 Vinstallation_directory);
3635 tem1 = Ffile_exists_p (tem);
3637 /* Don't be fooled if they moved the entire source tree
3638 AFTER dumping Emacs. If the build directory is indeed
3639 different from the source dir, src/Makefile.in and
3640 src/Makefile will not be found together. */
3641 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
3642 Vinstallation_directory);
3643 tem2 = Ffile_exists_p (tem);
3644 if (!NILP (tem1) && NILP (tem2))
3646 tem = Fexpand_file_name (build_string ("lisp"),
3647 Vsource_directory);
3649 if (NILP (Fmember (tem, Vload_path)))
3650 Vload_path = Fcons (tem, Vload_path);
3652 tem = Fexpand_file_name (build_string ("leim"),
3653 Vsource_directory);
3655 if (NILP (Fmember (tem, Vload_path)))
3656 Vload_path = Fcons (tem, Vload_path);
3658 tem = Fexpand_file_name (build_string ("site-lisp"),
3659 Vsource_directory);
3661 if (NILP (Fmember (tem, Vload_path)))
3662 Vload_path = Fcons (tem, Vload_path);
3665 if (!NILP (sitelisp))
3666 Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path);
3670 else
3672 /* NORMAL refers to the lisp dir in the source directory. */
3673 /* We used to add ../lisp at the front here, but
3674 that caused trouble because it was copied from dump_path
3675 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3676 It should be unnecessary. */
3677 Vload_path = decode_env_path (0, normal);
3678 dump_path = Vload_path;
3680 #endif
3682 #if (!(defined(WINDOWSNT) || (defined(HAVE_CARBON))))
3683 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3684 almost never correct, thereby causing a warning to be printed out that
3685 confuses users. Since PATH_LOADSEARCH is always overridden by the
3686 EMACSLOADPATH environment variable below, disable the warning on NT.
3687 Also, when using the "self-contained" option for Carbon Emacs for MacOSX,
3688 the "standard" paths may not exist and would be overridden by
3689 EMACSLOADPATH as on NT. Since this depends on how the executable
3690 was build and packaged, turn off the warnings in general */
3692 /* Warn if dirs in the *standard* path don't exist. */
3693 if (!turn_off_warning)
3695 Lisp_Object path_tail;
3697 for (path_tail = Vload_path;
3698 !NILP (path_tail);
3699 path_tail = XCDR (path_tail))
3701 Lisp_Object dirfile;
3702 dirfile = Fcar (path_tail);
3703 if (STRINGP (dirfile))
3705 dirfile = Fdirectory_file_name (dirfile);
3706 if (access (SDATA (dirfile), 0) < 0)
3707 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3708 XCAR (path_tail));
3712 #endif /* !(WINDOWSNT || HAVE_CARBON) */
3714 /* If the EMACSLOADPATH environment variable is set, use its value.
3715 This doesn't apply if we're dumping. */
3716 #ifndef CANNOT_DUMP
3717 if (NILP (Vpurify_flag)
3718 && egetenv ("EMACSLOADPATH"))
3719 #endif
3720 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
3722 Vvalues = Qnil;
3724 load_in_progress = 0;
3725 Vload_file_name = Qnil;
3727 load_descriptor_list = Qnil;
3729 Vstandard_input = Qt;
3730 Vloads_in_progress = Qnil;
3733 /* Print a warning, using format string FORMAT, that directory DIRNAME
3734 does not exist. Print it on stderr and put it in *Message*. */
3736 void
3737 dir_warning (format, dirname)
3738 char *format;
3739 Lisp_Object dirname;
3741 char *buffer
3742 = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);
3744 fprintf (stderr, format, SDATA (dirname));
3745 sprintf (buffer, format, SDATA (dirname));
3746 /* Don't log the warning before we've initialized!! */
3747 if (initialized)
3748 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
3751 void
3752 syms_of_lread ()
3754 defsubr (&Sread);
3755 defsubr (&Sread_from_string);
3756 defsubr (&Sintern);
3757 defsubr (&Sintern_soft);
3758 defsubr (&Sunintern);
3759 defsubr (&Sload);
3760 defsubr (&Seval_buffer);
3761 defsubr (&Seval_region);
3762 defsubr (&Sread_char);
3763 defsubr (&Sread_char_exclusive);
3764 defsubr (&Sread_event);
3765 defsubr (&Sget_file_char);
3766 defsubr (&Smapatoms);
3767 defsubr (&Slocate_file_internal);
3769 DEFVAR_LISP ("obarray", &Vobarray,
3770 doc: /* Symbol table for use by `intern' and `read'.
3771 It is a vector whose length ought to be prime for best results.
3772 The vector's contents don't make sense if examined from Lisp programs;
3773 to find all the symbols in an obarray, use `mapatoms'. */);
3775 DEFVAR_LISP ("values", &Vvalues,
3776 doc: /* List of values of all expressions which were read, evaluated and printed.
3777 Order is reverse chronological. */);
3779 DEFVAR_LISP ("standard-input", &Vstandard_input,
3780 doc: /* Stream for read to get input from.
3781 See documentation of `read' for possible values. */);
3782 Vstandard_input = Qt;
3784 DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions,
3785 doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
3787 If this variable is a buffer, then only forms read from that buffer
3788 will be added to `read-symbol-positions-list'.
3789 If this variable is t, then all read forms will be added.
3790 The effect of all other values other than nil are not currently
3791 defined, although they may be in the future.
3793 The positions are relative to the last call to `read' or
3794 `read-from-string'. It is probably a bad idea to set this variable at
3795 the toplevel; bind it instead. */);
3796 Vread_with_symbol_positions = Qnil;
3798 DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list,
3799 doc: /* A list mapping read symbols to their positions.
3800 This variable is modified during calls to `read' or
3801 `read-from-string', but only when `read-with-symbol-positions' is
3802 non-nil.
3804 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
3805 CHAR-POSITION is an integer giving the offset of that occurrence of the
3806 symbol from the position where `read' or `read-from-string' started.
3808 Note that a symbol will appear multiple times in this list, if it was
3809 read multiple times. The list is in the same order as the symbols
3810 were read in. */);
3811 Vread_symbol_positions_list = Qnil;
3813 DEFVAR_LISP ("load-path", &Vload_path,
3814 doc: /* *List of directories to search for files to load.
3815 Each element is a string (directory name) or nil (try default directory).
3816 Initialized based on EMACSLOADPATH environment variable, if any,
3817 otherwise to default specified by file `epaths.h' when Emacs was built. */);
3819 DEFVAR_LISP ("load-suffixes", &Vload_suffixes,
3820 doc: /* *List of suffixes to try for files to load.
3821 This list should not include the empty string. */);
3822 Vload_suffixes = Fcons (build_string (".elc"),
3823 Fcons (build_string (".el"), Qnil));
3824 /* We don't use empty_string because it's not initialized yet. */
3825 default_suffixes = Fcons (build_string (""), Qnil);
3826 staticpro (&default_suffixes);
3828 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
3829 doc: /* Non-nil iff inside of `load'. */);
3831 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
3832 doc: /* An alist of expressions to be evalled when particular files are loaded.
3833 Each element looks like (FILENAME FORMS...).
3834 When `load' is run and the file-name argument is FILENAME,
3835 the FORMS in the corresponding element are executed at the end of loading.
3837 FILENAME must match exactly! Normally FILENAME is the name of a library,
3838 with no directory specified, since that is how `load' is normally called.
3839 An error in FORMS does not undo the load,
3840 but does prevent execution of the rest of the FORMS.
3841 FILENAME can also be a symbol (a feature) and FORMS are then executed
3842 when the corresponding call to `provide' is made. */);
3843 Vafter_load_alist = Qnil;
3845 DEFVAR_LISP ("load-history", &Vload_history,
3846 doc: /* Alist mapping source file names to symbols and features.
3847 Each alist element is a list that starts with a file name,
3848 except for one element (optional) that starts with nil and describes
3849 definitions evaluated from buffers not visiting files.
3850 The remaining elements of each list are symbols defined as variables
3851 and cons cells of the form `(provide . FEATURE)', `(require . FEATURE)',
3852 `(defun . FUNCTION)', `(autoload . SYMBOL)', and `(t . SYMBOL)'.
3853 An element `(t . SYMBOL)' precedes an entry `(defun . FUNCTION)',
3854 and means that SYMBOL was an autoload before this file redefined it
3855 as a function. */);
3856 Vload_history = Qnil;
3858 DEFVAR_LISP ("load-file-name", &Vload_file_name,
3859 doc: /* Full name of file being loaded by `load'. */);
3860 Vload_file_name = Qnil;
3862 DEFVAR_LISP ("user-init-file", &Vuser_init_file,
3863 doc: /* File name, including directory, of user's initialization file.
3864 If the file loaded had extension `.elc', and the corresponding source file
3865 exists, this variable contains the name of source file, suitable for use
3866 by functions like `custom-save-all' which edit the init file. */);
3867 Vuser_init_file = Qnil;
3869 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
3870 doc: /* Used for internal purposes by `load'. */);
3871 Vcurrent_load_list = Qnil;
3873 DEFVAR_LISP ("load-read-function", &Vload_read_function,
3874 doc: /* Function used by `load' and `eval-region' for reading expressions.
3875 The default is nil, which means use the function `read'. */);
3876 Vload_read_function = Qnil;
3878 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
3879 doc: /* Function called in `load' for loading an Emacs lisp source file.
3880 This function is for doing code conversion before reading the source file.
3881 If nil, loading is done without any code conversion.
3882 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
3883 FULLNAME is the full name of FILE.
3884 See `load' for the meaning of the remaining arguments. */);
3885 Vload_source_file_function = Qnil;
3887 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
3888 doc: /* Non-nil means `load' should force-load all dynamic doc strings.
3889 This is useful when the file being loaded is a temporary copy. */);
3890 load_force_doc_strings = 0;
3892 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
3893 doc: /* Non-nil means `read' converts strings to unibyte whenever possible.
3894 This is normally bound by `load' and `eval-buffer' to control `read',
3895 and is not meant for users to change. */);
3896 load_convert_to_unibyte = 0;
3898 DEFVAR_LISP ("source-directory", &Vsource_directory,
3899 doc: /* Directory in which Emacs sources were found when Emacs was built.
3900 You cannot count on them to still be there! */);
3901 Vsource_directory
3902 = Fexpand_file_name (build_string ("../"),
3903 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
3905 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
3906 doc: /* List of files that were preloaded (when dumping Emacs). */);
3907 Vpreloaded_file_list = Qnil;
3909 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
3910 doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
3911 Vbyte_boolean_vars = Qnil;
3913 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries,
3914 doc: /* Non-nil means load dangerous compiled Lisp files.
3915 Some versions of XEmacs use different byte codes than Emacs. These
3916 incompatible byte codes can make Emacs crash when it tries to execute
3917 them. */);
3918 load_dangerous_libraries = 0;
3920 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp,
3921 doc: /* Regular expression matching safe to load compiled Lisp files.
3922 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
3923 from the file, and matches them against this regular expression.
3924 When the regular expression matches, the file is considered to be safe
3925 to load. See also `load-dangerous-libraries'. */);
3926 Vbytecomp_version_regexp
3927 = build_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
3929 /* Vsource_directory was initialized in init_lread. */
3931 load_descriptor_list = Qnil;
3932 staticpro (&load_descriptor_list);
3934 Qcurrent_load_list = intern ("current-load-list");
3935 staticpro (&Qcurrent_load_list);
3937 Qstandard_input = intern ("standard-input");
3938 staticpro (&Qstandard_input);
3940 Qread_char = intern ("read-char");
3941 staticpro (&Qread_char);
3943 Qget_file_char = intern ("get-file-char");
3944 staticpro (&Qget_file_char);
3946 Qbackquote = intern ("`");
3947 staticpro (&Qbackquote);
3948 Qcomma = intern (",");
3949 staticpro (&Qcomma);
3950 Qcomma_at = intern (",@");
3951 staticpro (&Qcomma_at);
3952 Qcomma_dot = intern (",.");
3953 staticpro (&Qcomma_dot);
3955 Qinhibit_file_name_operation = intern ("inhibit-file-name-operation");
3956 staticpro (&Qinhibit_file_name_operation);
3958 Qascii_character = intern ("ascii-character");
3959 staticpro (&Qascii_character);
3961 Qfunction = intern ("function");
3962 staticpro (&Qfunction);
3964 Qload = intern ("load");
3965 staticpro (&Qload);
3967 Qload_file_name = intern ("load-file-name");
3968 staticpro (&Qload_file_name);
3970 staticpro (&dump_path);
3972 staticpro (&read_objects);
3973 read_objects = Qnil;
3974 staticpro (&seen_list);
3976 Vloads_in_progress = Qnil;
3977 staticpro (&Vloads_in_progress);
3980 /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d
3981 (do not change this comment) */