]> code.delx.au - gnu-emacs/blob - src/lread.c
(echo_area_display): Use selected frame's minibuf window
[gnu-emacs] / src / lread.c
1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989,
3 1993, 1994, 1995 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21
22 #include <config.h>
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/file.h>
27 #include <errno.h>
28 #include "lisp.h"
29
30 #ifndef standalone
31 #include "buffer.h"
32 #include <paths.h>
33 #include "commands.h"
34 #include "keyboard.h"
35 #include "termhooks.h"
36 #endif
37
38 #ifdef lint
39 #include <sys/inode.h>
40 #endif /* lint */
41
42 #ifndef X_OK
43 #define X_OK 01
44 #endif
45
46 #ifdef LISP_FLOAT_TYPE
47 #ifdef STDC_HEADERS
48 #include <stdlib.h>
49 #endif
50
51 #ifdef MSDOS
52 #include "msdos.h"
53 /* These are redefined (correctly, but differently) in values.h. */
54 #undef INTBITS
55 #undef LONGBITS
56 #undef SHORTBITS
57 #endif
58
59 #include <math.h>
60 #endif /* LISP_FLOAT_TYPE */
61
62 #ifndef O_RDONLY
63 #define O_RDONLY 0
64 #endif
65
66 extern int errno;
67
68 Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
69 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
70 Lisp_Object Qascii_character, Qload, Qload_file_name;
71 Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot;
72
73 extern Lisp_Object Qevent_symbol_element_mask;
74
75 /* non-zero if inside `load' */
76 int load_in_progress;
77
78 /* Search path for files to be loaded. */
79 Lisp_Object Vload_path;
80
81 /* This is the user-visible association list that maps features to
82 lists of defs in their load files. */
83 Lisp_Object Vload_history;
84
85 /* This is used to build the load history. */
86 Lisp_Object Vcurrent_load_list;
87
88 /* Name of file actually being read by `load'. */
89 Lisp_Object Vload_file_name;
90
91 /* Function to use for reading, in `load' and friends. */
92 Lisp_Object Vload_read_function;
93
94 /* List of descriptors now open for Fload. */
95 static Lisp_Object load_descriptor_list;
96
97 /* File for get_file_char to read from. Use by load */
98 static FILE *instream;
99
100 /* When nonzero, read conses in pure space */
101 static int read_pure;
102
103 /* For use within read-from-string (this reader is non-reentrant!!) */
104 static int read_from_string_index;
105 static int read_from_string_limit;
106
107 /* Nonzero means inside a new-style backquote
108 with no surrounding parentheses.
109 Fread initializes this to zero, so we need not specbind it
110 or worry about what happens to it when there is an error. */
111 static int new_backquote_flag;
112 \f
113 /* Handle unreading and rereading of characters.
114 Write READCHAR to read a character,
115 UNREAD(c) to unread c to be read again. */
116
117 #define READCHAR readchar (readcharfun)
118 #define UNREAD(c) unreadchar (readcharfun, c)
119
120 static int
121 readchar (readcharfun)
122 Lisp_Object readcharfun;
123 {
124 Lisp_Object tem;
125 register struct buffer *inbuffer;
126 register int c, mpos;
127
128 if (BUFFERP (readcharfun))
129 {
130 inbuffer = XBUFFER (readcharfun);
131
132 if (BUF_PT (inbuffer) >= BUF_ZV (inbuffer))
133 return -1;
134 c = *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer, BUF_PT (inbuffer));
135 SET_BUF_PT (inbuffer, BUF_PT (inbuffer) + 1);
136
137 return c;
138 }
139 if (MARKERP (readcharfun))
140 {
141 inbuffer = XMARKER (readcharfun)->buffer;
142
143 mpos = marker_position (readcharfun);
144
145 if (mpos > BUF_ZV (inbuffer) - 1)
146 return -1;
147 c = *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer, mpos);
148 if (mpos != BUF_GPT (inbuffer))
149 XMARKER (readcharfun)->bufpos++;
150 else
151 Fset_marker (readcharfun, make_number (mpos + 1),
152 Fmarker_buffer (readcharfun));
153 return c;
154 }
155 if (EQ (readcharfun, Qget_file_char))
156 {
157 c = getc (instream);
158 #ifdef EINTR
159 /* Interrupted reads have been observed while reading over the network */
160 while (c == EOF && ferror (instream) && errno == EINTR)
161 {
162 clearerr (instream);
163 c = getc (instream);
164 }
165 #endif
166 return c;
167 }
168
169 if (STRINGP (readcharfun))
170 {
171 register int c;
172 /* This used to be return of a conditional expression,
173 but that truncated -1 to a char on VMS. */
174 if (read_from_string_index < read_from_string_limit)
175 c = XSTRING (readcharfun)->data[read_from_string_index++];
176 else
177 c = -1;
178 return c;
179 }
180
181 tem = call0 (readcharfun);
182
183 if (NILP (tem))
184 return -1;
185 return XINT (tem);
186 }
187
188 /* Unread the character C in the way appropriate for the stream READCHARFUN.
189 If the stream is a user function, call it with the char as argument. */
190
191 static void
192 unreadchar (readcharfun, c)
193 Lisp_Object readcharfun;
194 int c;
195 {
196 if (c == -1)
197 /* Don't back up the pointer if we're unreading the end-of-input mark,
198 since readchar didn't advance it when we read it. */
199 ;
200 else if (BUFFERP (readcharfun))
201 {
202 if (XBUFFER (readcharfun) == current_buffer)
203 SET_PT (point - 1);
204 else
205 SET_BUF_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1);
206 }
207 else if (MARKERP (readcharfun))
208 XMARKER (readcharfun)->bufpos--;
209 else if (STRINGP (readcharfun))
210 read_from_string_index--;
211 else if (EQ (readcharfun, Qget_file_char))
212 ungetc (c, instream);
213 else
214 call1 (readcharfun, make_number (c));
215 }
216
217 static Lisp_Object read0 (), read1 (), read_list (), read_vector ();
218 \f
219 /* get a character from the tty */
220
221 extern Lisp_Object read_char ();
222
223 /* Read input events until we get one that's acceptable for our purposes.
224
225 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
226 until we get a character we like, and then stuffed into
227 unread_switch_frame.
228
229 If ASCII_REQUIRED is non-zero, we check function key events to see
230 if the unmodified version of the symbol has a Qascii_character
231 property, and use that character, if present.
232
233 If ERROR_NONASCII is non-zero, we signal an error if the input we
234 get isn't an ASCII character with modifiers. If it's zero but
235 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
236 character. */
237 Lisp_Object
238 read_filtered_event (no_switch_frame, ascii_required, error_nonascii)
239 int no_switch_frame, ascii_required, error_nonascii;
240 {
241 #ifdef standalone
242 return make_number (getchar ());
243 #else
244 register Lisp_Object val, delayed_switch_frame;
245
246 delayed_switch_frame = Qnil;
247
248 /* Read until we get an acceptable event. */
249 retry:
250 val = read_char (0, 0, 0, Qnil, 0);
251
252 if (BUFFERP (val))
253 goto retry;
254
255 /* switch-frame events are put off until after the next ASCII
256 character. This is better than signalling an error just because
257 the last characters were typed to a separate minibuffer frame,
258 for example. Eventually, some code which can deal with
259 switch-frame events will read it and process it. */
260 if (no_switch_frame
261 && EVENT_HAS_PARAMETERS (val)
262 && EQ (EVENT_HEAD (val), Qswitch_frame))
263 {
264 delayed_switch_frame = val;
265 goto retry;
266 }
267
268 if (ascii_required)
269 {
270 /* Convert certain symbols to their ASCII equivalents. */
271 if (SYMBOLP (val))
272 {
273 Lisp_Object tem, tem1, tem2;
274 tem = Fget (val, Qevent_symbol_element_mask);
275 if (!NILP (tem))
276 {
277 tem1 = Fget (Fcar (tem), Qascii_character);
278 /* Merge this symbol's modifier bits
279 with the ASCII equivalent of its basic code. */
280 if (!NILP (tem1))
281 XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
282 }
283 }
284
285 /* If we don't have a character now, deal with it appropriately. */
286 if (!INTEGERP (val))
287 {
288 if (error_nonascii)
289 {
290 Vunread_command_events = Fcons (val, Qnil);
291 error ("Non-character input-event");
292 }
293 else
294 goto retry;
295 }
296 }
297
298 if (! NILP (delayed_switch_frame))
299 unread_switch_frame = delayed_switch_frame;
300
301 return val;
302 #endif
303 }
304
305 DEFUN ("read-char", Fread_char, Sread_char, 0, 0, 0,
306 "Read a character from the command input (keyboard or macro).\n\
307 It is returned as a number.\n\
308 If the user generates an event which is not a character (i.e. a mouse\n\
309 click or function key event), `read-char' signals an error. As an\n\
310 exception, switch-frame events are put off until non-ASCII events can\n\
311 be read.\n\
312 If you want to read non-character events, or ignore them, call\n\
313 `read-event' or `read-char-exclusive' instead.")
314 ()
315 {
316 return read_filtered_event (1, 1, 1);
317 }
318
319 DEFUN ("read-event", Fread_event, Sread_event, 0, 0, 0,
320 "Read an event object from the input stream.")
321 ()
322 {
323 return read_filtered_event (0, 0, 0);
324 }
325
326 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 0, 0,
327 "Read a character from the command input (keyboard or macro).\n\
328 It is returned as a number. Non character events are ignored.")
329 ()
330 {
331 return read_filtered_event (1, 1, 0);
332 }
333
334 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
335 "Don't use this yourself.")
336 ()
337 {
338 register Lisp_Object val;
339 XSETINT (val, getc (instream));
340 return val;
341 }
342 \f
343 static void readevalloop ();
344 static Lisp_Object load_unwind ();
345 static Lisp_Object load_descriptor_unwind ();
346
347 DEFUN ("load", Fload, Sload, 1, 4, 0,
348 "Execute a file of Lisp code named FILE.\n\
349 First try FILE with `.elc' appended, then try with `.el',\n\
350 then try FILE unmodified.\n\
351 This function searches the directories in `load-path'.\n\
352 If optional second arg NOERROR is non-nil,\n\
353 report no error if FILE doesn't exist.\n\
354 Print messages at start and end of loading unless\n\
355 optional third arg NOMESSAGE is non-nil.\n\
356 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
357 suffixes `.elc' or `.el' to the specified name FILE.\n\
358 Return t if file exists.")
359 (str, noerror, nomessage, nosuffix)
360 Lisp_Object str, noerror, nomessage, nosuffix;
361 {
362 register FILE *stream;
363 register int fd = -1;
364 register Lisp_Object lispstream;
365 int count = specpdl_ptr - specpdl;
366 Lisp_Object temp;
367 struct gcpro gcpro1;
368 Lisp_Object found;
369 /* 1 means inhibit the message at the beginning. */
370 int nomessage1 = 0;
371 Lisp_Object handler;
372 #ifdef DOS_NT
373 char *dosmode = "rt";
374 #endif /* DOS_NT */
375
376 CHECK_STRING (str, 0);
377
378 /* If file name is magic, call the handler. */
379 handler = Ffind_file_name_handler (str, Qload);
380 if (!NILP (handler))
381 return call5 (handler, Qload, str, noerror, nomessage, nosuffix);
382
383 /* Do this after the handler to avoid
384 the need to gcpro noerror, nomessage and nosuffix.
385 (Below here, we care only whether they are nil or not.) */
386 str = Fsubstitute_in_file_name (str);
387
388 /* Avoid weird lossage with null string as arg,
389 since it would try to load a directory as a Lisp file */
390 if (XSTRING (str)->size > 0)
391 {
392 GCPRO1 (str);
393 fd = openp (Vload_path, str, !NILP (nosuffix) ? "" : ".elc:.el:",
394 &found, 0);
395 UNGCPRO;
396 }
397
398 if (fd < 0)
399 {
400 if (NILP (noerror))
401 while (1)
402 Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"),
403 Fcons (str, Qnil)));
404 else
405 return Qnil;
406 }
407
408 if (!bcmp (&(XSTRING (found)->data[XSTRING (found)->size - 4]),
409 ".elc", 4))
410 {
411 struct stat s1, s2;
412 int result;
413
414 #ifdef DOS_NT
415 dosmode = "rb";
416 #endif /* DOS_NT */
417 stat ((char *)XSTRING (found)->data, &s1);
418 XSTRING (found)->data[XSTRING (found)->size - 1] = 0;
419 result = stat ((char *)XSTRING (found)->data, &s2);
420 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
421 {
422 message ("Source file `%s' newer than byte-compiled file",
423 XSTRING (found)->data);
424 /* Don't immediately overwrite this message. */
425 if (!noninteractive)
426 nomessage1 = 1;
427 }
428 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c';
429 }
430
431 #ifdef DOS_NT
432 close (fd);
433 stream = fopen ((char *) XSTRING (found)->data, dosmode);
434 #else /* not DOS_NT */
435 stream = fdopen (fd, "r");
436 #endif /* not DOS_NT */
437 if (stream == 0)
438 {
439 close (fd);
440 error ("Failure to create stdio stream for %s", XSTRING (str)->data);
441 }
442
443 if (NILP (nomessage) && !nomessage1)
444 message ("Loading %s...", XSTRING (str)->data);
445
446 GCPRO1 (str);
447 lispstream = Fcons (Qnil, Qnil);
448 XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16);
449 XSETFASTINT (XCONS (lispstream)->cdr, (EMACS_UINT)stream & 0xffff);
450 record_unwind_protect (load_unwind, lispstream);
451 record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
452 specbind (Qload_file_name, found);
453 load_descriptor_list
454 = Fcons (make_number (fileno (stream)), load_descriptor_list);
455 load_in_progress++;
456 readevalloop (Qget_file_char, stream, str, Feval, 0);
457 unbind_to (count, Qnil);
458
459 /* Run any load-hooks for this file. */
460 temp = Fassoc (str, Vafter_load_alist);
461 if (!NILP (temp))
462 Fprogn (Fcdr (temp));
463 UNGCPRO;
464
465 if (!noninteractive && NILP (nomessage))
466 message ("Loading %s...done", XSTRING (str)->data);
467 return Qt;
468 }
469
470 static Lisp_Object
471 load_unwind (stream) /* used as unwind-protect function in load */
472 Lisp_Object stream;
473 {
474 fclose ((FILE *) (XFASTINT (XCONS (stream)->car) << 16
475 | XFASTINT (XCONS (stream)->cdr)));
476 if (--load_in_progress < 0) load_in_progress = 0;
477 return Qnil;
478 }
479
480 static Lisp_Object
481 load_descriptor_unwind (oldlist)
482 Lisp_Object oldlist;
483 {
484 load_descriptor_list = oldlist;
485 return Qnil;
486 }
487
488 /* Close all descriptors in use for Floads.
489 This is used when starting a subprocess. */
490
491 void
492 close_load_descs ()
493 {
494 Lisp_Object tail;
495 for (tail = load_descriptor_list; !NILP (tail); tail = XCONS (tail)->cdr)
496 close (XFASTINT (XCONS (tail)->car));
497 }
498 \f
499 static int
500 complete_filename_p (pathname)
501 Lisp_Object pathname;
502 {
503 register unsigned char *s = XSTRING (pathname)->data;
504 return (IS_DIRECTORY_SEP (s[0])
505 || (XSTRING (pathname)->size > 2
506 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
507 #ifdef ALTOS
508 || *s == '@'
509 #endif
510 #ifdef VMS
511 || index (s, ':')
512 #endif /* VMS */
513 );
514 }
515
516 /* Search for a file whose name is STR, looking in directories
517 in the Lisp list PATH, and trying suffixes from SUFFIX.
518 SUFFIX is a string containing possible suffixes separated by colons.
519 On success, returns a file descriptor. On failure, returns -1.
520
521 EXEC_ONLY nonzero means don't open the files,
522 just look for one that is executable. In this case,
523 returns 1 on success.
524
525 If STOREPTR is nonzero, it points to a slot where the name of
526 the file actually found should be stored as a Lisp string.
527 Nil is stored there on failure. */
528
529 int
530 openp (path, str, suffix, storeptr, exec_only)
531 Lisp_Object path, str;
532 char *suffix;
533 Lisp_Object *storeptr;
534 int exec_only;
535 {
536 register int fd;
537 int fn_size = 100;
538 char buf[100];
539 register char *fn = buf;
540 int absolute = 0;
541 int want_size;
542 register Lisp_Object filename;
543 struct stat st;
544 struct gcpro gcpro1;
545
546 GCPRO1 (str);
547 if (storeptr)
548 *storeptr = Qnil;
549
550 if (complete_filename_p (str))
551 absolute = 1;
552
553 for (; !NILP (path); path = Fcdr (path))
554 {
555 char *nsuffix;
556
557 filename = Fexpand_file_name (str, Fcar (path));
558 if (!complete_filename_p (filename))
559 /* If there are non-absolute elts in PATH (eg ".") */
560 /* Of course, this could conceivably lose if luser sets
561 default-directory to be something non-absolute... */
562 {
563 filename = Fexpand_file_name (filename, current_buffer->directory);
564 if (!complete_filename_p (filename))
565 /* Give up on this path element! */
566 continue;
567 }
568
569 /* Calculate maximum size of any filename made from
570 this path element/specified file name and any possible suffix. */
571 want_size = strlen (suffix) + XSTRING (filename)->size + 1;
572 if (fn_size < want_size)
573 fn = (char *) alloca (fn_size = 100 + want_size);
574
575 nsuffix = suffix;
576
577 /* Loop over suffixes. */
578 while (1)
579 {
580 char *esuffix = (char *) index (nsuffix, ':');
581 int lsuffix = esuffix ? esuffix - nsuffix : strlen (nsuffix);
582
583 /* Concatenate path element/specified name with the suffix. */
584 strncpy (fn, XSTRING (filename)->data, XSTRING (filename)->size);
585 fn[XSTRING (filename)->size] = 0;
586 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
587 strncat (fn, nsuffix, lsuffix);
588
589 /* Ignore file if it's a directory. */
590 if (stat (fn, &st) >= 0
591 && (st.st_mode & S_IFMT) != S_IFDIR)
592 {
593 /* Check that we can access or open it. */
594 if (exec_only)
595 fd = (access (fn, X_OK) == 0) ? 1 : -1;
596 else
597 fd = open (fn, O_RDONLY, 0);
598
599 if (fd >= 0)
600 {
601 /* We succeeded; return this descriptor and filename. */
602 if (storeptr)
603 *storeptr = build_string (fn);
604 UNGCPRO;
605 return fd;
606 }
607 }
608
609 /* Advance to next suffix. */
610 if (esuffix == 0)
611 break;
612 nsuffix += lsuffix + 1;
613 }
614 if (absolute)
615 break;
616 }
617
618 UNGCPRO;
619 return -1;
620 }
621
622 \f
623 /* Merge the list we've accumulated of globals from the current input source
624 into the load_history variable. The details depend on whether
625 the source has an associated file name or not. */
626
627 static void
628 build_load_history (stream, source)
629 FILE *stream;
630 Lisp_Object source;
631 {
632 register Lisp_Object tail, prev, newelt;
633 register Lisp_Object tem, tem2;
634 register int foundit, loading;
635
636 /* Don't bother recording anything for preloaded files. */
637 if (!NILP (Vpurify_flag))
638 return;
639
640 loading = stream || !NARROWED;
641
642 tail = Vload_history;
643 prev = Qnil;
644 foundit = 0;
645 while (!NILP (tail))
646 {
647 tem = Fcar (tail);
648
649 /* Find the feature's previous assoc list... */
650 if (!NILP (Fequal (source, Fcar (tem))))
651 {
652 foundit = 1;
653
654 /* If we're loading, remove it. */
655 if (loading)
656 {
657 if (NILP (prev))
658 Vload_history = Fcdr (tail);
659 else
660 Fsetcdr (prev, Fcdr (tail));
661 }
662
663 /* Otherwise, cons on new symbols that are not already members. */
664 else
665 {
666 tem2 = Vcurrent_load_list;
667
668 while (CONSP (tem2))
669 {
670 newelt = Fcar (tem2);
671
672 if (NILP (Fmemq (newelt, tem)))
673 Fsetcar (tail, Fcons (Fcar (tem),
674 Fcons (newelt, Fcdr (tem))));
675
676 tem2 = Fcdr (tem2);
677 QUIT;
678 }
679 }
680 }
681 else
682 prev = tail;
683 tail = Fcdr (tail);
684 QUIT;
685 }
686
687 /* If we're loading, cons the new assoc onto the front of load-history,
688 the most-recently-loaded position. Also do this if we didn't find
689 an existing member for the current source. */
690 if (loading || !foundit)
691 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
692 Vload_history);
693 }
694
695 Lisp_Object
696 unreadpure () /* Used as unwind-protect function in readevalloop */
697 {
698 read_pure = 0;
699 return Qnil;
700 }
701
702 static void
703 readevalloop (readcharfun, stream, sourcename, evalfun, printflag)
704 Lisp_Object readcharfun;
705 FILE *stream;
706 Lisp_Object sourcename;
707 Lisp_Object (*evalfun) ();
708 int printflag;
709 {
710 register int c;
711 register Lisp_Object val;
712 int count = specpdl_ptr - specpdl;
713 struct gcpro gcpro1;
714 struct buffer *b = 0;
715
716 if (BUFFERP (readcharfun))
717 b = XBUFFER (readcharfun);
718 else if (MARKERP (readcharfun))
719 b = XMARKER (readcharfun)->buffer;
720
721 specbind (Qstandard_input, readcharfun);
722 specbind (Qcurrent_load_list, Qnil);
723
724 GCPRO1 (sourcename);
725
726 LOADHIST_ATTACH (sourcename);
727
728 while (1)
729 {
730 if (b != 0 && NILP (b->name))
731 error ("Reading from killed buffer");
732
733 instream = stream;
734 c = READCHAR;
735 if (c == ';')
736 {
737 while ((c = READCHAR) != '\n' && c != -1);
738 continue;
739 }
740 if (c < 0) break;
741
742 /* Ignore whitespace here, so we can detect eof. */
743 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
744 continue;
745
746 if (!NILP (Vpurify_flag) && c == '(')
747 {
748 int count1 = specpdl_ptr - specpdl;
749 record_unwind_protect (unreadpure, Qnil);
750 val = read_list (-1, readcharfun);
751 unbind_to (count1, Qnil);
752 }
753 else
754 {
755 UNREAD (c);
756 if (NILP (Vload_read_function))
757 val = read0 (readcharfun);
758 else
759 val = call1 (Vload_read_function, readcharfun);
760 }
761
762 val = (*evalfun) (val);
763 if (printflag)
764 {
765 Vvalues = Fcons (val, Vvalues);
766 if (EQ (Vstandard_output, Qt))
767 Fprin1 (val, Qnil);
768 else
769 Fprint (val, Qnil);
770 }
771 }
772
773 build_load_history (stream, sourcename);
774 UNGCPRO;
775
776 unbind_to (count, Qnil);
777 }
778
779 #ifndef standalone
780
781 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 2, "",
782 "Execute the current buffer as Lisp code.\n\
783 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
784 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
785 PRINTFLAG controls printing of output:\n\
786 nil means discard it; anything else is stream for print.\n\
787 \n\
788 If there is no error, point does not move. If there is an error,\n\
789 point remains at the end of the last character read from the buffer.")
790 (bufname, printflag)
791 Lisp_Object bufname, printflag;
792 {
793 int count = specpdl_ptr - specpdl;
794 Lisp_Object tem, buf;
795
796 if (NILP (bufname))
797 buf = Fcurrent_buffer ();
798 else
799 buf = Fget_buffer (bufname);
800 if (NILP (buf))
801 error ("No such buffer.");
802
803 if (NILP (printflag))
804 tem = Qsymbolp;
805 else
806 tem = printflag;
807 specbind (Qstandard_output, tem);
808 record_unwind_protect (save_excursion_restore, save_excursion_save ());
809 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
810 readevalloop (buf, 0, XBUFFER (buf)->filename, Feval, !NILP (printflag));
811 unbind_to (count, Qnil);
812
813 return Qnil;
814 }
815
816 #if 0
817 DEFUN ("eval-current-buffer", Feval_current_buffer, Seval_current_buffer, 0, 1, "",
818 "Execute the current buffer as Lisp code.\n\
819 Programs can pass argument PRINTFLAG which controls printing of output:\n\
820 nil means discard it; anything else is stream for print.\n\
821 \n\
822 If there is no error, point does not move. If there is an error,\n\
823 point remains at the end of the last character read from the buffer.")
824 (printflag)
825 Lisp_Object printflag;
826 {
827 int count = specpdl_ptr - specpdl;
828 Lisp_Object tem, cbuf;
829
830 cbuf = Fcurrent_buffer ()
831
832 if (NILP (printflag))
833 tem = Qsymbolp;
834 else
835 tem = printflag;
836 specbind (Qstandard_output, tem);
837 record_unwind_protect (save_excursion_restore, save_excursion_save ());
838 SET_PT (BEGV);
839 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, !NILP (printflag));
840 return unbind_to (count, Qnil);
841 }
842 #endif
843
844 DEFUN ("eval-region", Feval_region, Seval_region, 2, 3, "r",
845 "Execute the region as Lisp code.\n\
846 When called from programs, expects two arguments,\n\
847 giving starting and ending indices in the current buffer\n\
848 of the text to be executed.\n\
849 Programs can pass third argument PRINTFLAG which controls output:\n\
850 nil means discard it; anything else is stream for printing it.\n\
851 \n\
852 If there is no error, point does not move. If there is an error,\n\
853 point remains at the end of the last character read from the buffer.")
854 (b, e, printflag)
855 Lisp_Object b, e, printflag;
856 {
857 int count = specpdl_ptr - specpdl;
858 Lisp_Object tem, cbuf;
859
860 cbuf = Fcurrent_buffer ();
861
862 if (NILP (printflag))
863 tem = Qsymbolp;
864 else
865 tem = printflag;
866 specbind (Qstandard_output, tem);
867
868 if (NILP (printflag))
869 record_unwind_protect (save_excursion_restore, save_excursion_save ());
870 record_unwind_protect (save_restriction_restore, save_restriction_save ());
871
872 /* This both uses b and checks its type. */
873 Fgoto_char (b);
874 Fnarrow_to_region (make_number (BEGV), e);
875 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, !NILP (printflag));
876
877 return unbind_to (count, Qnil);
878 }
879
880 #endif /* standalone */
881 \f
882 DEFUN ("read", Fread, Sread, 0, 1, 0,
883 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
884 If STREAM is nil, use the value of `standard-input' (which see).\n\
885 STREAM or the value of `standard-input' may be:\n\
886 a buffer (read from point and advance it)\n\
887 a marker (read from where it points and advance it)\n\
888 a function (call it with no arguments for each character,\n\
889 call it with a char as argument to push a char back)\n\
890 a string (takes text from string, starting at the beginning)\n\
891 t (read text line using minibuffer and use it).")
892 (stream)
893 Lisp_Object stream;
894 {
895 extern Lisp_Object Fread_minibuffer ();
896
897 if (NILP (stream))
898 stream = Vstandard_input;
899 if (EQ (stream, Qt))
900 stream = Qread_char;
901
902 new_backquote_flag = 0;
903
904 #ifndef standalone
905 if (EQ (stream, Qread_char))
906 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
907 #endif
908
909 if (STRINGP (stream))
910 return Fcar (Fread_from_string (stream, Qnil, Qnil));
911
912 return read0 (stream);
913 }
914
915 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
916 "Read one Lisp expression which is represented as text by STRING.\n\
917 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
918 START and END optionally delimit a substring of STRING from which to read;\n\
919 they default to 0 and (length STRING) respectively.")
920 (string, start, end)
921 Lisp_Object string, start, end;
922 {
923 int startval, endval;
924 Lisp_Object tem;
925
926 CHECK_STRING (string,0);
927
928 if (NILP (end))
929 endval = XSTRING (string)->size;
930 else
931 { CHECK_NUMBER (end,2);
932 endval = XINT (end);
933 if (endval < 0 || endval > XSTRING (string)->size)
934 args_out_of_range (string, end);
935 }
936
937 if (NILP (start))
938 startval = 0;
939 else
940 { CHECK_NUMBER (start,1);
941 startval = XINT (start);
942 if (startval < 0 || startval > endval)
943 args_out_of_range (string, start);
944 }
945
946 read_from_string_index = startval;
947 read_from_string_limit = endval;
948
949 new_backquote_flag = 0;
950
951 tem = read0 (string);
952 return Fcons (tem, make_number (read_from_string_index));
953 }
954 \f
955 /* Use this for recursive reads, in contexts where internal tokens
956 are not allowed. */
957 static Lisp_Object
958 read0 (readcharfun)
959 Lisp_Object readcharfun;
960 {
961 register Lisp_Object val;
962 char c;
963
964 val = read1 (readcharfun, &c, 0);
965 if (c)
966 Fsignal (Qinvalid_read_syntax, Fcons (make_string (&c, 1), Qnil));
967
968 return val;
969 }
970 \f
971 static int read_buffer_size;
972 static char *read_buffer;
973
974 static int
975 read_escape (readcharfun)
976 Lisp_Object readcharfun;
977 {
978 register int c = READCHAR;
979 switch (c)
980 {
981 case 'a':
982 return '\007';
983 case 'b':
984 return '\b';
985 case 'd':
986 return 0177;
987 case 'e':
988 return 033;
989 case 'f':
990 return '\f';
991 case 'n':
992 return '\n';
993 case 'r':
994 return '\r';
995 case 't':
996 return '\t';
997 case 'v':
998 return '\v';
999 case '\n':
1000 return -1;
1001
1002 case 'M':
1003 c = READCHAR;
1004 if (c != '-')
1005 error ("Invalid escape character syntax");
1006 c = READCHAR;
1007 if (c == '\\')
1008 c = read_escape (readcharfun);
1009 return c | meta_modifier;
1010
1011 case 'S':
1012 c = READCHAR;
1013 if (c != '-')
1014 error ("Invalid escape character syntax");
1015 c = READCHAR;
1016 if (c == '\\')
1017 c = read_escape (readcharfun);
1018 return c | shift_modifier;
1019
1020 case 'H':
1021 c = READCHAR;
1022 if (c != '-')
1023 error ("Invalid escape character syntax");
1024 c = READCHAR;
1025 if (c == '\\')
1026 c = read_escape (readcharfun);
1027 return c | hyper_modifier;
1028
1029 case 'A':
1030 c = READCHAR;
1031 if (c != '-')
1032 error ("Invalid escape character syntax");
1033 c = READCHAR;
1034 if (c == '\\')
1035 c = read_escape (readcharfun);
1036 return c | alt_modifier;
1037
1038 case 's':
1039 c = READCHAR;
1040 if (c != '-')
1041 error ("Invalid escape character syntax");
1042 c = READCHAR;
1043 if (c == '\\')
1044 c = read_escape (readcharfun);
1045 return c | super_modifier;
1046
1047 case 'C':
1048 c = READCHAR;
1049 if (c != '-')
1050 error ("Invalid escape character syntax");
1051 case '^':
1052 c = READCHAR;
1053 if (c == '\\')
1054 c = read_escape (readcharfun);
1055 if ((c & 0177) == '?')
1056 return 0177 | c;
1057 /* ASCII control chars are made from letters (both cases),
1058 as well as the non-letters within 0100...0137. */
1059 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
1060 return (c & (037 | ~0177));
1061 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
1062 return (c & (037 | ~0177));
1063 else
1064 return c | ctrl_modifier;
1065
1066 case '0':
1067 case '1':
1068 case '2':
1069 case '3':
1070 case '4':
1071 case '5':
1072 case '6':
1073 case '7':
1074 /* An octal escape, as in ANSI C. */
1075 {
1076 register int i = c - '0';
1077 register int count = 0;
1078 while (++count < 3)
1079 {
1080 if ((c = READCHAR) >= '0' && c <= '7')
1081 {
1082 i *= 8;
1083 i += c - '0';
1084 }
1085 else
1086 {
1087 UNREAD (c);
1088 break;
1089 }
1090 }
1091 return i;
1092 }
1093
1094 case 'x':
1095 /* A hex escape, as in ANSI C. */
1096 {
1097 int i = 0;
1098 while (1)
1099 {
1100 c = READCHAR;
1101 if (c >= '0' && c <= '9')
1102 {
1103 i *= 16;
1104 i += c - '0';
1105 }
1106 else if ((c >= 'a' && c <= 'f')
1107 || (c >= 'A' && c <= 'F'))
1108 {
1109 i *= 16;
1110 if (c >= 'a' && c <= 'f')
1111 i += c - 'a' + 10;
1112 else
1113 i += c - 'A' + 10;
1114 }
1115 else
1116 {
1117 UNREAD (c);
1118 break;
1119 }
1120 }
1121 return i;
1122 }
1123
1124 default:
1125 return c;
1126 }
1127 }
1128
1129 /* If the next token is ')' or ']' or '.', we store that character
1130 in *PCH and the return value is not interesting. Else, we store
1131 zero in *PCH and we read and return one lisp object.
1132
1133 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1134
1135 static Lisp_Object
1136 read1 (readcharfun, pch, first_in_list)
1137 register Lisp_Object readcharfun;
1138 char *pch;
1139 int first_in_list;
1140 {
1141 register int c;
1142 *pch = 0;
1143
1144 retry:
1145
1146 c = READCHAR;
1147 if (c < 0) return Fsignal (Qend_of_file, Qnil);
1148
1149 switch (c)
1150 {
1151 case '(':
1152 return read_list (0, readcharfun);
1153
1154 case '[':
1155 return read_vector (readcharfun);
1156
1157 case ')':
1158 case ']':
1159 {
1160 *pch = c;
1161 return Qnil;
1162 }
1163
1164 case '#':
1165 c = READCHAR;
1166 if (c == '[')
1167 {
1168 /* Accept compiled functions at read-time so that we don't have to
1169 build them using function calls. */
1170 Lisp_Object tmp;
1171 tmp = read_vector (readcharfun);
1172 return Fmake_byte_code (XVECTOR (tmp)->size,
1173 XVECTOR (tmp)->contents);
1174 }
1175 #ifdef USE_TEXT_PROPERTIES
1176 if (c == '(')
1177 {
1178 Lisp_Object tmp;
1179 struct gcpro gcpro1;
1180 char ch;
1181
1182 /* Read the string itself. */
1183 tmp = read1 (readcharfun, &ch, 0);
1184 if (ch != 0 || !STRINGP (tmp))
1185 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
1186 GCPRO1 (tmp);
1187 /* Read the intervals and their properties. */
1188 while (1)
1189 {
1190 Lisp_Object beg, end, plist;
1191
1192 beg = read1 (readcharfun, &ch, 0);
1193 if (ch == ')')
1194 break;
1195 if (ch == 0)
1196 end = read1 (readcharfun, &ch, 0);
1197 if (ch == 0)
1198 plist = read1 (readcharfun, &ch, 0);
1199 if (ch)
1200 Fsignal (Qinvalid_read_syntax,
1201 Fcons (build_string ("invalid string property list"),
1202 Qnil));
1203 Fset_text_properties (beg, end, plist, tmp);
1204 }
1205 UNGCPRO;
1206 return tmp;
1207 }
1208 #endif
1209 /* #@NUMBER is used to skip NUMBER following characters.
1210 That's used in .elc files to skip over doc strings
1211 and function definitions. */
1212 if (c == '@')
1213 {
1214 int i, nskip = 0;
1215
1216 /* Read a decimal integer. */
1217 while ((c = READCHAR) >= 0
1218 && c >= '0' && c <= '9')
1219 {
1220 nskip *= 10;
1221 nskip += c - '0';
1222 }
1223 if (c >= 0)
1224 UNREAD (c);
1225
1226 /* Skip that many characters. */
1227 for (i = 0; i < nskip && c >= 0; i++)
1228 c = READCHAR;
1229 goto retry;
1230 }
1231 if (c == '$')
1232 return Vload_file_name;
1233
1234 UNREAD (c);
1235 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
1236
1237 case ';':
1238 while ((c = READCHAR) >= 0 && c != '\n');
1239 goto retry;
1240
1241 case '\'':
1242 {
1243 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
1244 }
1245
1246 case '`':
1247 if (first_in_list)
1248 goto default_label;
1249 else
1250 {
1251 Lisp_Object value;
1252
1253 new_backquote_flag = 1;
1254 value = read0 (readcharfun);
1255 new_backquote_flag = 0;
1256
1257 return Fcons (Qbackquote, Fcons (value, Qnil));
1258 }
1259
1260 case ',':
1261 if (new_backquote_flag)
1262 {
1263 Lisp_Object comma_type = Qnil;
1264 Lisp_Object value;
1265 int ch = READCHAR;
1266
1267 if (ch == '@')
1268 comma_type = Qcomma_at;
1269 else if (ch == '.')
1270 comma_type = Qcomma_dot;
1271 else
1272 {
1273 if (ch >= 0) UNREAD (ch);
1274 comma_type = Qcomma;
1275 }
1276
1277 new_backquote_flag = 0;
1278 value = read0 (readcharfun);
1279 new_backquote_flag = 1;
1280 return Fcons (comma_type, Fcons (value, Qnil));
1281 }
1282 else
1283 goto default_label;
1284
1285 case '?':
1286 {
1287 register Lisp_Object val;
1288
1289 c = READCHAR;
1290 if (c < 0) return Fsignal (Qend_of_file, Qnil);
1291
1292 if (c == '\\')
1293 XSETINT (val, read_escape (readcharfun));
1294 else
1295 XSETINT (val, c);
1296
1297 return val;
1298 }
1299
1300 case '\"':
1301 {
1302 register char *p = read_buffer;
1303 register char *end = read_buffer + read_buffer_size;
1304 register int c;
1305 int cancel = 0;
1306
1307 while ((c = READCHAR) >= 0
1308 && c != '\"')
1309 {
1310 if (p == end)
1311 {
1312 char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
1313 p += new - read_buffer;
1314 read_buffer += new - read_buffer;
1315 end = read_buffer + read_buffer_size;
1316 }
1317 if (c == '\\')
1318 c = read_escape (readcharfun);
1319 /* c is -1 if \ newline has just been seen */
1320 if (c == -1)
1321 {
1322 if (p == read_buffer)
1323 cancel = 1;
1324 }
1325 else
1326 {
1327 /* Allow `\C- ' and `\C-?'. */
1328 if (c == (CHAR_CTL | ' '))
1329 c = 0;
1330 else if (c == (CHAR_CTL | '?'))
1331 c = 127;
1332
1333 if (c & CHAR_META)
1334 /* Move the meta bit to the right place for a string. */
1335 c = (c & ~CHAR_META) | 0x80;
1336 if (c & ~0xff)
1337 error ("Invalid modifier in string");
1338 *p++ = c;
1339 }
1340 }
1341 if (c < 0) return Fsignal (Qend_of_file, Qnil);
1342
1343 /* If purifying, and string starts with \ newline,
1344 return zero instead. This is for doc strings
1345 that we are really going to find in etc/DOC.nn.nn */
1346 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
1347 return make_number (0);
1348
1349 if (read_pure)
1350 return make_pure_string (read_buffer, p - read_buffer);
1351 else
1352 return make_string (read_buffer, p - read_buffer);
1353 }
1354
1355 case '.':
1356 {
1357 #ifdef LISP_FLOAT_TYPE
1358 /* If a period is followed by a number, then we should read it
1359 as a floating point number. Otherwise, it denotes a dotted
1360 pair. */
1361 int next_char = READCHAR;
1362 UNREAD (next_char);
1363
1364 if (! (next_char >= '0' && next_char <= '9'))
1365 #endif
1366 {
1367 *pch = c;
1368 return Qnil;
1369 }
1370
1371 /* Otherwise, we fall through! Note that the atom-reading loop
1372 below will now loop at least once, assuring that we will not
1373 try to UNREAD two characters in a row. */
1374 }
1375 default:
1376 default_label:
1377 if (c <= 040) goto retry;
1378 {
1379 register char *p = read_buffer;
1380 int quoted = 0;
1381
1382 {
1383 register char *end = read_buffer + read_buffer_size;
1384
1385 while (c > 040 &&
1386 !(c == '\"' || c == '\'' || c == ';' || c == '?'
1387 || c == '(' || c == ')'
1388 #ifndef LISP_FLOAT_TYPE
1389 /* If we have floating-point support, then we need
1390 to allow <digits><dot><digits>. */
1391 || c =='.'
1392 #endif /* not LISP_FLOAT_TYPE */
1393 || c == '[' || c == ']' || c == '#'
1394 ))
1395 {
1396 if (p == end)
1397 {
1398 register char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
1399 p += new - read_buffer;
1400 read_buffer += new - read_buffer;
1401 end = read_buffer + read_buffer_size;
1402 }
1403 if (c == '\\')
1404 {
1405 c = READCHAR;
1406 quoted = 1;
1407 }
1408 *p++ = c;
1409 c = READCHAR;
1410 }
1411
1412 if (p == end)
1413 {
1414 char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
1415 p += new - read_buffer;
1416 read_buffer += new - read_buffer;
1417 /* end = read_buffer + read_buffer_size; */
1418 }
1419 *p = 0;
1420 if (c >= 0)
1421 UNREAD (c);
1422 }
1423
1424 if (!quoted)
1425 {
1426 register char *p1;
1427 register Lisp_Object val;
1428 p1 = read_buffer;
1429 if (*p1 == '+' || *p1 == '-') p1++;
1430 /* Is it an integer? */
1431 if (p1 != p)
1432 {
1433 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
1434 #ifdef LISP_FLOAT_TYPE
1435 /* Integers can have trailing decimal points. */
1436 if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
1437 #endif
1438 if (p1 == p)
1439 /* It is an integer. */
1440 {
1441 #ifdef LISP_FLOAT_TYPE
1442 if (p1[-1] == '.')
1443 p1[-1] = '\0';
1444 #endif
1445 if (sizeof (int) == sizeof (EMACS_INT))
1446 XSETINT (val, atoi (read_buffer));
1447 else if (sizeof (long) == sizeof (EMACS_INT))
1448 XSETINT (val, atol (read_buffer));
1449 else
1450 abort ();
1451 return val;
1452 }
1453 }
1454 #ifdef LISP_FLOAT_TYPE
1455 if (isfloat_string (read_buffer))
1456 return make_float (atof (read_buffer));
1457 #endif
1458 }
1459
1460 return intern (read_buffer);
1461 }
1462 }
1463 }
1464 \f
1465 #ifdef LISP_FLOAT_TYPE
1466
1467 #define LEAD_INT 1
1468 #define DOT_CHAR 2
1469 #define TRAIL_INT 4
1470 #define E_CHAR 8
1471 #define EXP_INT 16
1472
1473 int
1474 isfloat_string (cp)
1475 register char *cp;
1476 {
1477 register state;
1478
1479 state = 0;
1480 if (*cp == '+' || *cp == '-')
1481 cp++;
1482
1483 if (*cp >= '0' && *cp <= '9')
1484 {
1485 state |= LEAD_INT;
1486 while (*cp >= '0' && *cp <= '9')
1487 cp++;
1488 }
1489 if (*cp == '.')
1490 {
1491 state |= DOT_CHAR;
1492 cp++;
1493 }
1494 if (*cp >= '0' && *cp <= '9')
1495 {
1496 state |= TRAIL_INT;
1497 while (*cp >= '0' && *cp <= '9')
1498 cp++;
1499 }
1500 if (*cp == 'e')
1501 {
1502 state |= E_CHAR;
1503 cp++;
1504 if (*cp == '+' || *cp == '-')
1505 cp++;
1506 }
1507
1508 if (*cp >= '0' && *cp <= '9')
1509 {
1510 state |= EXP_INT;
1511 while (*cp >= '0' && *cp <= '9')
1512 cp++;
1513 }
1514 return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
1515 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
1516 || state == (DOT_CHAR|TRAIL_INT)
1517 || state == (LEAD_INT|E_CHAR|EXP_INT)
1518 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
1519 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
1520 }
1521 #endif /* LISP_FLOAT_TYPE */
1522 \f
1523 static Lisp_Object
1524 read_vector (readcharfun)
1525 Lisp_Object readcharfun;
1526 {
1527 register int i;
1528 register int size;
1529 register Lisp_Object *ptr;
1530 register Lisp_Object tem, vector;
1531 register struct Lisp_Cons *otem;
1532 Lisp_Object len;
1533
1534 tem = read_list (1, readcharfun);
1535 len = Flength (tem);
1536 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
1537
1538
1539 size = XVECTOR (vector)->size;
1540 ptr = XVECTOR (vector)->contents;
1541 for (i = 0; i < size; i++)
1542 {
1543 ptr[i] = read_pure ? Fpurecopy (Fcar (tem)) : Fcar (tem);
1544 otem = XCONS (tem);
1545 tem = Fcdr (tem);
1546 free_cons (otem);
1547 }
1548 return vector;
1549 }
1550
1551 /* flag = 1 means check for ] to terminate rather than ) and .
1552 flag = -1 means check for starting with defun
1553 and make structure pure. */
1554
1555 static Lisp_Object
1556 read_list (flag, readcharfun)
1557 int flag;
1558 register Lisp_Object readcharfun;
1559 {
1560 /* -1 means check next element for defun,
1561 0 means don't check,
1562 1 means already checked and found defun. */
1563 int defunflag = flag < 0 ? -1 : 0;
1564 Lisp_Object val, tail;
1565 register Lisp_Object elt, tem;
1566 struct gcpro gcpro1, gcpro2;
1567 int cancel = 0;
1568
1569 /* Initialize this to 1 if we are reading a list. */
1570 int first_in_list = flag <= 0;
1571
1572 val = Qnil;
1573 tail = Qnil;
1574
1575 while (1)
1576 {
1577 char ch;
1578 GCPRO2 (val, tail);
1579 elt = read1 (readcharfun, &ch, first_in_list);
1580 UNGCPRO;
1581
1582 first_in_list = 0;
1583
1584 /* If purifying, and the list starts with #$,
1585 return 0 instead. This is a doc string reference
1586 and it will be replaced anyway by Snarf-documentation,
1587 so don't waste pure space with it. */
1588 if (EQ (elt, Vload_file_name)
1589 && !NILP (Vpurify_flag) && NILP (Vdoc_file_name))
1590 cancel = 1;
1591
1592 if (ch)
1593 {
1594 if (flag > 0)
1595 {
1596 if (ch == ']')
1597 return val;
1598 Fsignal (Qinvalid_read_syntax, Fcons (make_string (") or . in a vector", 18), Qnil));
1599 }
1600 if (ch == ')')
1601 return val;
1602 if (ch == '.')
1603 {
1604 GCPRO2 (val, tail);
1605 if (!NILP (tail))
1606 XCONS (tail)->cdr = read0 (readcharfun);
1607 else
1608 val = read0 (readcharfun);
1609 read1 (readcharfun, &ch, 0);
1610 UNGCPRO;
1611 if (ch == ')')
1612 return (cancel ? make_number (0) : val);
1613 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil));
1614 }
1615 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil));
1616 }
1617 tem = (read_pure && flag <= 0
1618 ? pure_cons (elt, Qnil)
1619 : Fcons (elt, Qnil));
1620 if (!NILP (tail))
1621 XCONS (tail)->cdr = tem;
1622 else
1623 val = tem;
1624 tail = tem;
1625 if (defunflag < 0)
1626 defunflag = EQ (elt, Qdefun);
1627 else if (defunflag > 0)
1628 read_pure = 1;
1629 }
1630 }
1631 \f
1632 Lisp_Object Vobarray;
1633 Lisp_Object initial_obarray;
1634
1635 /* oblookup stores the bucket number here, for the sake of Funintern. */
1636
1637 int oblookup_last_bucket_number;
1638
1639 static int hash_string ();
1640 Lisp_Object oblookup ();
1641
1642 /* Get an error if OBARRAY is not an obarray.
1643 If it is one, return it. */
1644
1645 Lisp_Object
1646 check_obarray (obarray)
1647 Lisp_Object obarray;
1648 {
1649 while (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
1650 {
1651 /* If Vobarray is now invalid, force it to be valid. */
1652 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
1653
1654 obarray = wrong_type_argument (Qvectorp, obarray);
1655 }
1656 return obarray;
1657 }
1658
1659 /* Intern the C string STR: return a symbol with that name,
1660 interned in the current obarray. */
1661
1662 Lisp_Object
1663 intern (str)
1664 char *str;
1665 {
1666 Lisp_Object tem;
1667 int len = strlen (str);
1668 Lisp_Object obarray;
1669
1670 obarray = Vobarray;
1671 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
1672 obarray = check_obarray (obarray);
1673 tem = oblookup (obarray, str, len);
1674 if (SYMBOLP (tem))
1675 return tem;
1676 return Fintern ((!NILP (Vpurify_flag)
1677 ? make_pure_string (str, len)
1678 : make_string (str, len)),
1679 obarray);
1680 }
1681 \f
1682 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
1683 "Return the canonical symbol whose name is STRING.\n\
1684 If there is none, one is created by this function and returned.\n\
1685 A second optional argument specifies the obarray to use;\n\
1686 it defaults to the value of `obarray'.")
1687 (str, obarray)
1688 Lisp_Object str, obarray;
1689 {
1690 register Lisp_Object tem, sym, *ptr;
1691
1692 if (NILP (obarray)) obarray = Vobarray;
1693 obarray = check_obarray (obarray);
1694
1695 CHECK_STRING (str, 0);
1696
1697 tem = oblookup (obarray, XSTRING (str)->data, XSTRING (str)->size);
1698 if (!INTEGERP (tem))
1699 return tem;
1700
1701 if (!NILP (Vpurify_flag))
1702 str = Fpurecopy (str);
1703 sym = Fmake_symbol (str);
1704
1705 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
1706 if (SYMBOLP (*ptr))
1707 XSYMBOL (sym)->next = XSYMBOL (*ptr);
1708 else
1709 XSYMBOL (sym)->next = 0;
1710 *ptr = sym;
1711 return sym;
1712 }
1713
1714 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
1715 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
1716 A second optional argument specifies the obarray to use;\n\
1717 it defaults to the value of `obarray'.")
1718 (str, obarray)
1719 Lisp_Object str, obarray;
1720 {
1721 register Lisp_Object tem;
1722
1723 if (NILP (obarray)) obarray = Vobarray;
1724 obarray = check_obarray (obarray);
1725
1726 CHECK_STRING (str, 0);
1727
1728 tem = oblookup (obarray, XSTRING (str)->data, XSTRING (str)->size);
1729 if (!INTEGERP (tem))
1730 return tem;
1731 return Qnil;
1732 }
1733 \f
1734 DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
1735 "Delete the symbol named NAME, if any, from OBARRAY.\n\
1736 The value is t if a symbol was found and deleted, nil otherwise.\n\
1737 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
1738 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
1739 OBARRAY defaults to the value of the variable `obarray'.")
1740 (name, obarray)
1741 Lisp_Object name, obarray;
1742 {
1743 register Lisp_Object string, tem;
1744 int hash;
1745
1746 if (NILP (obarray)) obarray = Vobarray;
1747 obarray = check_obarray (obarray);
1748
1749 if (SYMBOLP (name))
1750 XSETSTRING (string, XSYMBOL (name)->name);
1751 else
1752 {
1753 CHECK_STRING (name, 0);
1754 string = name;
1755 }
1756
1757 tem = oblookup (obarray, XSTRING (string)->data, XSTRING (string)->size);
1758 if (INTEGERP (tem))
1759 return Qnil;
1760 /* If arg was a symbol, don't delete anything but that symbol itself. */
1761 if (SYMBOLP (name) && !EQ (name, tem))
1762 return Qnil;
1763
1764 hash = oblookup_last_bucket_number;
1765
1766 if (EQ (XVECTOR (obarray)->contents[hash], tem))
1767 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
1768 else
1769 {
1770 Lisp_Object tail, following;
1771
1772 for (tail = XVECTOR (obarray)->contents[hash];
1773 XSYMBOL (tail)->next;
1774 tail = following)
1775 {
1776 XSETSYMBOL (following, XSYMBOL (tail)->next);
1777 if (EQ (following, tem))
1778 {
1779 XSYMBOL (tail)->next = XSYMBOL (following)->next;
1780 break;
1781 }
1782 }
1783 }
1784
1785 return Qt;
1786 }
1787 \f
1788 /* Return the symbol in OBARRAY whose names matches the string
1789 of SIZE characters at PTR. If there is no such symbol in OBARRAY,
1790 return nil.
1791
1792 Also store the bucket number in oblookup_last_bucket_number. */
1793
1794 Lisp_Object
1795 oblookup (obarray, ptr, size)
1796 Lisp_Object obarray;
1797 register char *ptr;
1798 register int size;
1799 {
1800 int hash;
1801 int obsize;
1802 register Lisp_Object tail;
1803 Lisp_Object bucket, tem;
1804
1805 if (!VECTORP (obarray)
1806 || (obsize = XVECTOR (obarray)->size) == 0)
1807 {
1808 obarray = check_obarray (obarray);
1809 obsize = XVECTOR (obarray)->size;
1810 }
1811 /* Combining next two lines breaks VMS C 2.3. */
1812 hash = hash_string (ptr, size);
1813 hash %= obsize;
1814 bucket = XVECTOR (obarray)->contents[hash];
1815 oblookup_last_bucket_number = hash;
1816 if (XFASTINT (bucket) == 0)
1817 ;
1818 else if (!SYMBOLP (bucket))
1819 error ("Bad data in guts of obarray"); /* Like CADR error message */
1820 else
1821 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
1822 {
1823 if (XSYMBOL (tail)->name->size == size
1824 && !bcmp (XSYMBOL (tail)->name->data, ptr, size))
1825 return tail;
1826 else if (XSYMBOL (tail)->next == 0)
1827 break;
1828 }
1829 XSETINT (tem, hash);
1830 return tem;
1831 }
1832
1833 static int
1834 hash_string (ptr, len)
1835 unsigned char *ptr;
1836 int len;
1837 {
1838 register unsigned char *p = ptr;
1839 register unsigned char *end = p + len;
1840 register unsigned char c;
1841 register int hash = 0;
1842
1843 while (p != end)
1844 {
1845 c = *p++;
1846 if (c >= 0140) c -= 40;
1847 hash = ((hash<<3) + (hash>>28) + c);
1848 }
1849 return hash & 07777777777;
1850 }
1851 \f
1852 void
1853 map_obarray (obarray, fn, arg)
1854 Lisp_Object obarray;
1855 int (*fn) ();
1856 Lisp_Object arg;
1857 {
1858 register int i;
1859 register Lisp_Object tail;
1860 CHECK_VECTOR (obarray, 1);
1861 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
1862 {
1863 tail = XVECTOR (obarray)->contents[i];
1864 if (XFASTINT (tail) != 0)
1865 while (1)
1866 {
1867 (*fn) (tail, arg);
1868 if (XSYMBOL (tail)->next == 0)
1869 break;
1870 XSETSYMBOL (tail, XSYMBOL (tail)->next);
1871 }
1872 }
1873 }
1874
1875 mapatoms_1 (sym, function)
1876 Lisp_Object sym, function;
1877 {
1878 call1 (function, sym);
1879 }
1880
1881 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
1882 "Call FUNCTION on every symbol in OBARRAY.\n\
1883 OBARRAY defaults to the value of `obarray'.")
1884 (function, obarray)
1885 Lisp_Object function, obarray;
1886 {
1887 Lisp_Object tem;
1888
1889 if (NILP (obarray)) obarray = Vobarray;
1890 obarray = check_obarray (obarray);
1891
1892 map_obarray (obarray, mapatoms_1, function);
1893 return Qnil;
1894 }
1895
1896 #define OBARRAY_SIZE 1511
1897
1898 void
1899 init_obarray ()
1900 {
1901 Lisp_Object oblength;
1902 int hash;
1903 Lisp_Object *tem;
1904
1905 XSETFASTINT (oblength, OBARRAY_SIZE);
1906
1907 Qnil = Fmake_symbol (make_pure_string ("nil", 3));
1908 Vobarray = Fmake_vector (oblength, make_number (0));
1909 initial_obarray = Vobarray;
1910 staticpro (&initial_obarray);
1911 /* Intern nil in the obarray */
1912 /* These locals are to kludge around a pyramid compiler bug. */
1913 hash = hash_string ("nil", 3);
1914 /* Separate statement here to avoid VAXC bug. */
1915 hash %= OBARRAY_SIZE;
1916 tem = &XVECTOR (Vobarray)->contents[hash];
1917 *tem = Qnil;
1918
1919 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7));
1920 XSYMBOL (Qnil)->function = Qunbound;
1921 XSYMBOL (Qunbound)->value = Qunbound;
1922 XSYMBOL (Qunbound)->function = Qunbound;
1923
1924 Qt = intern ("t");
1925 XSYMBOL (Qnil)->value = Qnil;
1926 XSYMBOL (Qnil)->plist = Qnil;
1927 XSYMBOL (Qt)->value = Qt;
1928
1929 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
1930 Vpurify_flag = Qt;
1931
1932 Qvariable_documentation = intern ("variable-documentation");
1933
1934 read_buffer_size = 100;
1935 read_buffer = (char *) malloc (read_buffer_size);
1936 }
1937 \f
1938 void
1939 defsubr (sname)
1940 struct Lisp_Subr *sname;
1941 {
1942 Lisp_Object sym;
1943 sym = intern (sname->symbol_name);
1944 XSETSUBR (XSYMBOL (sym)->function, sname);
1945 }
1946
1947 #ifdef NOTDEF /* use fset in subr.el now */
1948 void
1949 defalias (sname, string)
1950 struct Lisp_Subr *sname;
1951 char *string;
1952 {
1953 Lisp_Object sym;
1954 sym = intern (string);
1955 XSETSUBR (XSYMBOL (sym)->function, sname);
1956 }
1957 #endif /* NOTDEF */
1958
1959 /* Define an "integer variable"; a symbol whose value is forwarded
1960 to a C variable of type int. Sample call: */
1961 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
1962 void
1963 defvar_int (namestring, address)
1964 char *namestring;
1965 int *address;
1966 {
1967 Lisp_Object sym, val;
1968 sym = intern (namestring);
1969 val = allocate_misc ();
1970 XMISCTYPE (val) = Lisp_Misc_Intfwd;
1971 XINTFWD (val)->intvar = address;
1972 XSYMBOL (sym)->value = val;
1973 }
1974
1975 /* Similar but define a variable whose value is T if address contains 1,
1976 NIL if address contains 0 */
1977 void
1978 defvar_bool (namestring, address)
1979 char *namestring;
1980 int *address;
1981 {
1982 Lisp_Object sym, val;
1983 sym = intern (namestring);
1984 val = allocate_misc ();
1985 XMISCTYPE (val) = Lisp_Misc_Boolfwd;
1986 XBOOLFWD (val)->boolvar = address;
1987 XSYMBOL (sym)->value = val;
1988 }
1989
1990 /* Similar but define a variable whose value is the Lisp Object stored
1991 at address. Two versions: with and without gc-marking of the C
1992 variable. The nopro version is used when that variable will be
1993 gc-marked for some other reason, since marking the same slot twice
1994 can cause trouble with strings. */
1995 void
1996 defvar_lisp_nopro (namestring, address)
1997 char *namestring;
1998 Lisp_Object *address;
1999 {
2000 Lisp_Object sym, val;
2001 sym = intern (namestring);
2002 val = allocate_misc ();
2003 XMISCTYPE (val) = Lisp_Misc_Objfwd;
2004 XOBJFWD (val)->objvar = address;
2005 XSYMBOL (sym)->value = val;
2006 }
2007
2008 void
2009 defvar_lisp (namestring, address)
2010 char *namestring;
2011 Lisp_Object *address;
2012 {
2013 defvar_lisp_nopro (namestring, address);
2014 staticpro (address);
2015 }
2016
2017 #ifndef standalone
2018
2019 /* Similar but define a variable whose value is the Lisp Object stored in
2020 the current buffer. address is the address of the slot in the buffer
2021 that is current now. */
2022
2023 void
2024 defvar_per_buffer (namestring, address, type, doc)
2025 char *namestring;
2026 Lisp_Object *address;
2027 Lisp_Object type;
2028 char *doc;
2029 {
2030 Lisp_Object sym, val;
2031 int offset;
2032 extern struct buffer buffer_local_symbols;
2033
2034 sym = intern (namestring);
2035 val = allocate_misc ();
2036 offset = (char *)address - (char *)current_buffer;
2037
2038 XMISCTYPE (val) = Lisp_Misc_Buffer_Objfwd;
2039 XBUFFER_OBJFWD (val)->offset = offset;
2040 XSYMBOL (sym)->value = val;
2041 *(Lisp_Object *)(offset + (char *)&buffer_local_symbols) = sym;
2042 *(Lisp_Object *)(offset + (char *)&buffer_local_types) = type;
2043 if (XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags)) == 0)
2044 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
2045 slot of buffer_local_flags */
2046 abort ();
2047 }
2048
2049 #endif /* standalone */
2050
2051 /* Similar but define a variable whose value is the Lisp Object stored
2052 at a particular offset in the current kboard object. */
2053
2054 void
2055 defvar_kboard (namestring, offset)
2056 char *namestring;
2057 int offset;
2058 {
2059 Lisp_Object sym, val;
2060 sym = intern (namestring);
2061 val = allocate_misc ();
2062 XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd;
2063 XKBOARD_OBJFWD (val)->offset = offset;
2064 XSYMBOL (sym)->value = val;
2065 }
2066 \f
2067 init_lread ()
2068 {
2069 char *normal;
2070 int turn_off_warning = 0;
2071
2072 /* Compute the default load-path. */
2073 #ifdef CANNOT_DUMP
2074 normal = PATH_LOADSEARCH;
2075 Vload_path = decode_env_path (0, normal);
2076 #else
2077 if (NILP (Vpurify_flag))
2078 normal = PATH_LOADSEARCH;
2079 else
2080 normal = PATH_DUMPLOADSEARCH;
2081
2082 /* In a dumped Emacs, we normally have to reset the value of
2083 Vload_path from PATH_LOADSEARCH, since the value that was dumped
2084 uses ../lisp, instead of the path of the installed elisp
2085 libraries. However, if it appears that Vload_path was changed
2086 from the default before dumping, don't override that value. */
2087 if (initialized)
2088 {
2089 Lisp_Object dump_path;
2090
2091 dump_path = decode_env_path (0, PATH_DUMPLOADSEARCH);
2092 if (! NILP (Fequal (dump_path, Vload_path)))
2093 {
2094 Vload_path = decode_env_path (0, normal);
2095 if (!NILP (Vinstallation_directory))
2096 {
2097 /* Add to the path the lisp subdir of the
2098 installation dir, if it exists. */
2099 Lisp_Object tem, tem1;
2100 tem = Fexpand_file_name (build_string ("lisp"),
2101 Vinstallation_directory);
2102 tem1 = Ffile_exists_p (tem);
2103 if (!NILP (tem1))
2104 {
2105 if (NILP (Fmember (tem, Vload_path)))
2106 {
2107 turn_off_warning = 1;
2108 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
2109 }
2110 }
2111 else
2112 /* That dir doesn't exist, so add the build-time
2113 Lisp dirs instead. */
2114 Vload_path = nconc2 (Vload_path, dump_path);
2115
2116 /* Add site-list under the installation dir, if it exists. */
2117 tem = Fexpand_file_name (build_string ("site-lisp"),
2118 Vinstallation_directory);
2119 tem1 = Ffile_exists_p (tem);
2120 if (!NILP (tem1))
2121 {
2122 if (NILP (Fmember (tem, Vload_path)))
2123 Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
2124 }
2125 }
2126 }
2127 }
2128 else
2129 Vload_path = decode_env_path (0, normal);
2130 #endif
2131
2132 #ifndef WINDOWSNT
2133 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
2134 almost never correct, thereby causing a warning to be printed out that
2135 confuses users. Since PATH_LOADSEARCH is always overriden by the
2136 EMACSLOADPATH environment variable below, disable the warning on NT. */
2137
2138 /* Warn if dirs in the *standard* path don't exist. */
2139 if (!turn_off_warning)
2140 {
2141 Lisp_Object path_tail;
2142
2143 for (path_tail = Vload_path;
2144 !NILP (path_tail);
2145 path_tail = XCONS (path_tail)->cdr)
2146 {
2147 Lisp_Object dirfile;
2148 dirfile = Fcar (path_tail);
2149 if (STRINGP (dirfile))
2150 {
2151 dirfile = Fdirectory_file_name (dirfile);
2152 if (access (XSTRING (dirfile)->data, 0) < 0)
2153 fprintf (stderr,
2154 "Warning: Lisp directory `%s' does not exist.\n",
2155 XSTRING (Fcar (path_tail))->data);
2156 }
2157 }
2158 }
2159 #endif /* WINDOWSNT */
2160
2161 /* If the EMACSLOADPATH environment variable is set, use its value.
2162 This doesn't apply if we're dumping. */
2163 #ifndef CANNOT_DUMP
2164 if (NILP (Vpurify_flag)
2165 && egetenv ("EMACSLOADPATH"))
2166 #endif
2167 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
2168
2169 Vvalues = Qnil;
2170
2171 load_in_progress = 0;
2172
2173 load_descriptor_list = Qnil;
2174 }
2175
2176 void
2177 syms_of_lread ()
2178 {
2179 defsubr (&Sread);
2180 defsubr (&Sread_from_string);
2181 defsubr (&Sintern);
2182 defsubr (&Sintern_soft);
2183 defsubr (&Sunintern);
2184 defsubr (&Sload);
2185 defsubr (&Seval_buffer);
2186 defsubr (&Seval_region);
2187 defsubr (&Sread_char);
2188 defsubr (&Sread_char_exclusive);
2189 defsubr (&Sread_event);
2190 defsubr (&Sget_file_char);
2191 defsubr (&Smapatoms);
2192
2193 DEFVAR_LISP ("obarray", &Vobarray,
2194 "Symbol table for use by `intern' and `read'.\n\
2195 It is a vector whose length ought to be prime for best results.\n\
2196 The vector's contents don't make sense if examined from Lisp programs;\n\
2197 to find all the symbols in an obarray, use `mapatoms'.");
2198
2199 DEFVAR_LISP ("values", &Vvalues,
2200 "List of values of all expressions which were read, evaluated and printed.\n\
2201 Order is reverse chronological.");
2202
2203 DEFVAR_LISP ("standard-input", &Vstandard_input,
2204 "Stream for read to get input from.\n\
2205 See documentation of `read' for possible values.");
2206 Vstandard_input = Qt;
2207
2208 DEFVAR_LISP ("load-path", &Vload_path,
2209 "*List of directories to search for files to load.\n\
2210 Each element is a string (directory name) or nil (try default directory).\n\
2211 Initialized based on EMACSLOADPATH environment variable, if any,\n\
2212 otherwise to default specified by file `paths.h' when Emacs was built.");
2213
2214 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
2215 "Non-nil iff inside of `load'.");
2216
2217 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
2218 "An alist of expressions to be evalled when particular files are loaded.\n\
2219 Each element looks like (FILENAME FORMS...).\n\
2220 When `load' is run and the file-name argument is FILENAME,\n\
2221 the FORMS in the corresponding element are executed at the end of loading.\n\n\
2222 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
2223 with no directory specified, since that is how `load' is normally called.\n\
2224 An error in FORMS does not undo the load,\n\
2225 but does prevent execution of the rest of the FORMS.");
2226 Vafter_load_alist = Qnil;
2227
2228 DEFVAR_LISP ("load-history", &Vload_history,
2229 "Alist mapping source file names to symbols and features.\n\
2230 Each alist element is a list that starts with a file name,\n\
2231 except for one element (optional) that starts with nil and describes\n\
2232 definitions evaluated from buffers not visiting files.\n\
2233 The remaining elements of each list are symbols defined as functions\n\
2234 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
2235 Vload_history = Qnil;
2236
2237 DEFVAR_LISP ("load-file-name", &Vload_file_name,
2238 "Full name of file being loaded by `load'.");
2239 Vload_file_name = Qnil;
2240
2241 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
2242 "Used for internal purposes by `load'.");
2243 Vcurrent_load_list = Qnil;
2244
2245 DEFVAR_LISP ("load-read-function", &Vload_read_function,
2246 "Function used by `load' and `eval-region' for reading expressions.\n\
2247 The default is nil, which means use the function `read'.");
2248 Vload_read_function = Qnil;
2249
2250 load_descriptor_list = Qnil;
2251 staticpro (&load_descriptor_list);
2252
2253 Qcurrent_load_list = intern ("current-load-list");
2254 staticpro (&Qcurrent_load_list);
2255
2256 Qstandard_input = intern ("standard-input");
2257 staticpro (&Qstandard_input);
2258
2259 Qread_char = intern ("read-char");
2260 staticpro (&Qread_char);
2261
2262 Qget_file_char = intern ("get-file-char");
2263 staticpro (&Qget_file_char);
2264
2265 Qbackquote = intern ("`");
2266 staticpro (&Qbackquote);
2267 Qcomma = intern (",");
2268 staticpro (&Qcomma);
2269 Qcomma_at = intern (",@");
2270 staticpro (&Qcomma_at);
2271 Qcomma_dot = intern (",.");
2272 staticpro (&Qcomma_dot);
2273
2274 Qascii_character = intern ("ascii-character");
2275 staticpro (&Qascii_character);
2276
2277 Qload = intern ("load");
2278 staticpro (&Qload);
2279
2280 Qload_file_name = intern ("load-file-name");
2281 staticpro (&Qload_file_name);
2282 }