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