entered into RCS
[bpt/emacs.git] / src / lread.c
1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989,
3 1992 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 <stdio.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/file.h>
26 #include <ctype.h>
27 #undef NULL
28 #include "config.h"
29 #include "lisp.h"
30
31 #ifndef standalone
32 #include "buffer.h"
33 #include "paths.h"
34 #include "commands.h"
35 #endif
36
37 #ifdef lint
38 #include <sys/inode.h>
39 #endif /* lint */
40
41 #ifndef X_OK
42 #define X_OK 01
43 #endif
44
45 #ifdef LISP_FLOAT_TYPE
46 #include <math.h>
47 #endif /* LISP_FLOAT_TYPE */
48
49 Lisp_Object Qread_char, Qget_file_char, Qstandard_input;
50 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
51
52 /* non-zero if inside `load' */
53 int load_in_progress;
54
55 /* Search path for files to be loaded. */
56 Lisp_Object Vload_path;
57
58 /* File for get_file_char to read from. Use by load */
59 static FILE *instream;
60
61 /* When nonzero, read conses in pure space */
62 static int read_pure;
63
64 /* For use within read-from-string (this reader is non-reentrant!!) */
65 static int read_from_string_index;
66 static int read_from_string_limit;
67 \f
68 /* Handle unreading and rereading of characters.
69 Write READCHAR to read a character,
70 UNREAD(c) to unread c to be read again. */
71
72 #define READCHAR readchar (readcharfun)
73 #define UNREAD(c) unreadchar (readcharfun, c)
74
75 static int
76 readchar (readcharfun)
77 Lisp_Object readcharfun;
78 {
79 Lisp_Object tem;
80 register struct buffer *inbuffer;
81 register int c, mpos;
82
83 if (XTYPE (readcharfun) == Lisp_Buffer)
84 {
85 inbuffer = XBUFFER (readcharfun);
86
87 if (BUF_PT (inbuffer) >= BUF_ZV (inbuffer))
88 return -1;
89 c = *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer, BUF_PT (inbuffer));
90 SET_BUF_PT (inbuffer, BUF_PT (inbuffer) + 1);
91
92 return c;
93 }
94 if (XTYPE (readcharfun) == Lisp_Marker)
95 {
96 inbuffer = XMARKER (readcharfun)->buffer;
97
98 mpos = marker_position (readcharfun);
99
100 if (mpos > BUF_ZV (inbuffer) - 1)
101 return -1;
102 c = *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer, mpos);
103 if (mpos != BUF_GPT (inbuffer))
104 XMARKER (readcharfun)->bufpos++;
105 else
106 Fset_marker (readcharfun, make_number (mpos + 1),
107 Fmarker_buffer (readcharfun));
108 return c;
109 }
110 if (EQ (readcharfun, Qget_file_char))
111 return getc (instream);
112
113 if (XTYPE (readcharfun) == Lisp_String)
114 {
115 register int c;
116 /* This used to be return of a conditional expression,
117 but that truncated -1 to a char on VMS. */
118 if (read_from_string_index < read_from_string_limit)
119 c = XSTRING (readcharfun)->data[read_from_string_index++];
120 else
121 c = -1;
122 return c;
123 }
124
125 tem = call0 (readcharfun);
126
127 if (NILP (tem))
128 return -1;
129 return XINT (tem);
130 }
131
132 /* Unread the character C in the way appropriate for the stream READCHARFUN.
133 If the stream is a user function, call it with the char as argument. */
134
135 static void
136 unreadchar (readcharfun, c)
137 Lisp_Object readcharfun;
138 int c;
139 {
140 if (XTYPE (readcharfun) == Lisp_Buffer)
141 {
142 if (XBUFFER (readcharfun) == current_buffer)
143 SET_PT (point - 1);
144 else
145 SET_BUF_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1);
146 }
147 else if (XTYPE (readcharfun) == Lisp_Marker)
148 XMARKER (readcharfun)->bufpos--;
149 else if (XTYPE (readcharfun) == Lisp_String)
150 read_from_string_index--;
151 else if (EQ (readcharfun, Qget_file_char))
152 ungetc (c, instream);
153 else
154 call1 (readcharfun, make_number (c));
155 }
156
157 static Lisp_Object read0 (), read1 (), read_list (), read_vector ();
158 \f
159 /* get a character from the tty */
160
161 DEFUN ("read-char", Fread_char, Sread_char, 0, 0, 0,
162 "Read a character from the command input (keyboard or macro).\n\
163 It is returned as a number.")
164 ()
165 {
166 register Lisp_Object val;
167
168 #ifndef standalone
169 val = read_char (0);
170 if (XTYPE (val) != Lisp_Int)
171 {
172 unread_command_char = val;
173 error ("Object read was not a character");
174 }
175 #else
176 val = getchar ();
177 #endif
178
179 return val;
180 }
181
182 #ifdef HAVE_X_WINDOWS
183 DEFUN ("read-event", Fread_event, Sread_event, 0, 0, 0,
184 "Read an event object from the input stream.")
185 ()
186 {
187 register Lisp_Object val;
188
189 val = read_char (0);
190 return val;
191 }
192 #endif
193
194 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 0, 0,
195 "Read a character from the command input (keyboard or macro).\n\
196 It is returned as a number. Non character events are ignored.")
197 ()
198 {
199 register Lisp_Object val;
200
201 #ifndef standalone
202 val = read_char (0);
203 while (XTYPE (val) != Lisp_Int)
204 val = read_char (0);
205 #else
206 val = getchar ();
207 #endif
208
209 return val;
210 }
211
212 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
213 "Don't use this yourself.")
214 ()
215 {
216 register Lisp_Object val;
217 XSET (val, Lisp_Int, getc (instream));
218 return val;
219 }
220 \f
221 static void readevalloop ();
222 static Lisp_Object load_unwind ();
223
224 DEFUN ("load", Fload, Sload, 1, 4, 0,
225 "Execute a file of Lisp code named FILE.\n\
226 First try FILE with `.elc' appended, then try with `.el',\n\
227 then try FILE unmodified.\n\
228 This function searches the directories in `load-path'.\n\
229 If optional second arg NOERROR is non-nil,\n\
230 report no error if FILE doesn't exist.\n\
231 Print messages at start and end of loading unless\n\
232 optional third arg NOMESSAGE is non-nil.\n\
233 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
234 suffixes `.elc' or `.el' to the specified name FILE.\n\
235 Return t if file exists.")
236 (str, noerror, nomessage, nosuffix)
237 Lisp_Object str, noerror, nomessage, nosuffix;
238 {
239 register FILE *stream;
240 register int fd = -1;
241 register Lisp_Object lispstream;
242 register FILE **ptr;
243 int count = specpdl_ptr - specpdl;
244 Lisp_Object temp;
245 struct gcpro gcpro1;
246 Lisp_Object found;
247
248 CHECK_STRING (str, 0);
249 str = Fsubstitute_in_file_name (str);
250
251 /* Avoid weird lossage with null string as arg,
252 since it would try to load a directory as a Lisp file */
253 if (XSTRING (str)->size > 0)
254 {
255 fd = openp (Vload_path, str, !NILP (nosuffix) ? "" : ".elc:.el:",
256 &found, 0);
257 }
258
259 if (fd < 0)
260 {
261 if (NILP (noerror))
262 while (1)
263 Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"),
264 Fcons (str, Qnil)));
265 else
266 return Qnil;
267 }
268
269 if (!bcmp (&(XSTRING (found)->data[XSTRING (found)->size - 4]),
270 ".elc", 4))
271 {
272 struct stat s1, s2;
273 int result;
274
275 stat (XSTRING (found)->data, &s1);
276 XSTRING (found)->data[XSTRING (found)->size - 1] = 0;
277 result = stat (XSTRING (found)->data, &s2);
278 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
279 message ("Source file `%s' newer than byte-compiled file",
280 XSTRING (found)->data);
281 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c';
282 }
283
284 stream = fdopen (fd, "r");
285 if (stream == 0)
286 {
287 close (fd);
288 error ("Failure to create stdio stream for %s", XSTRING (str)->data);
289 }
290
291 if (NILP (nomessage))
292 message ("Loading %s...", XSTRING (str)->data);
293
294 GCPRO1 (str);
295 /* We may not be able to store STREAM itself as a Lisp_Object pointer
296 since that is guaranteed to work only for data that has been malloc'd.
297 So malloc a full-size pointer, and record the address of that pointer. */
298 ptr = (FILE **) xmalloc (sizeof (FILE *));
299 *ptr = stream;
300 XSET (lispstream, Lisp_Internal_Stream, (int) ptr);
301 record_unwind_protect (load_unwind, lispstream);
302 load_in_progress++;
303 readevalloop (Qget_file_char, stream, Feval, 0);
304 unbind_to (count, Qnil);
305
306 /* Run any load-hooks for this file. */
307 temp = Fassoc (str, Vafter_load_alist);
308 if (!NILP (temp))
309 Fprogn (Fcdr (temp));
310 UNGCPRO;
311
312 if (!noninteractive && NILP (nomessage))
313 message ("Loading %s...done", XSTRING (str)->data);
314 return Qt;
315 }
316
317 static Lisp_Object
318 load_unwind (stream) /* used as unwind-protect function in load */
319 Lisp_Object stream;
320 {
321 fclose (*(FILE **) XSTRING (stream));
322 free (XPNTR (stream));
323 if (--load_in_progress < 0) load_in_progress = 0;
324 return Qnil;
325 }
326
327 \f
328 static int
329 complete_filename_p (pathname)
330 Lisp_Object pathname;
331 {
332 register unsigned char *s = XSTRING (pathname)->data;
333 return (*s == '/'
334 #ifdef ALTOS
335 || *s == '@'
336 #endif
337 #ifdef VMS
338 || index (s, ':')
339 #endif /* VMS */
340 );
341 }
342
343 /* Search for a file whose name is STR, looking in directories
344 in the Lisp list PATH, and trying suffixes from SUFFIX.
345 SUFFIX is a string containing possible suffixes separated by colons.
346 On success, returns a file descriptor. On failure, returns -1.
347
348 EXEC_ONLY nonzero means don't open the files,
349 just look for one that is executable. In this case,
350 returns 1 on success.
351
352 If STOREPTR is nonzero, it points to a slot where the name of
353 the file actually found should be stored as a Lisp string.
354 Nil is stored there on failure. */
355
356 int
357 openp (path, str, suffix, storeptr, exec_only)
358 Lisp_Object path, str;
359 char *suffix;
360 Lisp_Object *storeptr;
361 int exec_only;
362 {
363 register int fd;
364 int fn_size = 100;
365 char buf[100];
366 register char *fn = buf;
367 int absolute = 0;
368 int want_size;
369 register Lisp_Object filename;
370 struct stat st;
371
372 if (storeptr)
373 *storeptr = Qnil;
374
375 if (complete_filename_p (str))
376 absolute = 1;
377
378 for (; !NILP (path); path = Fcdr (path))
379 {
380 char *nsuffix;
381
382 filename = Fexpand_file_name (str, Fcar (path));
383 if (!complete_filename_p (filename))
384 /* If there are non-absolute elts in PATH (eg ".") */
385 /* Of course, this could conceivably lose if luser sets
386 default-directory to be something non-absolute... */
387 {
388 filename = Fexpand_file_name (filename, current_buffer->directory);
389 if (!complete_filename_p (filename))
390 /* Give up on this path element! */
391 continue;
392 }
393
394 /* Calculate maximum size of any filename made from
395 this path element/specified file name and any possible suffix. */
396 want_size = strlen (suffix) + XSTRING (filename)->size + 1;
397 if (fn_size < want_size)
398 fn = (char *) alloca (fn_size = 100 + want_size);
399
400 nsuffix = suffix;
401
402 /* Loop over suffixes. */
403 while (1)
404 {
405 char *esuffix = (char *) index (nsuffix, ':');
406 int lsuffix = esuffix ? esuffix - nsuffix : strlen (nsuffix);
407
408 /* Concatenate path element/specified name with the suffix. */
409 strncpy (fn, XSTRING (filename)->data, XSTRING (filename)->size);
410 fn[XSTRING (filename)->size] = 0;
411 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
412 strncat (fn, nsuffix, lsuffix);
413
414 /* Ignore file if it's a directory. */
415 if (stat (fn, &st) >= 0
416 && (st.st_mode & S_IFMT) != S_IFDIR)
417 {
418 /* Check that we can access or open it. */
419 if (exec_only)
420 fd = (access (fn, X_OK) == 0) ? 1 : -1;
421 else
422 fd = open (fn, 0, 0);
423
424 if (fd >= 0)
425 {
426 /* We succeeded; return this descriptor and filename. */
427 if (storeptr)
428 *storeptr = build_string (fn);
429 return fd;
430 }
431 }
432
433 /* Advance to next suffix. */
434 if (esuffix == 0)
435 break;
436 nsuffix += lsuffix + 1;
437 }
438 if (absolute) return -1;
439 }
440
441 return -1;
442 }
443
444 \f
445 Lisp_Object
446 unreadpure () /* Used as unwind-protect function in readevalloop */
447 {
448 read_pure = 0;
449 return Qnil;
450 }
451
452 static void
453 readevalloop (readcharfun, stream, evalfun, printflag)
454 Lisp_Object readcharfun;
455 FILE *stream;
456 Lisp_Object (*evalfun) ();
457 int printflag;
458 {
459 register int c;
460 register Lisp_Object val;
461 int count = specpdl_ptr - specpdl;
462
463 specbind (Qstandard_input, readcharfun);
464
465 while (1)
466 {
467 instream = stream;
468 c = READCHAR;
469 if (c == ';')
470 {
471 while ((c = READCHAR) != '\n' && c != -1);
472 continue;
473 }
474 if (c < 0) break;
475 if (c == ' ' || c == '\t' || c == '\n' || c == '\f') continue;
476
477 if (!NILP (Vpurify_flag) && c == '(')
478 {
479 record_unwind_protect (unreadpure, Qnil);
480 val = read_list (-1, readcharfun);
481 unbind_to (count + 1, Qnil);
482 }
483 else
484 {
485 UNREAD (c);
486 val = read0 (readcharfun);
487 }
488
489 val = (*evalfun) (val);
490 if (printflag)
491 {
492 Vvalues = Fcons (val, Vvalues);
493 if (EQ (Vstandard_output, Qt))
494 Fprin1 (val, Qnil);
495 else
496 Fprint (val, Qnil);
497 }
498 }
499
500 unbind_to (count, Qnil);
501 }
502
503 #ifndef standalone
504
505 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 2, "",
506 "Execute the current buffer as Lisp code.\n\
507 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
508 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
509 PRINTFLAG controls printing of output:\n\
510 nil means discard it; anything else is stream for print.\n\
511 \n\
512 If there is no error, point does not move. If there is an error,\n\
513 point remains at the end of the last character read from the buffer.")
514 (bufname, printflag)
515 Lisp_Object bufname, printflag;
516 {
517 int count = specpdl_ptr - specpdl;
518 Lisp_Object tem, buf;
519
520 if (NILP (bufname))
521 buf = Fcurrent_buffer ();
522 else
523 buf = Fget_buffer (bufname);
524 if (NILP (buf))
525 error ("No such buffer.");
526
527 if (NILP (printflag))
528 tem = Qsymbolp;
529 else
530 tem = printflag;
531 specbind (Qstandard_output, tem);
532 record_unwind_protect (save_excursion_restore, save_excursion_save ());
533 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
534 readevalloop (buf, 0, Feval, !NILP (printflag));
535 unbind_to (count);
536
537 return Qnil;
538 }
539
540 #if 0
541 DEFUN ("eval-current-buffer", Feval_current_buffer, Seval_current_buffer, 0, 1, "",
542 "Execute the current buffer as Lisp code.\n\
543 Programs can pass argument PRINTFLAG which controls printing of output:\n\
544 nil means discard it; anything else is stream for print.\n\
545 \n\
546 If there is no error, point does not move. If there is an error,\n\
547 point remains at the end of the last character read from the buffer.")
548 (printflag)
549 Lisp_Object printflag;
550 {
551 int count = specpdl_ptr - specpdl;
552 Lisp_Object tem;
553
554 if (NILP (printflag))
555 tem = Qsymbolp;
556 else
557 tem = printflag;
558 specbind (Qstandard_output, tem);
559 record_unwind_protect (save_excursion_restore, save_excursion_save ());
560 SET_PT (BEGV);
561 readevalloop (Fcurrent_buffer (), 0, Feval, !NILP (printflag));
562 return unbind_to (count, Qnil);
563 }
564 #endif
565
566 DEFUN ("eval-region", Feval_region, Seval_region, 2, 3, "r",
567 "Execute the region as Lisp code.\n\
568 When called from programs, expects two arguments,\n\
569 giving starting and ending indices in the current buffer\n\
570 of the text to be executed.\n\
571 Programs can pass third argument PRINTFLAG which controls output:\n\
572 nil means discard it; anything else is stream for printing it.\n\
573 \n\
574 If there is no error, point does not move. If there is an error,\n\
575 point remains at the end of the last character read from the buffer.")
576 (b, e, printflag)
577 Lisp_Object b, e, printflag;
578 {
579 int count = specpdl_ptr - specpdl;
580 Lisp_Object tem;
581
582 if (NILP (printflag))
583 tem = Qsymbolp;
584 else
585 tem = printflag;
586 specbind (Qstandard_output, tem);
587
588 if (NILP (printflag))
589 record_unwind_protect (save_excursion_restore, save_excursion_save ());
590 record_unwind_protect (save_restriction_restore, save_restriction_save ());
591
592 /* This both uses b and checks its type. */
593 Fgoto_char (b);
594 Fnarrow_to_region (make_number (BEGV), e);
595 readevalloop (Fcurrent_buffer (), 0, Feval, !NILP (printflag));
596
597 return unbind_to (count, Qnil);
598 }
599
600 #endif /* standalone */
601 \f
602 DEFUN ("read", Fread, Sread, 0, 1, 0,
603 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
604 If STREAM is nil, use the value of `standard-input' (which see).\n\
605 STREAM or the value of `standard-input' may be:\n\
606 a buffer (read from point and advance it)\n\
607 a marker (read from where it points and advance it)\n\
608 a function (call it with no arguments for each character,\n\
609 call it with a char as argument to push a char back)\n\
610 a string (takes text from string, starting at the beginning)\n\
611 t (read text line using minibuffer and use it).")
612 (readcharfun)
613 Lisp_Object readcharfun;
614 {
615 extern Lisp_Object Fread_minibuffer ();
616
617 if (NILP (readcharfun))
618 readcharfun = Vstandard_input;
619 if (EQ (readcharfun, Qt))
620 readcharfun = Qread_char;
621
622 #ifndef standalone
623 if (EQ (readcharfun, Qread_char))
624 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
625 #endif
626
627 if (XTYPE (readcharfun) == Lisp_String)
628 return Fcar (Fread_from_string (readcharfun, Qnil, Qnil));
629
630 return read0 (readcharfun);
631 }
632
633 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
634 "Read one Lisp expression which is represented as text by STRING.\n\
635 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
636 START and END optionally delimit a substring of STRING from which to read;\n\
637 they default to 0 and (length STRING) respectively.")
638 (string, start, end)
639 Lisp_Object string, start, end;
640 {
641 int startval, endval;
642 Lisp_Object tem;
643
644 CHECK_STRING (string,0);
645
646 if (NILP (end))
647 endval = XSTRING (string)->size;
648 else
649 { CHECK_NUMBER (end,2);
650 endval = XINT (end);
651 if (endval < 0 || endval > XSTRING (string)->size)
652 args_out_of_range (string, end);
653 }
654
655 if (NILP (start))
656 startval = 0;
657 else
658 { CHECK_NUMBER (start,1);
659 startval = XINT (start);
660 if (startval < 0 || startval > endval)
661 args_out_of_range (string, start);
662 }
663
664 read_from_string_index = startval;
665 read_from_string_limit = endval;
666
667 tem = read0 (string);
668 return Fcons (tem, make_number (read_from_string_index));
669 }
670 \f
671 /* Use this for recursive reads, in contexts where internal tokens are not allowed. */
672
673 static Lisp_Object
674 read0 (readcharfun)
675 Lisp_Object readcharfun;
676 {
677 register Lisp_Object val;
678 char c;
679
680 val = read1 (readcharfun);
681 if (XTYPE (val) == Lisp_Internal)
682 {
683 c = XINT (val);
684 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (&c, 1), Qnil));
685 }
686
687 return val;
688 }
689 \f
690 static int read_buffer_size;
691 static char *read_buffer;
692
693 static int
694 read_escape (readcharfun)
695 Lisp_Object readcharfun;
696 {
697 register int c = READCHAR;
698 switch (c)
699 {
700 case 'a':
701 return '\007';
702 case 'b':
703 return '\b';
704 case 'e':
705 return 033;
706 case 'f':
707 return '\f';
708 case 'n':
709 return '\n';
710 case 'r':
711 return '\r';
712 case 't':
713 return '\t';
714 case 'v':
715 return '\v';
716 case '\n':
717 return -1;
718
719 case 'M':
720 c = READCHAR;
721 if (c != '-')
722 error ("Invalid escape character syntax");
723 c = READCHAR;
724 if (c == '\\')
725 c = read_escape (readcharfun);
726 return c | 0200;
727
728 case 'C':
729 c = READCHAR;
730 if (c != '-')
731 error ("Invalid escape character syntax");
732 case '^':
733 c = READCHAR;
734 if (c == '\\')
735 c = read_escape (readcharfun);
736 if (c == '?')
737 return 0177;
738 else
739 return (c & (0200 | 037));
740
741 case '0':
742 case '1':
743 case '2':
744 case '3':
745 case '4':
746 case '5':
747 case '6':
748 case '7':
749 /* An octal escape, as in ANSI C. */
750 {
751 register int i = c - '0';
752 register int count = 0;
753 while (++count < 3)
754 {
755 if ((c = READCHAR) >= '0' && c <= '7')
756 {
757 i *= 8;
758 i += c - '0';
759 }
760 else
761 {
762 UNREAD (c);
763 break;
764 }
765 }
766 return i;
767 }
768
769 case 'x':
770 /* A hex escape, as in ANSI C. */
771 {
772 int i = 0;
773 while (1)
774 {
775 c = READCHAR;
776 if (c >= '0' && c <= '9')
777 {
778 i *= 16;
779 i += c - '0';
780 }
781 else if ((c >= 'a' && c <= 'f')
782 || (c >= 'A' && c <= 'F'))
783 {
784 i *= 16;
785 if (c >= 'a' && c <= 'f')
786 i += c - 'a' + 10;
787 else
788 i += c - 'A' + 10;
789 }
790 else
791 {
792 UNREAD (c);
793 break;
794 }
795 }
796 return i;
797 }
798
799 default:
800 return c;
801 }
802 }
803
804 static Lisp_Object
805 read1 (readcharfun)
806 register Lisp_Object readcharfun;
807 {
808 register int c;
809
810 retry:
811
812 c = READCHAR;
813 if (c < 0) return Fsignal (Qend_of_file, Qnil);
814
815 switch (c)
816 {
817 case '(':
818 return read_list (0, readcharfun);
819
820 case '[':
821 return read_vector (readcharfun);
822
823 case ')':
824 case ']':
825 {
826 register Lisp_Object val;
827 XSET (val, Lisp_Internal, c);
828 return val;
829 }
830
831 case '#':
832 c = READCHAR;
833 if (c == '[')
834 {
835 /* Accept compiled functions at read-time so that we don't have to
836 build them using function calls. */
837 Lisp_Object tmp = read_vector (readcharfun);
838 return Fmake_byte_code (XVECTOR(tmp)->size, XVECTOR (tmp)->contents);
839 }
840 UNREAD (c);
841 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
842
843 case ';':
844 while ((c = READCHAR) >= 0 && c != '\n');
845 goto retry;
846
847 case '\'':
848 {
849 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
850 }
851
852 case '?':
853 {
854 register Lisp_Object val;
855
856 c = READCHAR;
857 if (c < 0) return Fsignal (Qend_of_file, Qnil);
858
859 if (c == '\\')
860 XSET (val, Lisp_Int, read_escape (readcharfun));
861 else
862 XSET (val, Lisp_Int, c);
863
864 return val;
865 }
866
867 case '\"':
868 {
869 register char *p = read_buffer;
870 register char *end = read_buffer + read_buffer_size;
871 register int c;
872 int cancel = 0;
873
874 while ((c = READCHAR) >= 0
875 && c != '\"')
876 {
877 if (p == end)
878 {
879 char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
880 p += new - read_buffer;
881 read_buffer += new - read_buffer;
882 end = read_buffer + read_buffer_size;
883 }
884 if (c == '\\')
885 c = read_escape (readcharfun);
886 /* c is -1 if \ newline has just been seen */
887 if (c < 0)
888 {
889 if (p == read_buffer)
890 cancel = 1;
891 }
892 else
893 *p++ = c;
894 }
895 if (c < 0) return Fsignal (Qend_of_file, Qnil);
896
897 /* If purifying, and string starts with \ newline,
898 return zero instead. This is for doc strings
899 that we are really going to find in etc/DOC.nn.nn */
900 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
901 return make_number (0);
902
903 if (read_pure)
904 return make_pure_string (read_buffer, p - read_buffer);
905 else
906 return make_string (read_buffer, p - read_buffer);
907 }
908
909 case '.':
910 {
911 #ifdef LISP_FLOAT_TYPE
912 /* If a period is followed by a number, then we should read it
913 as a floating point number. Otherwise, it denotes a dotted
914 pair. */
915 int next_char = READCHAR;
916 UNREAD (next_char);
917
918 if (! isdigit (next_char))
919 #endif
920 {
921 register Lisp_Object val;
922 XSET (val, Lisp_Internal, c);
923 return val;
924 }
925
926 /* Otherwise, we fall through! Note that the atom-reading loop
927 below will now loop at least once, assuring that we will not
928 try to UNREAD two characters in a row. */
929 }
930 default:
931 if (c <= 040) goto retry;
932 {
933 register char *p = read_buffer;
934
935 {
936 register char *end = read_buffer + read_buffer_size;
937
938 while (c > 040 &&
939 !(c == '\"' || c == '\'' || c == ';' || c == '?'
940 || c == '(' || c == ')'
941 #ifndef LISP_FLOAT_TYPE
942 /* If we have floating-point support, then we need
943 to allow <digits><dot><digits>. */
944 || c =='.'
945 #endif /* not LISP_FLOAT_TYPE */
946 || c == '[' || c == ']' || c == '#'
947 ))
948 {
949 if (p == end)
950 {
951 register char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
952 p += new - read_buffer;
953 read_buffer += new - read_buffer;
954 end = read_buffer + read_buffer_size;
955 }
956 if (c == '\\')
957 c = READCHAR;
958 *p++ = c;
959 c = READCHAR;
960 }
961
962 if (p == end)
963 {
964 char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
965 p += new - read_buffer;
966 read_buffer += new - read_buffer;
967 /* end = read_buffer + read_buffer_size; */
968 }
969 *p = 0;
970 if (c >= 0)
971 UNREAD (c);
972 }
973
974 /* Is it an integer? */
975 {
976 register char *p1;
977 register Lisp_Object val;
978 p1 = read_buffer;
979 if (*p1 == '+' || *p1 == '-') p1++;
980 if (p1 != p)
981 {
982 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
983 if (p1 == p)
984 /* It is. */
985 {
986 XSET (val, Lisp_Int, atoi (read_buffer));
987 return val;
988 }
989 }
990 #ifdef LISP_FLOAT_TYPE
991 if (isfloat_string (read_buffer))
992 return make_float (atof (read_buffer));
993 #endif
994 }
995
996 return intern (read_buffer);
997 }
998 }
999 }
1000 \f
1001 #ifdef LISP_FLOAT_TYPE
1002
1003 #define LEAD_INT 1
1004 #define DOT_CHAR 2
1005 #define TRAIL_INT 4
1006 #define E_CHAR 8
1007 #define EXP_INT 16
1008
1009 int
1010 isfloat_string (cp)
1011 register char *cp;
1012 {
1013 register state;
1014
1015 state = 0;
1016 if (*cp == '+' || *cp == '-')
1017 cp++;
1018
1019 if (isdigit(*cp))
1020 {
1021 state |= LEAD_INT;
1022 while (isdigit (*cp))
1023 cp ++;
1024 }
1025 if (*cp == '.')
1026 {
1027 state |= DOT_CHAR;
1028 cp++;
1029 }
1030 if (isdigit(*cp))
1031 {
1032 state |= TRAIL_INT;
1033 while (isdigit (*cp))
1034 cp++;
1035 }
1036 if (*cp == 'e')
1037 {
1038 state |= E_CHAR;
1039 cp++;
1040 }
1041 if ((*cp == '+') || (*cp == '-'))
1042 cp++;
1043
1044 if (isdigit (*cp))
1045 {
1046 state |= EXP_INT;
1047 while (isdigit (*cp))
1048 cp++;
1049 }
1050 return (*cp == 0
1051 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
1052 || state == (DOT_CHAR|TRAIL_INT)
1053 || state == (LEAD_INT|E_CHAR|EXP_INT)
1054 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
1055 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
1056 }
1057 #endif /* LISP_FLOAT_TYPE */
1058 \f
1059 static Lisp_Object
1060 read_vector (readcharfun)
1061 Lisp_Object readcharfun;
1062 {
1063 register int i;
1064 register int size;
1065 register Lisp_Object *ptr;
1066 register Lisp_Object tem, vector;
1067 register struct Lisp_Cons *otem;
1068 Lisp_Object len;
1069
1070 tem = read_list (1, readcharfun);
1071 len = Flength (tem);
1072 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
1073
1074
1075 size = XVECTOR (vector)->size;
1076 ptr = XVECTOR (vector)->contents;
1077 for (i = 0; i < size; i++)
1078 {
1079 ptr[i] = read_pure ? Fpurecopy (Fcar (tem)) : Fcar (tem);
1080 otem = XCONS (tem);
1081 tem = Fcdr (tem);
1082 free_cons (otem);
1083 }
1084 return vector;
1085 }
1086
1087 /* flag = 1 means check for ] to terminate rather than ) and .
1088 flag = -1 means check for starting with defun
1089 and make structure pure. */
1090
1091 static Lisp_Object
1092 read_list (flag, readcharfun)
1093 int flag;
1094 register Lisp_Object readcharfun;
1095 {
1096 /* -1 means check next element for defun,
1097 0 means don't check,
1098 1 means already checked and found defun. */
1099 int defunflag = flag < 0 ? -1 : 0;
1100 Lisp_Object val, tail;
1101 register Lisp_Object elt, tem;
1102 struct gcpro gcpro1, gcpro2;
1103
1104 val = Qnil;
1105 tail = Qnil;
1106
1107 while (1)
1108 {
1109 GCPRO2 (val, tail);
1110 elt = read1 (readcharfun);
1111 UNGCPRO;
1112 if (XTYPE (elt) == Lisp_Internal)
1113 {
1114 if (flag > 0)
1115 {
1116 if (XINT (elt) == ']')
1117 return val;
1118 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (") or . in a vector", 18), Qnil));
1119 }
1120 if (XINT (elt) == ')')
1121 return val;
1122 if (XINT (elt) == '.')
1123 {
1124 GCPRO2 (val, tail);
1125 if (!NILP (tail))
1126 XCONS (tail)->cdr = read0 (readcharfun);
1127 else
1128 val = read0 (readcharfun);
1129 elt = read1 (readcharfun);
1130 UNGCPRO;
1131 if (XTYPE (elt) == Lisp_Internal && XINT (elt) == ')')
1132 return val;
1133 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil));
1134 }
1135 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil));
1136 }
1137 tem = (read_pure && flag <= 0
1138 ? pure_cons (elt, Qnil)
1139 : Fcons (elt, Qnil));
1140 if (!NILP (tail))
1141 XCONS (tail)->cdr = tem;
1142 else
1143 val = tem;
1144 tail = tem;
1145 if (defunflag < 0)
1146 defunflag = EQ (elt, Qdefun);
1147 else if (defunflag > 0)
1148 read_pure = 1;
1149 }
1150 }
1151 \f
1152 Lisp_Object Vobarray;
1153 Lisp_Object initial_obarray;
1154
1155 Lisp_Object
1156 check_obarray (obarray)
1157 Lisp_Object obarray;
1158 {
1159 while (XTYPE (obarray) != Lisp_Vector || XVECTOR (obarray)->size == 0)
1160 {
1161 /* If Vobarray is now invalid, force it to be valid. */
1162 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
1163
1164 obarray = wrong_type_argument (Qvectorp, obarray);
1165 }
1166 return obarray;
1167 }
1168
1169 static int hash_string ();
1170 Lisp_Object oblookup ();
1171
1172 Lisp_Object
1173 intern (str)
1174 char *str;
1175 {
1176 Lisp_Object tem;
1177 int len = strlen (str);
1178 Lisp_Object obarray = Vobarray;
1179
1180 if (XTYPE (obarray) != Lisp_Vector || XVECTOR (obarray)->size == 0)
1181 obarray = check_obarray (obarray);
1182 tem = oblookup (obarray, str, len);
1183 if (XTYPE (tem) == Lisp_Symbol)
1184 return tem;
1185 return Fintern ((!NILP (Vpurify_flag)
1186 ? make_pure_string (str, len)
1187 : make_string (str, len)),
1188 obarray);
1189 }
1190
1191 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
1192 "Return the canonical symbol whose name is STRING.\n\
1193 If there is none, one is created by this function and returned.\n\
1194 A second optional argument specifies the obarray to use;\n\
1195 it defaults to the value of `obarray'.")
1196 (str, obarray)
1197 Lisp_Object str, obarray;
1198 {
1199 register Lisp_Object tem, sym, *ptr;
1200
1201 if (NILP (obarray)) obarray = Vobarray;
1202 obarray = check_obarray (obarray);
1203
1204 CHECK_STRING (str, 0);
1205
1206 tem = oblookup (obarray, XSTRING (str)->data, XSTRING (str)->size);
1207 if (XTYPE (tem) != Lisp_Int)
1208 return tem;
1209
1210 if (!NILP (Vpurify_flag))
1211 str = Fpurecopy (str);
1212 sym = Fmake_symbol (str);
1213
1214 ptr = &XVECTOR (obarray)->contents[XINT (tem)];
1215 if (XTYPE (*ptr) == Lisp_Symbol)
1216 XSYMBOL (sym)->next = XSYMBOL (*ptr);
1217 else
1218 XSYMBOL (sym)->next = 0;
1219 *ptr = sym;
1220 return sym;
1221 }
1222
1223 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
1224 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
1225 A second optional argument specifies the obarray to use;\n\
1226 it defaults to the value of `obarray'.")
1227 (str, obarray)
1228 Lisp_Object str, obarray;
1229 {
1230 register Lisp_Object tem;
1231
1232 if (NILP (obarray)) obarray = Vobarray;
1233 obarray = check_obarray (obarray);
1234
1235 CHECK_STRING (str, 0);
1236
1237 tem = oblookup (obarray, XSTRING (str)->data, XSTRING (str)->size);
1238 if (XTYPE (tem) != Lisp_Int)
1239 return tem;
1240 return Qnil;
1241 }
1242
1243 Lisp_Object
1244 oblookup (obarray, ptr, size)
1245 Lisp_Object obarray;
1246 register char *ptr;
1247 register int size;
1248 {
1249 int hash, obsize;
1250 register Lisp_Object tail;
1251 Lisp_Object bucket, tem;
1252
1253 if (XTYPE (obarray) != Lisp_Vector ||
1254 (obsize = XVECTOR (obarray)->size) == 0)
1255 {
1256 obarray = check_obarray (obarray);
1257 obsize = XVECTOR (obarray)->size;
1258 }
1259 /* Combining next two lines breaks VMS C 2.3. */
1260 hash = hash_string (ptr, size);
1261 hash %= obsize;
1262 bucket = XVECTOR (obarray)->contents[hash];
1263 if (XFASTINT (bucket) == 0)
1264 ;
1265 else if (XTYPE (bucket) != Lisp_Symbol)
1266 error ("Bad data in guts of obarray"); /* Like CADR error message */
1267 else for (tail = bucket; ; XSET (tail, Lisp_Symbol, XSYMBOL (tail)->next))
1268 {
1269 if (XSYMBOL (tail)->name->size == size &&
1270 !bcmp (XSYMBOL (tail)->name->data, ptr, size))
1271 return tail;
1272 else if (XSYMBOL (tail)->next == 0)
1273 break;
1274 }
1275 XSET (tem, Lisp_Int, hash);
1276 return tem;
1277 }
1278
1279 static int
1280 hash_string (ptr, len)
1281 unsigned char *ptr;
1282 int len;
1283 {
1284 register unsigned char *p = ptr;
1285 register unsigned char *end = p + len;
1286 register unsigned char c;
1287 register int hash = 0;
1288
1289 while (p != end)
1290 {
1291 c = *p++;
1292 if (c >= 0140) c -= 40;
1293 hash = ((hash<<3) + (hash>>28) + c);
1294 }
1295 return hash & 07777777777;
1296 }
1297
1298 void
1299 map_obarray (obarray, fn, arg)
1300 Lisp_Object obarray;
1301 int (*fn) ();
1302 Lisp_Object arg;
1303 {
1304 register int i;
1305 register Lisp_Object tail;
1306 CHECK_VECTOR (obarray, 1);
1307 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
1308 {
1309 tail = XVECTOR (obarray)->contents[i];
1310 if (XFASTINT (tail) != 0)
1311 while (1)
1312 {
1313 (*fn) (tail, arg);
1314 if (XSYMBOL (tail)->next == 0)
1315 break;
1316 XSET (tail, Lisp_Symbol, XSYMBOL (tail)->next);
1317 }
1318 }
1319 }
1320
1321 mapatoms_1 (sym, function)
1322 Lisp_Object sym, function;
1323 {
1324 call1 (function, sym);
1325 }
1326
1327 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
1328 "Call FUNCTION on every symbol in OBARRAY.\n\
1329 OBARRAY defaults to the value of `obarray'.")
1330 (function, obarray)
1331 Lisp_Object function, obarray;
1332 {
1333 Lisp_Object tem;
1334
1335 if (NILP (obarray)) obarray = Vobarray;
1336 obarray = check_obarray (obarray);
1337
1338 map_obarray (obarray, mapatoms_1, function);
1339 return Qnil;
1340 }
1341
1342 #define OBARRAY_SIZE 509
1343
1344 void
1345 init_obarray ()
1346 {
1347 Lisp_Object oblength;
1348 int hash;
1349 Lisp_Object *tem;
1350
1351 XFASTINT (oblength) = OBARRAY_SIZE;
1352
1353 Qnil = Fmake_symbol (make_pure_string ("nil", 3));
1354 Vobarray = Fmake_vector (oblength, make_number (0));
1355 initial_obarray = Vobarray;
1356 staticpro (&initial_obarray);
1357 /* Intern nil in the obarray */
1358 /* These locals are to kludge around a pyramid compiler bug. */
1359 hash = hash_string ("nil", 3);
1360 /* Separate statement here to avoid VAXC bug. */
1361 hash %= OBARRAY_SIZE;
1362 tem = &XVECTOR (Vobarray)->contents[hash];
1363 *tem = Qnil;
1364
1365 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7));
1366 XSYMBOL (Qnil)->function = Qunbound;
1367 XSYMBOL (Qunbound)->value = Qunbound;
1368 XSYMBOL (Qunbound)->function = Qunbound;
1369
1370 Qt = intern ("t");
1371 XSYMBOL (Qnil)->value = Qnil;
1372 XSYMBOL (Qnil)->plist = Qnil;
1373 XSYMBOL (Qt)->value = Qt;
1374
1375 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
1376 Vpurify_flag = Qt;
1377
1378 Qvariable_documentation = intern ("variable-documentation");
1379
1380 read_buffer_size = 100;
1381 read_buffer = (char *) malloc (read_buffer_size);
1382 }
1383 \f
1384 void
1385 defsubr (sname)
1386 struct Lisp_Subr *sname;
1387 {
1388 Lisp_Object sym;
1389 sym = intern (sname->symbol_name);
1390 XSET (XSYMBOL (sym)->function, Lisp_Subr, sname);
1391 }
1392
1393 #ifdef NOTDEF /* use fset in subr.el now */
1394 void
1395 defalias (sname, string)
1396 struct Lisp_Subr *sname;
1397 char *string;
1398 {
1399 Lisp_Object sym;
1400 sym = intern (string);
1401 XSET (XSYMBOL (sym)->function, Lisp_Subr, sname);
1402 }
1403 #endif /* NOTDEF */
1404
1405 /* New replacement for DefIntVar; it ignores the doc string argument
1406 on the assumption that make-docfile will handle that. */
1407 /* Define an "integer variable"; a symbol whose value is forwarded
1408 to a C variable of type int. Sample call: */
1409 /* DEFVARINT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
1410
1411 void
1412 defvar_int (namestring, address, doc)
1413 char *namestring;
1414 int *address;
1415 char *doc;
1416 {
1417 Lisp_Object sym;
1418 sym = intern (namestring);
1419 XSET (XSYMBOL (sym)->value, Lisp_Intfwd, address);
1420 }
1421
1422 /* Similar but define a variable whose value is T if address contains 1,
1423 NIL if address contains 0 */
1424
1425 void
1426 defvar_bool (namestring, address, doc)
1427 char *namestring;
1428 int *address;
1429 char *doc;
1430 {
1431 Lisp_Object sym;
1432 sym = intern (namestring);
1433 XSET (XSYMBOL (sym)->value, Lisp_Boolfwd, address);
1434 }
1435
1436 /* Similar but define a variable whose value is the Lisp Object stored at address. */
1437
1438 void
1439 defvar_lisp (namestring, address, doc)
1440 char *namestring;
1441 Lisp_Object *address;
1442 char *doc;
1443 {
1444 Lisp_Object sym;
1445 sym = intern (namestring);
1446 XSET (XSYMBOL (sym)->value, Lisp_Objfwd, address);
1447 staticpro (address);
1448 }
1449
1450 /* Similar but don't request gc-marking of the C variable.
1451 Used when that variable will be gc-marked for some other reason,
1452 since marking the same slot twice can cause trouble with strings. */
1453
1454 void
1455 defvar_lisp_nopro (namestring, address, doc)
1456 char *namestring;
1457 Lisp_Object *address;
1458 char *doc;
1459 {
1460 Lisp_Object sym;
1461 sym = intern (namestring);
1462 XSET (XSYMBOL (sym)->value, Lisp_Objfwd, address);
1463 }
1464
1465 #ifndef standalone
1466
1467 /* Similar but define a variable whose value is the Lisp Object stored in
1468 the current buffer. address is the address of the slot in the buffer that is current now. */
1469
1470 void
1471 defvar_per_buffer (namestring, address, doc)
1472 char *namestring;
1473 Lisp_Object *address;
1474 char *doc;
1475 {
1476 Lisp_Object sym;
1477 int offset;
1478 extern struct buffer buffer_local_symbols;
1479
1480 sym = intern (namestring);
1481 offset = (char *)address - (char *)current_buffer;
1482
1483 XSET (XSYMBOL (sym)->value, Lisp_Buffer_Objfwd,
1484 (Lisp_Object *) offset);
1485 *(Lisp_Object *)(offset + (char *)&buffer_local_symbols) = sym;
1486 if (*(int *)(offset + (char *)&buffer_local_flags) == 0)
1487 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
1488 slot of buffer_local_flags */
1489 abort ();
1490 }
1491
1492 #endif /* standalone */
1493 \f
1494 init_lread ()
1495 {
1496 char *normal;
1497
1498 /* Compute the default load-path. */
1499 #ifdef CANNOT_DUMP
1500 normal = PATH_LOADSEARCH;
1501 Vload_path = decode_env_path (0, normal);
1502 #else
1503 if (NILP (Vpurify_flag))
1504 normal = PATH_LOADSEARCH;
1505 else
1506 normal = PATH_DUMPLOADSEARCH;
1507
1508 /* In a dumped Emacs, we normally have to reset the value of
1509 Vload_path from PATH_LOADSEARCH, since the value that was dumped
1510 uses ../lisp, instead of the path of the installed elisp
1511 libraries. However, if it appears that Vload_path was changed
1512 from the default before dumping, don't override that value. */
1513 if (initialized)
1514 {
1515 Lisp_Object dump_path;
1516
1517 dump_path = decode_env_path (0, PATH_DUMPLOADSEARCH);
1518 if (! NILP (Fequal (dump_path, Vload_path)))
1519 Vload_path = decode_env_path (0, normal);
1520 }
1521 else
1522 Vload_path = decode_env_path (0, normal);
1523 #endif
1524
1525 /* Warn if dirs in the *standard* path don't exist. */
1526 {
1527 Lisp_Object path_tail;
1528
1529 for (path_tail = Vload_path;
1530 !NILP (path_tail);
1531 path_tail = XCONS (path_tail)->cdr)
1532 {
1533 Lisp_Object dirfile;
1534 dirfile = Fcar (path_tail);
1535 if (XTYPE (dirfile) == Lisp_String)
1536 {
1537 dirfile = Fdirectory_file_name (dirfile);
1538 if (access (XSTRING (dirfile)->data, 0) < 0)
1539 printf ("Warning: lisp library (%s) does not exist.\n",
1540 XSTRING (Fcar (path_tail))->data);
1541 }
1542 }
1543 }
1544
1545 /* If the EMACSLOADPATH environment variable is set, use its value.
1546 This doesn't apply if we're dumping. */
1547 if (NILP (Vpurify_flag)
1548 && egetenv ("EMACSLOADPATH"))
1549 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
1550
1551 Vvalues = Qnil;
1552
1553 load_in_progress = 0;
1554 }
1555
1556 void
1557 syms_of_lread ()
1558 {
1559 defsubr (&Sread);
1560 defsubr (&Sread_from_string);
1561 defsubr (&Sintern);
1562 defsubr (&Sintern_soft);
1563 defsubr (&Sload);
1564 defsubr (&Seval_buffer);
1565 defsubr (&Seval_region);
1566 defsubr (&Sread_char);
1567 defsubr (&Sread_char_exclusive);
1568 #ifdef HAVE_X_WINDOWS
1569 defsubr (&Sread_event);
1570 #endif /* HAVE_X_WINDOWS */
1571 defsubr (&Sget_file_char);
1572 defsubr (&Smapatoms);
1573
1574 DEFVAR_LISP ("obarray", &Vobarray,
1575 "Symbol table for use by `intern' and `read'.\n\
1576 It is a vector whose length ought to be prime for best results.\n\
1577 The vector's contents don't make sense if examined from Lisp programs;\n\
1578 to find all the symbols in an obarray, use `mapatoms'.");
1579
1580 DEFVAR_LISP ("values", &Vvalues,
1581 "List of values of all expressions which were read, evaluated and printed.\n\
1582 Order is reverse chronological.");
1583
1584 DEFVAR_LISP ("standard-input", &Vstandard_input,
1585 "Stream for read to get input from.\n\
1586 See documentation of `read' for possible values.");
1587 Vstandard_input = Qt;
1588
1589 DEFVAR_LISP ("load-path", &Vload_path,
1590 "*List of directories to search for files to load.\n\
1591 Each element is a string (directory name) or nil (try default directory).\n\
1592 Initialized based on EMACSLOADPATH environment variable, if any,\n\
1593 otherwise to default specified in by file `paths.h' when Emacs was built.");
1594
1595 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
1596 "Non-nil iff inside of `load'.");
1597
1598 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
1599 "An alist of expressions to be evalled when particular files are loaded.\n\
1600 Each element looks like (FILENAME FORMS...).\n\
1601 When `load' is run and the file-name argument is FILENAME,\n\
1602 the FORMS in the corresponding element are executed at the end of loading.\n\n\
1603 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
1604 with no directory specified, since that is how `load' is normally called.\n\
1605 An error in FORMS does not undo the load,\n\
1606 but does prevent execution of the rest of the FORMS.");
1607 Vafter_load_alist = Qnil;
1608
1609 Qstandard_input = intern ("standard-input");
1610 staticpro (&Qstandard_input);
1611
1612 Qread_char = intern ("read-char");
1613 staticpro (&Qread_char);
1614
1615 Qget_file_char = intern ("get-file-char");
1616 staticpro (&Qget_file_char);
1617 }