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