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