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