1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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)
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.
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. */
25 #include <sys/types.h>
37 #include "termhooks.h"
41 #include <sys/inode.h>
46 #include <unistd.h> /* to get X_OK */
59 #ifdef LISP_FLOAT_TYPE
65 #endif /* LISP_FLOAT_TYPE */
69 #endif /* HAVE_SETLOCALE */
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
;
83 extern Lisp_Object Qevent_symbol_element_mask
;
84 extern Lisp_Object Qfile_exists_p
;
86 /* non-zero if inside `load' */
89 /* Directory in which the sources were found. */
90 Lisp_Object Vsource_directory
;
92 /* Search path for files to be loaded. */
93 Lisp_Object Vload_path
;
95 /* File name of user's init file. */
96 Lisp_Object Vuser_init_file
;
98 /* This is the user-visible association list that maps features to
99 lists of defs in their load files. */
100 Lisp_Object Vload_history
;
102 /* This is used to build the load history. */
103 Lisp_Object Vcurrent_load_list
;
105 /* List of files that were preloaded. */
106 Lisp_Object Vpreloaded_file_list
;
108 /* Name of file actually being read by `load'. */
109 Lisp_Object Vload_file_name
;
111 /* Function to use for reading, in `load' and friends. */
112 Lisp_Object Vload_read_function
;
114 /* The association list of objects read with the #n=object form.
115 Each member of the list has the form (n . object), and is used to
116 look up the object for the corresponding #n# construct.
117 It must be set to nil before all top-level calls to read0. */
118 Lisp_Object read_objects
;
120 /* Nonzero means load should forcibly load all dynamic doc strings. */
121 static int load_force_doc_strings
;
123 /* Nonzero means read should convert strings to unibyte. */
124 static int load_convert_to_unibyte
;
126 /* Function to use for loading an Emacs lisp source file (not
127 compiled) instead of readevalloop. */
128 Lisp_Object Vload_source_file_function
;
130 /* List of descriptors now open for Fload. */
131 static Lisp_Object load_descriptor_list
;
133 /* File for get_file_char to read from. Use by load. */
134 static FILE *instream
;
136 /* When nonzero, read conses in pure space */
137 static int read_pure
;
139 /* For use within read-from-string (this reader is non-reentrant!!) */
140 static int read_from_string_index
;
141 static int read_from_string_index_byte
;
142 static int read_from_string_limit
;
144 /* Number of bytes left to read in the buffer character
145 that `readchar' has already advanced over. */
146 static int readchar_backlog
;
148 /* This contains the last string skipped with #@. */
149 static char *saved_doc_string
;
150 /* Length of buffer allocated in saved_doc_string. */
151 static int saved_doc_string_size
;
152 /* Length of actual data in saved_doc_string. */
153 static int saved_doc_string_length
;
154 /* This is the file position that string came from. */
155 static int saved_doc_string_position
;
157 /* This contains the previous string skipped with #@.
158 We copy it from saved_doc_string when a new string
159 is put in saved_doc_string. */
160 static char *prev_saved_doc_string
;
161 /* Length of buffer allocated in prev_saved_doc_string. */
162 static int prev_saved_doc_string_size
;
163 /* Length of actual data in prev_saved_doc_string. */
164 static int prev_saved_doc_string_length
;
165 /* This is the file position that string came from. */
166 static int prev_saved_doc_string_position
;
168 /* Nonzero means inside a new-style backquote
169 with no surrounding parentheses.
170 Fread initializes this to zero, so we need not specbind it
171 or worry about what happens to it when there is an error. */
172 static int new_backquote_flag
;
174 /* Handle unreading and rereading of characters.
175 Write READCHAR to read a character,
176 UNREAD(c) to unread c to be read again.
178 These macros actually read/unread a byte code, multibyte characters
179 are not handled here. The caller should manage them if necessary.
182 #define READCHAR readchar (readcharfun)
183 #define UNREAD(c) unreadchar (readcharfun, c)
186 readchar (readcharfun
)
187 Lisp_Object readcharfun
;
190 register int c
, mpos
;
192 if (BUFFERP (readcharfun
))
194 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
196 int pt_byte
= BUF_PT_BYTE (inbuffer
);
197 int orig_pt_byte
= pt_byte
;
199 if (readchar_backlog
> 0)
200 /* We get the address of the byte just passed,
201 which is the last byte of the character.
202 The other bytes in this character are consecutive with it,
203 because the gap can't be in the middle of a character. */
204 return *(BUF_BYTE_ADDRESS (inbuffer
, BUF_PT_BYTE (inbuffer
) - 1)
205 - --readchar_backlog
);
207 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
210 readchar_backlog
= -1;
212 if (! NILP (inbuffer
->enable_multibyte_characters
))
214 unsigned char workbuf
[4];
215 unsigned char *str
= workbuf
;
218 /* Fetch the character code from the buffer. */
219 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
220 BUF_INC_POS (inbuffer
, pt_byte
);
221 c
= STRING_CHAR (p
, pt_byte
- orig_pt_byte
);
223 /* Find the byte-sequence representation of that character. */
224 if (SINGLE_BYTE_CHAR_P (c
))
225 length
= 1, workbuf
[0] = c
;
227 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
229 /* If the bytes for this character in the buffer
230 are not identical with what the character code implies,
231 read the bytes one by one from the buffer. */
232 if (length
!= pt_byte
- orig_pt_byte
233 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
235 readchar_backlog
= pt_byte
- orig_pt_byte
;
236 c
= BUF_FETCH_BYTE (inbuffer
, orig_pt_byte
);
242 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
245 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
249 if (MARKERP (readcharfun
))
251 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
253 int bytepos
= marker_byte_position (readcharfun
);
254 int orig_bytepos
= bytepos
;
256 if (readchar_backlog
> 0)
257 /* We get the address of the byte just passed,
258 which is the last byte of the character.
259 The other bytes in this character are consecutive with it,
260 because the gap can't be in the middle of a character. */
261 return *(BUF_BYTE_ADDRESS (inbuffer
, XMARKER (readcharfun
)->bytepos
- 1)
262 - --readchar_backlog
);
264 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
267 readchar_backlog
= -1;
269 if (! NILP (inbuffer
->enable_multibyte_characters
))
271 unsigned char workbuf
[4];
272 unsigned char *str
= workbuf
;
275 /* Fetch the character code from the buffer. */
276 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
277 BUF_INC_POS (inbuffer
, bytepos
);
278 c
= STRING_CHAR (p
, bytepos
- orig_bytepos
);
280 /* Find the byte-sequence representation of that character. */
281 if (SINGLE_BYTE_CHAR_P (c
))
282 length
= 1, workbuf
[0] = c
;
284 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
286 /* If the bytes for this character in the buffer
287 are not identical with what the character code implies,
288 read the bytes one by one from the buffer. */
289 if (length
!= bytepos
- orig_bytepos
290 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
292 readchar_backlog
= bytepos
- orig_bytepos
;
293 c
= BUF_FETCH_BYTE (inbuffer
, orig_bytepos
);
299 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
303 XMARKER (readcharfun
)->bytepos
= bytepos
;
304 XMARKER (readcharfun
)->charpos
++;
309 if (EQ (readcharfun
, Qlambda
))
310 return read_bytecode_char (0);
312 if (EQ (readcharfun
, Qget_file_char
))
316 /* Interrupted reads have been observed while reading over the network */
317 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
326 if (STRINGP (readcharfun
))
328 if (read_from_string_index
>= read_from_string_limit
)
330 else if (STRING_MULTIBYTE (readcharfun
))
331 FETCH_STRING_CHAR_ADVANCE (c
, readcharfun
,
332 read_from_string_index
,
333 read_from_string_index_byte
);
335 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
340 tem
= call0 (readcharfun
);
347 /* Unread the character C in the way appropriate for the stream READCHARFUN.
348 If the stream is a user function, call it with the char as argument. */
351 unreadchar (readcharfun
, c
)
352 Lisp_Object readcharfun
;
356 /* Don't back up the pointer if we're unreading the end-of-input mark,
357 since readchar didn't advance it when we read it. */
359 else if (BUFFERP (readcharfun
))
361 struct buffer
*b
= XBUFFER (readcharfun
);
362 int bytepos
= BUF_PT_BYTE (b
);
364 if (readchar_backlog
>= 0)
369 if (! NILP (b
->enable_multibyte_characters
))
370 BUF_DEC_POS (b
, bytepos
);
374 BUF_PT_BYTE (b
) = bytepos
;
377 else if (MARKERP (readcharfun
))
379 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
380 int bytepos
= XMARKER (readcharfun
)->bytepos
;
382 if (readchar_backlog
>= 0)
386 XMARKER (readcharfun
)->charpos
--;
387 if (! NILP (b
->enable_multibyte_characters
))
388 BUF_DEC_POS (b
, bytepos
);
392 XMARKER (readcharfun
)->bytepos
= bytepos
;
395 else if (STRINGP (readcharfun
))
397 read_from_string_index
--;
398 read_from_string_index_byte
399 = string_char_to_byte (readcharfun
, read_from_string_index
);
401 else if (EQ (readcharfun
, Qlambda
))
402 read_bytecode_char (1);
403 else if (EQ (readcharfun
, Qget_file_char
))
404 ungetc (c
, instream
);
406 call1 (readcharfun
, make_number (c
));
409 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
410 static int read_multibyte ();
412 /* Get a character from the tty. */
414 extern Lisp_Object
read_char ();
416 /* Read input events until we get one that's acceptable for our purposes.
418 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
419 until we get a character we like, and then stuffed into
422 If ASCII_REQUIRED is non-zero, we check function key events to see
423 if the unmodified version of the symbol has a Qascii_character
424 property, and use that character, if present.
426 If ERROR_NONASCII is non-zero, we signal an error if the input we
427 get isn't an ASCII character with modifiers. If it's zero but
428 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
431 If INPUT_METHOD is nonzero, we invoke the current input method
432 if the character warrants that. */
435 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
437 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
440 return make_number (getchar ());
442 register Lisp_Object val
, delayed_switch_frame
;
444 delayed_switch_frame
= Qnil
;
446 /* Read until we get an acceptable event. */
448 val
= read_char (0, 0, 0,
449 (input_method
? Qnil
: Qt
),
455 /* switch-frame events are put off until after the next ASCII
456 character. This is better than signaling an error just because
457 the last characters were typed to a separate minibuffer frame,
458 for example. Eventually, some code which can deal with
459 switch-frame events will read it and process it. */
461 && EVENT_HAS_PARAMETERS (val
)
462 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
464 delayed_switch_frame
= val
;
470 /* Convert certain symbols to their ASCII equivalents. */
473 Lisp_Object tem
, tem1
, tem2
;
474 tem
= Fget (val
, Qevent_symbol_element_mask
);
477 tem1
= Fget (Fcar (tem
), Qascii_character
);
478 /* Merge this symbol's modifier bits
479 with the ASCII equivalent of its basic code. */
481 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
485 /* If we don't have a character now, deal with it appropriately. */
490 Vunread_command_events
= Fcons (val
, Qnil
);
491 error ("Non-character input-event");
498 if (! NILP (delayed_switch_frame
))
499 unread_switch_frame
= delayed_switch_frame
;
505 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 2, 0,
506 "Read a character from the command input (keyboard or macro).\n\
507 It is returned as a number.\n\
508 If the user generates an event which is not a character (i.e. a mouse\n\
509 click or function key event), `read-char' signals an error. As an\n\
510 exception, switch-frame events are put off until non-ASCII events can\n\
512 If you want to read non-character events, or ignore them, call\n\
513 `read-event' or `read-char-exclusive' instead.\n\
515 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
516 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
517 input method is turned on in the current buffer, that input method\n\
518 is used for reading a character.")
519 (prompt
, inherit_input_method
)
520 Lisp_Object prompt
, inherit_input_method
;
523 message_with_string ("%s", prompt
, 0);
524 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
));
527 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 2, 0,
528 "Read an event object from the input stream.\n\
529 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
530 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
531 input method is turned on in the current buffer, that input method\n\
532 is used for reading a character.")
533 (prompt
, inherit_input_method
)
534 Lisp_Object prompt
, inherit_input_method
;
537 message_with_string ("%s", prompt
, 0);
538 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
));
541 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 2, 0,
542 "Read a character from the command input (keyboard or macro).\n\
543 It is returned as a number. Non-character events are ignored.\n\
545 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
546 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
547 input method is turned on in the current buffer, that input method\n\
548 is used for reading a character.")
549 (prompt
, inherit_input_method
)
550 Lisp_Object prompt
, inherit_input_method
;
553 message_with_string ("%s", prompt
, 0);
554 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
));
557 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
558 "Don't use this yourself.")
561 register Lisp_Object val
;
562 XSETINT (val
, getc (instream
));
566 static void readevalloop ();
567 static Lisp_Object
load_unwind ();
568 static Lisp_Object
load_descriptor_unwind ();
570 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
571 "Execute a file of Lisp code named FILE.\n\
572 First try FILE with `.elc' appended, then try with `.el',\n\
573 then try FILE unmodified.\n\
574 This function searches the directories in `load-path'.\n\
575 If optional second arg NOERROR is non-nil,\n\
576 report no error if FILE doesn't exist.\n\
577 Print messages at start and end of loading unless\n\
578 optional third arg NOMESSAGE is non-nil.\n\
579 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
580 suffixes `.elc' or `.el' to the specified name FILE.\n\
581 If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
582 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
583 it ends in one of those suffixes or includes a directory name.\n\
584 Return t if file exists.")
585 (file
, noerror
, nomessage
, nosuffix
, must_suffix
)
586 Lisp_Object file
, noerror
, nomessage
, nosuffix
, must_suffix
;
588 register FILE *stream
;
589 register int fd
= -1;
590 register Lisp_Object lispstream
;
591 int count
= specpdl_ptr
- specpdl
;
595 /* 1 means we printed the ".el is newer" message. */
597 /* 1 means we are loading a compiled file. */
605 CHECK_STRING (file
, 0);
607 /* If file name is magic, call the handler. */
608 handler
= Ffind_file_name_handler (file
, Qload
);
610 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
612 /* Do this after the handler to avoid
613 the need to gcpro noerror, nomessage and nosuffix.
614 (Below here, we care only whether they are nil or not.) */
615 file
= Fsubstitute_in_file_name (file
);
617 /* Avoid weird lossage with null string as arg,
618 since it would try to load a directory as a Lisp file */
619 if (XSTRING (file
)->size
> 0)
621 int size
= XSTRING (file
)->size
;
625 if (! NILP (must_suffix
))
627 /* Don't insist on adding a suffix if FILE already ends with one. */
629 && !strcmp (XSTRING (file
)->data
+ size
- 3, ".el"))
632 && !strcmp (XSTRING (file
)->data
+ size
- 4, ".elc"))
634 /* Don't insist on adding a suffix
635 if the argument includes a directory name. */
636 else if (! NILP (Ffile_name_directory (file
)))
640 fd
= openp (Vload_path
, file
,
641 (!NILP (nosuffix
) ? ""
642 : ! NILP (must_suffix
) ? ".elc:.el"
652 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
653 Fcons (file
, Qnil
)));
658 if (EQ (Qt
, Vuser_init_file
))
659 Vuser_init_file
= found
;
661 /* If FD is 0, that means openp found a magic file. */
664 if (NILP (Fequal (found
, file
)))
665 /* If FOUND is a different file name from FILE,
666 find its handler even if we have already inhibited
667 the `load' operation on FILE. */
668 handler
= Ffind_file_name_handler (found
, Qt
);
670 handler
= Ffind_file_name_handler (found
, Qload
);
671 if (! NILP (handler
))
672 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
675 /* Load .elc files directly, but not when they are
676 remote and have no handler! */
677 if (!bcmp (&(XSTRING (found
)->data
[XSTRING (found
)->size
- 4]),
689 stat ((char *)XSTRING (found
)->data
, &s1
);
690 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 0;
691 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
692 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
694 /* Make the progress messages mention that source is newer. */
697 /* If we won't print another message, mention this anyway. */
698 if (! NILP (nomessage
))
699 message_with_string ("Source file `%s' newer than byte-compiled file",
702 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 'c';
706 /* We are loading a source file (*.el). */
707 if (!NILP (Vload_source_file_function
))
711 return call4 (Vload_source_file_function
, found
, file
,
712 NILP (noerror
) ? Qnil
: Qt
,
713 NILP (nomessage
) ? Qnil
: Qt
);
719 stream
= fopen ((char *) XSTRING (found
)->data
, fmode
);
720 #else /* not WINDOWSNT */
721 stream
= fdopen (fd
, fmode
);
722 #endif /* not WINDOWSNT */
726 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
729 if (! NILP (Vpurify_flag
))
730 Vpreloaded_file_list
= Fcons (file
, Vpreloaded_file_list
);
732 if (NILP (nomessage
))
735 message_with_string ("Loading %s (source)...", file
, 1);
737 message_with_string ("Loading %s (compiled; note, source file is newer)...",
739 else /* The typical case; compiled file newer than source file. */
740 message_with_string ("Loading %s...", file
, 1);
744 lispstream
= Fcons (Qnil
, Qnil
);
745 XSETFASTINT (XCONS (lispstream
)->car
, (EMACS_UINT
)stream
>> 16);
746 XSETFASTINT (XCONS (lispstream
)->cdr
, (EMACS_UINT
)stream
& 0xffff);
747 record_unwind_protect (load_unwind
, lispstream
);
748 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
749 specbind (Qload_file_name
, found
);
750 specbind (Qinhibit_file_name_operation
, Qnil
);
752 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
754 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0, Qnil
, Qnil
);
755 unbind_to (count
, Qnil
);
757 /* Run any load-hooks for this file. */
758 temp
= Fassoc (file
, Vafter_load_alist
);
760 Fprogn (Fcdr (temp
));
763 if (saved_doc_string
)
764 free (saved_doc_string
);
765 saved_doc_string
= 0;
766 saved_doc_string_size
= 0;
768 if (prev_saved_doc_string
)
769 free (prev_saved_doc_string
);
770 prev_saved_doc_string
= 0;
771 prev_saved_doc_string_size
= 0;
773 if (!noninteractive
&& NILP (nomessage
))
776 message_with_string ("Loading %s (source)...done", file
, 1);
778 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
780 else /* The typical case; compiled file newer than source file. */
781 message_with_string ("Loading %s...done", file
, 1);
787 load_unwind (stream
) /* used as unwind-protect function in load */
790 fclose ((FILE *) (XFASTINT (XCONS (stream
)->car
) << 16
791 | XFASTINT (XCONS (stream
)->cdr
)));
792 if (--load_in_progress
< 0) load_in_progress
= 0;
797 load_descriptor_unwind (oldlist
)
800 load_descriptor_list
= oldlist
;
804 /* Close all descriptors in use for Floads.
805 This is used when starting a subprocess. */
812 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
813 close (XFASTINT (XCONS (tail
)->car
));
818 complete_filename_p (pathname
)
819 Lisp_Object pathname
;
821 register unsigned char *s
= XSTRING (pathname
)->data
;
822 return (IS_DIRECTORY_SEP (s
[0])
823 || (XSTRING (pathname
)->size
> 2
824 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
834 /* Search for a file whose name is STR, looking in directories
835 in the Lisp list PATH, and trying suffixes from SUFFIX.
836 SUFFIX is a string containing possible suffixes separated by colons.
837 On success, returns a file descriptor. On failure, returns -1.
839 EXEC_ONLY nonzero means don't open the files,
840 just look for one that is executable. In this case,
841 returns 1 on success.
843 If STOREPTR is nonzero, it points to a slot where the name of
844 the file actually found should be stored as a Lisp string.
845 nil is stored there on failure.
847 If the file we find is remote, return 0
848 but store the found remote file name in *STOREPTR.
849 We do not check for remote files if EXEC_ONLY is nonzero. */
852 openp (path
, str
, suffix
, storeptr
, exec_only
)
853 Lisp_Object path
, str
;
855 Lisp_Object
*storeptr
;
861 register char *fn
= buf
;
864 Lisp_Object filename
;
872 if (complete_filename_p (str
))
875 for (; !NILP (path
); path
= Fcdr (path
))
879 filename
= Fexpand_file_name (str
, Fcar (path
));
880 if (!complete_filename_p (filename
))
881 /* If there are non-absolute elts in PATH (eg ".") */
882 /* Of course, this could conceivably lose if luser sets
883 default-directory to be something non-absolute... */
885 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
886 if (!complete_filename_p (filename
))
887 /* Give up on this path element! */
891 /* Calculate maximum size of any filename made from
892 this path element/specified file name and any possible suffix. */
893 want_size
= strlen (suffix
) + XSTRING (filename
)->size
+ 1;
894 if (fn_size
< want_size
)
895 fn
= (char *) alloca (fn_size
= 100 + want_size
);
899 /* Loop over suffixes. */
902 char *esuffix
= (char *) index (nsuffix
, ':');
903 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
906 /* Concatenate path element/specified name with the suffix.
907 If the directory starts with /:, remove that. */
908 if (XSTRING (filename
)->size
> 2
909 && XSTRING (filename
)->data
[0] == '/'
910 && XSTRING (filename
)->data
[1] == ':')
912 strncpy (fn
, XSTRING (filename
)->data
+ 2,
913 XSTRING (filename
)->size
- 2);
914 fn
[XSTRING (filename
)->size
- 2] = 0;
918 strncpy (fn
, XSTRING (filename
)->data
, XSTRING (filename
)->size
);
919 fn
[XSTRING (filename
)->size
] = 0;
922 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
923 strncat (fn
, nsuffix
, lsuffix
);
925 /* Check that the file exists and is not a directory. */
929 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
930 if (! NILP (handler
) && ! exec_only
)
935 string
= build_string (fn
);
936 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
937 : Ffile_readable_p (string
));
939 && ! NILP (Ffile_directory_p (build_string (fn
))))
944 /* We succeeded; return this descriptor and filename. */
946 *storeptr
= build_string (fn
);
953 int exists
= (stat (fn
, &st
) >= 0
954 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
957 /* Check that we can access or open it. */
959 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
961 fd
= open (fn
, O_RDONLY
, 0);
965 /* We succeeded; return this descriptor and filename. */
967 *storeptr
= build_string (fn
);
974 /* Advance to next suffix. */
977 nsuffix
+= lsuffix
+ 1;
988 /* Merge the list we've accumulated of globals from the current input source
989 into the load_history variable. The details depend on whether
990 the source has an associated file name or not. */
993 build_load_history (stream
, source
)
997 register Lisp_Object tail
, prev
, newelt
;
998 register Lisp_Object tem
, tem2
;
999 register int foundit
, loading
;
1001 loading
= stream
|| !NARROWED
;
1003 tail
= Vload_history
;
1006 while (!NILP (tail
))
1010 /* Find the feature's previous assoc list... */
1011 if (!NILP (Fequal (source
, Fcar (tem
))))
1015 /* If we're loading, remove it. */
1019 Vload_history
= Fcdr (tail
);
1021 Fsetcdr (prev
, Fcdr (tail
));
1024 /* Otherwise, cons on new symbols that are not already members. */
1027 tem2
= Vcurrent_load_list
;
1029 while (CONSP (tem2
))
1031 newelt
= Fcar (tem2
);
1033 if (NILP (Fmemq (newelt
, tem
)))
1034 Fsetcar (tail
, Fcons (Fcar (tem
),
1035 Fcons (newelt
, Fcdr (tem
))));
1048 /* If we're loading, cons the new assoc onto the front of load-history,
1049 the most-recently-loaded position. Also do this if we didn't find
1050 an existing member for the current source. */
1051 if (loading
|| !foundit
)
1052 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1057 unreadpure () /* Used as unwind-protect function in readevalloop */
1064 readevalloop_1 (old
)
1067 load_convert_to_unibyte
= ! NILP (old
);
1071 /* UNIBYTE specifies how to set load_convert_to_unibyte
1072 for this invocation.
1073 READFUN, if non-nil, is used instead of `read'. */
1076 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
, unibyte
, readfun
)
1077 Lisp_Object readcharfun
;
1079 Lisp_Object sourcename
;
1080 Lisp_Object (*evalfun
) ();
1082 Lisp_Object unibyte
, readfun
;
1085 register Lisp_Object val
;
1086 int count
= specpdl_ptr
- specpdl
;
1087 struct gcpro gcpro1
;
1088 struct buffer
*b
= 0;
1090 if (BUFFERP (readcharfun
))
1091 b
= XBUFFER (readcharfun
);
1092 else if (MARKERP (readcharfun
))
1093 b
= XMARKER (readcharfun
)->buffer
;
1095 specbind (Qstandard_input
, readcharfun
);
1096 specbind (Qcurrent_load_list
, Qnil
);
1097 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1098 load_convert_to_unibyte
= !NILP (unibyte
);
1100 readchar_backlog
= -1;
1102 GCPRO1 (sourcename
);
1104 LOADHIST_ATTACH (sourcename
);
1108 if (b
!= 0 && NILP (b
->name
))
1109 error ("Reading from killed buffer");
1115 while ((c
= READCHAR
) != '\n' && c
!= -1);
1120 /* Ignore whitespace here, so we can detect eof. */
1121 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
1124 if (!NILP (Vpurify_flag
) && c
== '(')
1126 int count1
= specpdl_ptr
- specpdl
;
1127 record_unwind_protect (unreadpure
, Qnil
);
1128 val
= read_list (-1, readcharfun
);
1129 unbind_to (count1
, Qnil
);
1134 read_objects
= Qnil
;
1135 if (! NILP (readfun
))
1136 val
= call1 (readfun
, readcharfun
);
1137 else if (! NILP (Vload_read_function
))
1138 val
= call1 (Vload_read_function
, readcharfun
);
1140 val
= read0 (readcharfun
);
1143 val
= (*evalfun
) (val
);
1146 Vvalues
= Fcons (val
, Vvalues
);
1147 if (EQ (Vstandard_output
, Qt
))
1154 build_load_history (stream
, sourcename
);
1157 unbind_to (count
, Qnil
);
1162 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 4, "",
1163 "Execute the current buffer as Lisp code.\n\
1164 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1165 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1166 PRINTFLAG controls printing of output:\n\
1167 nil means discard it; anything else is stream for print.\n\
1169 If the optional third argument FILENAME is non-nil,\n\
1170 it specifies the file name to use for `load-history'.\n\
1172 This function preserves the position of point.")
1173 (buffer
, printflag
, filename
, unibyte
)
1174 Lisp_Object buffer
, printflag
, filename
, unibyte
;
1176 int count
= specpdl_ptr
- specpdl
;
1177 Lisp_Object tem
, buf
;
1180 buf
= Fcurrent_buffer ();
1182 buf
= Fget_buffer (buffer
);
1184 error ("No such buffer");
1186 if (NILP (printflag
))
1191 if (NILP (filename
))
1192 filename
= XBUFFER (buf
)->filename
;
1194 specbind (Qstandard_output
, tem
);
1195 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1196 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1197 readevalloop (buf
, 0, filename
, Feval
, !NILP (printflag
), unibyte
, Qnil
);
1198 unbind_to (count
, Qnil
);
1204 XDEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
1205 "Execute the current buffer as Lisp code.\n\
1206 Programs can pass argument PRINTFLAG which controls printing of output:\n\
1207 nil means discard it; anything else is stream for print.\n\
1209 If there is no error, point does not move. If there is an error,\n\
1210 point remains at the end of the last character read from the buffer.")
1212 Lisp_Object printflag
;
1214 int count
= specpdl_ptr
- specpdl
;
1215 Lisp_Object tem
, cbuf
;
1217 cbuf
= Fcurrent_buffer ()
1219 if (NILP (printflag
))
1223 specbind (Qstandard_output
, tem
);
1224 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1226 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1227 !NILP (printflag
), Qnil
, Qnil
);
1228 return unbind_to (count
, Qnil
);
1232 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1233 "Execute the region as Lisp code.\n\
1234 When called from programs, expects two arguments,\n\
1235 giving starting and ending indices in the current buffer\n\
1236 of the text to be executed.\n\
1237 Programs can pass third argument PRINTFLAG which controls output:\n\
1238 nil means discard it; anything else is stream for printing it.\n\
1239 Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1240 instead of `read' to read each expression. It gets one argument\n\
1241 which is the input stream for reading characters.\n\
1243 This function does not move point.")
1244 (start
, end
, printflag
, read_function
)
1245 Lisp_Object start
, end
, printflag
, read_function
;
1247 int count
= specpdl_ptr
- specpdl
;
1248 Lisp_Object tem
, cbuf
;
1250 cbuf
= Fcurrent_buffer ();
1252 if (NILP (printflag
))
1256 specbind (Qstandard_output
, tem
);
1258 if (NILP (printflag
))
1259 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1260 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1262 /* This both uses start and checks its type. */
1264 Fnarrow_to_region (make_number (BEGV
), end
);
1265 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1266 !NILP (printflag
), Qnil
, read_function
);
1268 return unbind_to (count
, Qnil
);
1271 #endif /* standalone */
1273 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1274 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1275 If STREAM is nil, use the value of `standard-input' (which see).\n\
1276 STREAM or the value of `standard-input' may be:\n\
1277 a buffer (read from point and advance it)\n\
1278 a marker (read from where it points and advance it)\n\
1279 a function (call it with no arguments for each character,\n\
1280 call it with a char as argument to push a char back)\n\
1281 a string (takes text from string, starting at the beginning)\n\
1282 t (read text line using minibuffer and use it).")
1286 extern Lisp_Object
Fread_minibuffer ();
1289 stream
= Vstandard_input
;
1290 if (EQ (stream
, Qt
))
1291 stream
= Qread_char
;
1293 readchar_backlog
= -1;
1294 new_backquote_flag
= 0;
1295 read_objects
= Qnil
;
1298 if (EQ (stream
, Qread_char
))
1299 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1302 if (STRINGP (stream
))
1303 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1305 return read0 (stream
);
1308 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1309 "Read one Lisp expression which is represented as text by STRING.\n\
1310 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1311 START and END optionally delimit a substring of STRING from which to read;\n\
1312 they default to 0 and (length STRING) respectively.")
1313 (string
, start
, end
)
1314 Lisp_Object string
, start
, end
;
1316 int startval
, endval
;
1319 CHECK_STRING (string
,0);
1322 endval
= XSTRING (string
)->size
;
1325 CHECK_NUMBER (end
, 2);
1326 endval
= XINT (end
);
1327 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1328 args_out_of_range (string
, end
);
1335 CHECK_NUMBER (start
, 1);
1336 startval
= XINT (start
);
1337 if (startval
< 0 || startval
> endval
)
1338 args_out_of_range (string
, start
);
1341 read_from_string_index
= startval
;
1342 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1343 read_from_string_limit
= endval
;
1345 new_backquote_flag
= 0;
1346 read_objects
= Qnil
;
1348 tem
= read0 (string
);
1349 return Fcons (tem
, make_number (read_from_string_index
));
1352 /* Use this for recursive reads, in contexts where internal tokens
1357 Lisp_Object readcharfun
;
1359 register Lisp_Object val
;
1362 val
= read1 (readcharfun
, &c
, 0);
1364 Fsignal (Qinvalid_read_syntax
, Fcons (Fmake_string (make_number (1),
1371 static int read_buffer_size
;
1372 static char *read_buffer
;
1374 /* Read multibyte form and return it as a character. C is a first
1375 byte of multibyte form, and rest of them are read from
1379 read_multibyte (c
, readcharfun
)
1381 Lisp_Object readcharfun
;
1383 /* We need the actual character code of this multibyte
1385 unsigned char str
[MAX_LENGTH_OF_MULTI_BYTE_FORM
];
1389 while ((c
= READCHAR
) >= 0xA0
1390 && len
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1393 return STRING_CHAR (str
, len
);
1396 /* Read a \-escape sequence, assuming we already read the `\'. */
1399 read_escape (readcharfun
, stringp
)
1400 Lisp_Object readcharfun
;
1403 register int c
= READCHAR
;
1407 error ("End of file");
1437 error ("Invalid escape character syntax");
1440 c
= read_escape (readcharfun
, 0);
1441 return c
| meta_modifier
;
1446 error ("Invalid escape character syntax");
1449 c
= read_escape (readcharfun
, 0);
1450 return c
| shift_modifier
;
1455 error ("Invalid escape character syntax");
1458 c
= read_escape (readcharfun
, 0);
1459 return c
| hyper_modifier
;
1464 error ("Invalid escape character syntax");
1467 c
= read_escape (readcharfun
, 0);
1468 return c
| alt_modifier
;
1473 error ("Invalid escape character syntax");
1476 c
= read_escape (readcharfun
, 0);
1477 return c
| super_modifier
;
1482 error ("Invalid escape character syntax");
1486 c
= read_escape (readcharfun
, 0);
1487 if ((c
& 0177) == '?')
1489 /* ASCII control chars are made from letters (both cases),
1490 as well as the non-letters within 0100...0137. */
1491 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1492 return (c
& (037 | ~0177));
1493 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1494 return (c
& (037 | ~0177));
1496 return c
| ctrl_modifier
;
1506 /* An octal escape, as in ANSI C. */
1508 register int i
= c
- '0';
1509 register int count
= 0;
1512 if ((c
= READCHAR
) >= '0' && c
<= '7')
1527 /* A hex escape, as in ANSI C. */
1533 if (c
>= '0' && c
<= '9')
1538 else if ((c
>= 'a' && c
<= 'f')
1539 || (c
>= 'A' && c
<= 'F'))
1542 if (c
>= 'a' && c
<= 'f')
1557 if (BASE_LEADING_CODE_P (c
))
1558 c
= read_multibyte (c
, readcharfun
);
1563 /* If the next token is ')' or ']' or '.', we store that character
1564 in *PCH and the return value is not interesting. Else, we store
1565 zero in *PCH and we read and return one lisp object.
1567 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1570 read1 (readcharfun
, pch
, first_in_list
)
1571 register Lisp_Object readcharfun
;
1576 int uninterned_symbol
= 0;
1583 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1588 return read_list (0, readcharfun
);
1591 return read_vector (readcharfun
, 0);
1608 tmp
= read_vector (readcharfun
, 0);
1609 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1610 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1611 error ("Invalid size char-table");
1612 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1613 XCHAR_TABLE (tmp
)->top
= Qt
;
1622 tmp
= read_vector (readcharfun
, 0);
1623 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1624 error ("Invalid size char-table");
1625 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1626 XCHAR_TABLE (tmp
)->top
= Qnil
;
1629 Fsignal (Qinvalid_read_syntax
,
1630 Fcons (make_string ("#^^", 3), Qnil
));
1632 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1637 length
= read1 (readcharfun
, pch
, first_in_list
);
1641 Lisp_Object tmp
, val
;
1642 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1646 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1647 if (size_in_chars
!= XSTRING (tmp
)->size
1648 /* We used to print 1 char too many
1649 when the number of bits was a multiple of 8.
1650 Accept such input in case it came from an old version. */
1651 && ! (XFASTINT (length
)
1652 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1653 Fsignal (Qinvalid_read_syntax
,
1654 Fcons (make_string ("#&...", 5), Qnil
));
1656 val
= Fmake_bool_vector (length
, Qnil
);
1657 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1659 /* Clear the extraneous bits in the last byte. */
1660 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1661 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1662 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1665 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1670 /* Accept compiled functions at read-time so that we don't have to
1671 build them using function calls. */
1673 tmp
= read_vector (readcharfun
, 1);
1674 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1675 XVECTOR (tmp
)->contents
);
1677 #ifdef USE_TEXT_PROPERTIES
1681 struct gcpro gcpro1
;
1684 /* Read the string itself. */
1685 tmp
= read1 (readcharfun
, &ch
, 0);
1686 if (ch
!= 0 || !STRINGP (tmp
))
1687 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1689 /* Read the intervals and their properties. */
1692 Lisp_Object beg
, end
, plist
;
1694 beg
= read1 (readcharfun
, &ch
, 0);
1698 end
= read1 (readcharfun
, &ch
, 0);
1700 plist
= read1 (readcharfun
, &ch
, 0);
1702 Fsignal (Qinvalid_read_syntax
,
1703 Fcons (build_string ("invalid string property list"),
1705 Fset_text_properties (beg
, end
, plist
, tmp
);
1711 /* #@NUMBER is used to skip NUMBER following characters.
1712 That's used in .elc files to skip over doc strings
1713 and function definitions. */
1718 /* Read a decimal integer. */
1719 while ((c
= READCHAR
) >= 0
1720 && c
>= '0' && c
<= '9')
1728 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1730 /* If we are supposed to force doc strings into core right now,
1731 record the last string that we skipped,
1732 and record where in the file it comes from. */
1734 /* But first exchange saved_doc_string
1735 with prev_saved_doc_string, so we save two strings. */
1737 char *temp
= saved_doc_string
;
1738 int temp_size
= saved_doc_string_size
;
1739 int temp_pos
= saved_doc_string_position
;
1740 int temp_len
= saved_doc_string_length
;
1742 saved_doc_string
= prev_saved_doc_string
;
1743 saved_doc_string_size
= prev_saved_doc_string_size
;
1744 saved_doc_string_position
= prev_saved_doc_string_position
;
1745 saved_doc_string_length
= prev_saved_doc_string_length
;
1747 prev_saved_doc_string
= temp
;
1748 prev_saved_doc_string_size
= temp_size
;
1749 prev_saved_doc_string_position
= temp_pos
;
1750 prev_saved_doc_string_length
= temp_len
;
1753 if (saved_doc_string_size
== 0)
1755 saved_doc_string_size
= nskip
+ 100;
1756 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1758 if (nskip
> saved_doc_string_size
)
1760 saved_doc_string_size
= nskip
+ 100;
1761 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1762 saved_doc_string_size
);
1765 saved_doc_string_position
= ftell (instream
);
1767 /* Copy that many characters into saved_doc_string. */
1768 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1769 saved_doc_string
[i
] = c
= READCHAR
;
1771 saved_doc_string_length
= i
;
1775 /* Skip that many characters. */
1776 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1783 return Vload_file_name
;
1785 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1786 /* #:foo is the uninterned symbol named foo. */
1789 uninterned_symbol
= 1;
1793 /* Reader forms that can reuse previously read objects. */
1794 if (c
>= '0' && c
<= '9')
1799 /* Read a non-negative integer. */
1800 while (c
>= '0' && c
<= '9')
1806 /* #n=object returns object, but associates it with n for #n#. */
1809 tem
= read0 (readcharfun
);
1810 read_objects
= Fcons (Fcons (make_number (n
), tem
), read_objects
);
1813 /* #n# returns a previously read object. */
1816 tem
= Fassq (make_number (n
), read_objects
);
1819 /* Fall through to error message. */
1821 /* Fall through to error message. */
1825 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1828 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1833 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1843 new_backquote_flag
= 1;
1844 value
= read0 (readcharfun
);
1845 new_backquote_flag
= 0;
1847 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1851 if (new_backquote_flag
)
1853 Lisp_Object comma_type
= Qnil
;
1858 comma_type
= Qcomma_at
;
1860 comma_type
= Qcomma_dot
;
1863 if (ch
>= 0) UNREAD (ch
);
1864 comma_type
= Qcomma
;
1867 new_backquote_flag
= 0;
1868 value
= read0 (readcharfun
);
1869 new_backquote_flag
= 1;
1870 return Fcons (comma_type
, Fcons (value
, Qnil
));
1877 register Lisp_Object val
;
1880 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1883 c
= read_escape (readcharfun
, 0);
1884 else if (BASE_LEADING_CODE_P (c
))
1885 c
= read_multibyte (c
, readcharfun
);
1887 return make_number (c
);
1892 register char *p
= read_buffer
;
1893 register char *end
= read_buffer
+ read_buffer_size
;
1895 /* Nonzero if we saw an escape sequence specifying
1896 a multibyte character. */
1897 int force_multibyte
= 0;
1898 /* Nonzero if we saw an escape sequence specifying
1899 a single-byte character. */
1900 int force_singlebyte
= 0;
1904 while ((c
= READCHAR
) >= 0
1907 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1909 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1910 p
+= new - read_buffer
;
1911 read_buffer
+= new - read_buffer
;
1912 end
= read_buffer
+ read_buffer_size
;
1917 c
= read_escape (readcharfun
, 1);
1919 /* C is -1 if \ newline has just been seen */
1922 if (p
== read_buffer
)
1927 /* If an escape specifies a non-ASCII single-byte character,
1928 this must be a unibyte string. */
1929 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_META
))
1930 && ! ASCII_BYTE_P (c
))
1931 force_singlebyte
= 1;
1934 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_META
)))
1936 unsigned char workbuf
[4];
1937 unsigned char *str
= workbuf
;
1940 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
1942 force_multibyte
= 1;
1944 bcopy (str
, p
, length
);
1949 /* Allow `\C- ' and `\C-?'. */
1950 if (c
== (CHAR_CTL
| ' '))
1952 else if (c
== (CHAR_CTL
| '?'))
1956 /* Move the meta bit to the right place for a string. */
1957 c
= (c
& ~CHAR_META
) | 0x80;
1959 error ("Invalid modifier in string");
1964 return Fsignal (Qend_of_file
, Qnil
);
1966 /* If purifying, and string starts with \ newline,
1967 return zero instead. This is for doc strings
1968 that we are really going to find in etc/DOC.nn.nn */
1969 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
1970 return make_number (0);
1972 if (force_multibyte
)
1973 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1974 else if (force_singlebyte
)
1975 nchars
= p
- read_buffer
;
1976 else if (load_convert_to_unibyte
)
1979 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1980 if (p
- read_buffer
!= nchars
)
1982 string
= make_multibyte_string (read_buffer
, nchars
,
1984 return Fstring_make_unibyte (string
);
1987 else if (EQ (readcharfun
, Qget_file_char
)
1988 || EQ (readcharfun
, Qlambda
))
1989 /* Nowadays, reading directly from a file
1990 is used only for compiled Emacs Lisp files,
1991 and those always use the Emacs internal encoding.
1992 Meanwhile, Qlambda is used for reading dynamic byte code
1993 (compiled with byte-compile-dynamic = t). */
1994 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1996 /* In all other cases, if we read these bytes as
1997 separate characters, treat them as separate characters now. */
1998 nchars
= p
- read_buffer
;
2001 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2003 || (p
- read_buffer
!= nchars
)));
2004 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2006 || (p
- read_buffer
!= nchars
)));
2011 #ifdef LISP_FLOAT_TYPE
2012 /* If a period is followed by a number, then we should read it
2013 as a floating point number. Otherwise, it denotes a dotted
2015 int next_char
= READCHAR
;
2018 if (! (next_char
>= '0' && next_char
<= '9'))
2025 /* Otherwise, we fall through! Note that the atom-reading loop
2026 below will now loop at least once, assuring that we will not
2027 try to UNREAD two characters in a row. */
2031 if (c
<= 040) goto retry
;
2033 register char *p
= read_buffer
;
2037 register char *end
= read_buffer
+ read_buffer_size
;
2040 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2041 || c
== '(' || c
== ')'
2042 #ifndef LISP_FLOAT_TYPE
2043 /* If we have floating-point support, then we need
2044 to allow <digits><dot><digits>. */
2046 #endif /* not LISP_FLOAT_TYPE */
2047 || c
== '[' || c
== ']' || c
== '#'
2050 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
2052 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2053 p
+= new - read_buffer
;
2054 read_buffer
+= new - read_buffer
;
2055 end
= read_buffer
+ read_buffer_size
;
2063 if (! SINGLE_BYTE_CHAR_P (c
))
2065 unsigned char workbuf
[4];
2066 unsigned char *str
= workbuf
;
2069 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
2071 bcopy (str
, p
, length
);
2082 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2083 p
+= new - read_buffer
;
2084 read_buffer
+= new - read_buffer
;
2085 /* end = read_buffer + read_buffer_size; */
2092 if (!quoted
&& !uninterned_symbol
)
2095 register Lisp_Object val
;
2097 if (*p1
== '+' || *p1
== '-') p1
++;
2098 /* Is it an integer? */
2101 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2102 #ifdef LISP_FLOAT_TYPE
2103 /* Integers can have trailing decimal points. */
2104 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2107 /* It is an integer. */
2109 #ifdef LISP_FLOAT_TYPE
2113 if (sizeof (int) == sizeof (EMACS_INT
))
2114 XSETINT (val
, atoi (read_buffer
));
2115 else if (sizeof (long) == sizeof (EMACS_INT
))
2116 XSETINT (val
, atol (read_buffer
));
2122 #ifdef LISP_FLOAT_TYPE
2123 if (isfloat_string (read_buffer
))
2125 /* Compute NaN and infinities using 0.0 in a variable,
2126 to cope with compilers that think they are smarter
2132 /* Negate the value ourselves. This treats 0, NaNs,
2133 and infinity properly on IEEE floating point hosts,
2134 and works around a common bug where atof ("-0.0")
2136 int negative
= read_buffer
[0] == '-';
2138 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2139 returns 1, is if the input ends in e+INF or e+NaN. */
2146 value
= zero
/ zero
;
2149 value
= atof (read_buffer
+ negative
);
2153 return make_float (negative
? - value
: value
);
2158 if (uninterned_symbol
)
2159 return make_symbol (read_buffer
);
2161 return intern (read_buffer
);
2166 #ifdef LISP_FLOAT_TYPE
2183 if (*cp
== '+' || *cp
== '-')
2186 if (*cp
>= '0' && *cp
<= '9')
2189 while (*cp
>= '0' && *cp
<= '9')
2197 if (*cp
>= '0' && *cp
<= '9')
2200 while (*cp
>= '0' && *cp
<= '9')
2203 if (*cp
== 'e' || *cp
== 'E')
2207 if (*cp
== '+' || *cp
== '-')
2211 if (*cp
>= '0' && *cp
<= '9')
2214 while (*cp
>= '0' && *cp
<= '9')
2217 else if (cp
== start
)
2219 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2224 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2230 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2231 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2232 || state
== (DOT_CHAR
|TRAIL_INT
)
2233 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2234 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2235 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2237 #endif /* LISP_FLOAT_TYPE */
2240 read_vector (readcharfun
, bytecodeflag
)
2241 Lisp_Object readcharfun
;
2246 register Lisp_Object
*ptr
;
2247 register Lisp_Object tem
, item
, vector
;
2248 register struct Lisp_Cons
*otem
;
2251 tem
= read_list (1, readcharfun
);
2252 len
= Flength (tem
);
2253 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2255 size
= XVECTOR (vector
)->size
;
2256 ptr
= XVECTOR (vector
)->contents
;
2257 for (i
= 0; i
< size
; i
++)
2260 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2261 bytecode object, the docstring containing the bytecode and
2262 constants values must be treated as unibyte and passed to
2263 Fread, to get the actual bytecode string and constants vector. */
2264 if (bytecodeflag
&& load_force_doc_strings
)
2266 if (i
== COMPILED_BYTECODE
)
2268 if (!STRINGP (item
))
2269 error ("invalid byte code");
2271 /* Delay handling the bytecode slot until we know whether
2272 it is lazily-loaded (we can tell by whether the
2273 constants slot is nil). */
2274 ptr
[COMPILED_CONSTANTS
] = item
;
2277 else if (i
== COMPILED_CONSTANTS
)
2279 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2283 /* Coerce string to unibyte (like string-as-unibyte,
2284 but without generating extra garbage and
2285 guaranteeing no change in the contents). */
2286 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2287 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2289 item
= Fread (bytestr
);
2291 error ("invalid byte code");
2293 otem
= XCONS (item
);
2294 bytestr
= XCONS (item
)->car
;
2295 item
= XCONS (item
)->cdr
;
2299 /* Now handle the bytecode slot. */
2300 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2303 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2311 /* FLAG = 1 means check for ] to terminate rather than ) and .
2312 FLAG = -1 means check for starting with defun
2313 and make structure pure. */
2316 read_list (flag
, readcharfun
)
2318 register Lisp_Object readcharfun
;
2320 /* -1 means check next element for defun,
2321 0 means don't check,
2322 1 means already checked and found defun. */
2323 int defunflag
= flag
< 0 ? -1 : 0;
2324 Lisp_Object val
, tail
;
2325 register Lisp_Object elt
, tem
;
2326 struct gcpro gcpro1
, gcpro2
;
2327 /* 0 is the normal case.
2328 1 means this list is a doc reference; replace it with the number 0.
2329 2 means this list is a doc reference; replace it with the doc string. */
2330 int doc_reference
= 0;
2332 /* Initialize this to 1 if we are reading a list. */
2333 int first_in_list
= flag
<= 0;
2342 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2347 /* While building, if the list starts with #$, treat it specially. */
2348 if (EQ (elt
, Vload_file_name
)
2350 && !NILP (Vpurify_flag
))
2352 if (NILP (Vdoc_file_name
))
2353 /* We have not yet called Snarf-documentation, so assume
2354 this file is described in the DOC-MM.NN file
2355 and Snarf-documentation will fill in the right value later.
2356 For now, replace the whole list with 0. */
2359 /* We have already called Snarf-documentation, so make a relative
2360 file name for this file, so it can be found properly
2361 in the installed Lisp directory.
2362 We don't use Fexpand_file_name because that would make
2363 the directory absolute now. */
2364 elt
= concat2 (build_string ("../lisp/"),
2365 Ffile_name_nondirectory (elt
));
2367 else if (EQ (elt
, Vload_file_name
)
2369 && load_force_doc_strings
)
2378 Fsignal (Qinvalid_read_syntax
,
2379 Fcons (make_string (") or . in a vector", 18), Qnil
));
2387 XCONS (tail
)->cdr
= read0 (readcharfun
);
2389 val
= read0 (readcharfun
);
2390 read1 (readcharfun
, &ch
, 0);
2394 if (doc_reference
== 1)
2395 return make_number (0);
2396 if (doc_reference
== 2)
2398 /* Get a doc string from the file we are loading.
2399 If it's in saved_doc_string, get it from there. */
2400 int pos
= XINT (XCONS (val
)->cdr
);
2401 /* Position is negative for user variables. */
2402 if (pos
< 0) pos
= -pos
;
2403 if (pos
>= saved_doc_string_position
2404 && pos
< (saved_doc_string_position
2405 + saved_doc_string_length
))
2407 int start
= pos
- saved_doc_string_position
;
2410 /* Process quoting with ^A,
2411 and find the end of the string,
2412 which is marked with ^_ (037). */
2413 for (from
= start
, to
= start
;
2414 saved_doc_string
[from
] != 037;)
2416 int c
= saved_doc_string
[from
++];
2419 c
= saved_doc_string
[from
++];
2421 saved_doc_string
[to
++] = c
;
2423 saved_doc_string
[to
++] = 0;
2425 saved_doc_string
[to
++] = 037;
2428 saved_doc_string
[to
++] = c
;
2431 return make_string (saved_doc_string
+ start
,
2434 /* Look in prev_saved_doc_string the same way. */
2435 else if (pos
>= prev_saved_doc_string_position
2436 && pos
< (prev_saved_doc_string_position
2437 + prev_saved_doc_string_length
))
2439 int start
= pos
- prev_saved_doc_string_position
;
2442 /* Process quoting with ^A,
2443 and find the end of the string,
2444 which is marked with ^_ (037). */
2445 for (from
= start
, to
= start
;
2446 prev_saved_doc_string
[from
] != 037;)
2448 int c
= prev_saved_doc_string
[from
++];
2451 c
= prev_saved_doc_string
[from
++];
2453 prev_saved_doc_string
[to
++] = c
;
2455 prev_saved_doc_string
[to
++] = 0;
2457 prev_saved_doc_string
[to
++] = 037;
2460 prev_saved_doc_string
[to
++] = c
;
2463 return make_string (prev_saved_doc_string
+ start
,
2467 return get_doc_string (val
, 0, 0);
2472 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2474 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2476 tem
= (read_pure
&& flag
<= 0
2477 ? pure_cons (elt
, Qnil
)
2478 : Fcons (elt
, Qnil
));
2480 XCONS (tail
)->cdr
= tem
;
2485 defunflag
= EQ (elt
, Qdefun
);
2486 else if (defunflag
> 0)
2491 Lisp_Object Vobarray
;
2492 Lisp_Object initial_obarray
;
2494 /* oblookup stores the bucket number here, for the sake of Funintern. */
2496 int oblookup_last_bucket_number
;
2498 static int hash_string ();
2499 Lisp_Object
oblookup ();
2501 /* Get an error if OBARRAY is not an obarray.
2502 If it is one, return it. */
2505 check_obarray (obarray
)
2506 Lisp_Object obarray
;
2508 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2510 /* If Vobarray is now invalid, force it to be valid. */
2511 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2513 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2518 /* Intern the C string STR: return a symbol with that name,
2519 interned in the current obarray. */
2526 int len
= strlen (str
);
2527 Lisp_Object obarray
;
2530 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2531 obarray
= check_obarray (obarray
);
2532 tem
= oblookup (obarray
, str
, len
, len
);
2535 return Fintern (make_string (str
, len
), obarray
);
2538 /* Create an uninterned symbol with name STR. */
2544 int len
= strlen (str
);
2546 return Fmake_symbol ((!NILP (Vpurify_flag
)
2547 ? make_pure_string (str
, len
, len
, 0)
2548 : make_string (str
, len
)));
2551 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2552 "Return the canonical symbol whose name is STRING.\n\
2553 If there is none, one is created by this function and returned.\n\
2554 A second optional argument specifies the obarray to use;\n\
2555 it defaults to the value of `obarray'.")
2557 Lisp_Object string
, obarray
;
2559 register Lisp_Object tem
, sym
, *ptr
;
2561 if (NILP (obarray
)) obarray
= Vobarray
;
2562 obarray
= check_obarray (obarray
);
2564 CHECK_STRING (string
, 0);
2566 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2567 XSTRING (string
)->size
,
2568 STRING_BYTES (XSTRING (string
)));
2569 if (!INTEGERP (tem
))
2572 if (!NILP (Vpurify_flag
))
2573 string
= Fpurecopy (string
);
2574 sym
= Fmake_symbol (string
);
2575 XSYMBOL (sym
)->obarray
= obarray
;
2577 if ((XSTRING (string
)->data
[0] == ':')
2578 && EQ (obarray
, initial_obarray
))
2579 XSYMBOL (sym
)->value
= sym
;
2581 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2583 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2585 XSYMBOL (sym
)->next
= 0;
2590 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2591 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
2592 A second optional argument specifies the obarray to use;\n\
2593 it defaults to the value of `obarray'.")
2595 Lisp_Object string
, obarray
;
2597 register Lisp_Object tem
;
2599 if (NILP (obarray
)) obarray
= Vobarray
;
2600 obarray
= check_obarray (obarray
);
2602 CHECK_STRING (string
, 0);
2604 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2605 XSTRING (string
)->size
,
2606 STRING_BYTES (XSTRING (string
)));
2607 if (!INTEGERP (tem
))
2612 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2613 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2614 The value is t if a symbol was found and deleted, nil otherwise.\n\
2615 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2616 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2617 OBARRAY defaults to the value of the variable `obarray'.")
2619 Lisp_Object name
, obarray
;
2621 register Lisp_Object string
, tem
;
2624 if (NILP (obarray
)) obarray
= Vobarray
;
2625 obarray
= check_obarray (obarray
);
2628 XSETSTRING (string
, XSYMBOL (name
)->name
);
2631 CHECK_STRING (name
, 0);
2635 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2636 XSTRING (string
)->size
,
2637 STRING_BYTES (XSTRING (string
)));
2640 /* If arg was a symbol, don't delete anything but that symbol itself. */
2641 if (SYMBOLP (name
) && !EQ (name
, tem
))
2644 XSYMBOL (tem
)->obarray
= Qnil
;
2646 hash
= oblookup_last_bucket_number
;
2648 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2650 if (XSYMBOL (tem
)->next
)
2651 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2653 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2657 Lisp_Object tail
, following
;
2659 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2660 XSYMBOL (tail
)->next
;
2663 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2664 if (EQ (following
, tem
))
2666 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2675 /* Return the symbol in OBARRAY whose names matches the string
2676 of SIZE characters (SIZE_BYTE bytes) at PTR.
2677 If there is no such symbol in OBARRAY, return nil.
2679 Also store the bucket number in oblookup_last_bucket_number. */
2682 oblookup (obarray
, ptr
, size
, size_byte
)
2683 Lisp_Object obarray
;
2685 int size
, size_byte
;
2689 register Lisp_Object tail
;
2690 Lisp_Object bucket
, tem
;
2692 if (!VECTORP (obarray
)
2693 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2695 obarray
= check_obarray (obarray
);
2696 obsize
= XVECTOR (obarray
)->size
;
2698 /* This is sometimes needed in the middle of GC. */
2699 obsize
&= ~ARRAY_MARK_FLAG
;
2700 /* Combining next two lines breaks VMS C 2.3. */
2701 hash
= hash_string (ptr
, size_byte
);
2703 bucket
= XVECTOR (obarray
)->contents
[hash
];
2704 oblookup_last_bucket_number
= hash
;
2705 if (XFASTINT (bucket
) == 0)
2707 else if (!SYMBOLP (bucket
))
2708 error ("Bad data in guts of obarray"); /* Like CADR error message */
2710 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2712 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2713 && XSYMBOL (tail
)->name
->size
== size
2714 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2716 else if (XSYMBOL (tail
)->next
== 0)
2719 XSETINT (tem
, hash
);
2724 hash_string (ptr
, len
)
2728 register unsigned char *p
= ptr
;
2729 register unsigned char *end
= p
+ len
;
2730 register unsigned char c
;
2731 register int hash
= 0;
2736 if (c
>= 0140) c
-= 40;
2737 hash
= ((hash
<<3) + (hash
>>28) + c
);
2739 return hash
& 07777777777;
2743 map_obarray (obarray
, fn
, arg
)
2744 Lisp_Object obarray
;
2745 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2749 register Lisp_Object tail
;
2750 CHECK_VECTOR (obarray
, 1);
2751 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2753 tail
= XVECTOR (obarray
)->contents
[i
];
2758 if (XSYMBOL (tail
)->next
== 0)
2760 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2766 mapatoms_1 (sym
, function
)
2767 Lisp_Object sym
, function
;
2769 call1 (function
, sym
);
2772 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2773 "Call FUNCTION on every symbol in OBARRAY.\n\
2774 OBARRAY defaults to the value of `obarray'.")
2776 Lisp_Object function
, obarray
;
2780 if (NILP (obarray
)) obarray
= Vobarray
;
2781 obarray
= check_obarray (obarray
);
2783 map_obarray (obarray
, mapatoms_1
, function
);
2787 #define OBARRAY_SIZE 1511
2792 Lisp_Object oblength
;
2796 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2798 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2799 Vobarray
= Fmake_vector (oblength
, make_number (0));
2800 initial_obarray
= Vobarray
;
2801 staticpro (&initial_obarray
);
2802 /* Intern nil in the obarray */
2803 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2804 /* These locals are to kludge around a pyramid compiler bug. */
2805 hash
= hash_string ("nil", 3);
2806 /* Separate statement here to avoid VAXC bug. */
2807 hash
%= OBARRAY_SIZE
;
2808 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2811 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2812 XSYMBOL (Qnil
)->function
= Qunbound
;
2813 XSYMBOL (Qunbound
)->value
= Qunbound
;
2814 XSYMBOL (Qunbound
)->function
= Qunbound
;
2817 XSYMBOL (Qnil
)->value
= Qnil
;
2818 XSYMBOL (Qnil
)->plist
= Qnil
;
2819 XSYMBOL (Qt
)->value
= Qt
;
2821 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2824 Qvariable_documentation
= intern ("variable-documentation");
2825 staticpro (&Qvariable_documentation
);
2827 read_buffer_size
= 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM
;
2828 read_buffer
= (char *) malloc (read_buffer_size
);
2833 struct Lisp_Subr
*sname
;
2836 sym
= intern (sname
->symbol_name
);
2837 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2840 #ifdef NOTDEF /* use fset in subr.el now */
2842 defalias (sname
, string
)
2843 struct Lisp_Subr
*sname
;
2847 sym
= intern (string
);
2848 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2852 /* Define an "integer variable"; a symbol whose value is forwarded
2853 to a C variable of type int. Sample call: */
2854 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
2856 defvar_int (namestring
, address
)
2860 Lisp_Object sym
, val
;
2861 sym
= intern (namestring
);
2862 val
= allocate_misc ();
2863 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
2864 XINTFWD (val
)->intvar
= address
;
2865 XSYMBOL (sym
)->value
= val
;
2868 /* Similar but define a variable whose value is T if address contains 1,
2869 NIL if address contains 0 */
2871 defvar_bool (namestring
, address
)
2875 Lisp_Object sym
, val
;
2876 sym
= intern (namestring
);
2877 val
= allocate_misc ();
2878 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
2879 XBOOLFWD (val
)->boolvar
= address
;
2880 XSYMBOL (sym
)->value
= val
;
2883 /* Similar but define a variable whose value is the Lisp Object stored
2884 at address. Two versions: with and without gc-marking of the C
2885 variable. The nopro version is used when that variable will be
2886 gc-marked for some other reason, since marking the same slot twice
2887 can cause trouble with strings. */
2889 defvar_lisp_nopro (namestring
, address
)
2891 Lisp_Object
*address
;
2893 Lisp_Object sym
, val
;
2894 sym
= intern (namestring
);
2895 val
= allocate_misc ();
2896 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
2897 XOBJFWD (val
)->objvar
= address
;
2898 XSYMBOL (sym
)->value
= val
;
2902 defvar_lisp (namestring
, address
)
2904 Lisp_Object
*address
;
2906 defvar_lisp_nopro (namestring
, address
);
2907 staticpro (address
);
2912 /* Similar but define a variable whose value is the Lisp Object stored in
2913 the current buffer. address is the address of the slot in the buffer
2914 that is current now. */
2917 defvar_per_buffer (namestring
, address
, type
, doc
)
2919 Lisp_Object
*address
;
2923 Lisp_Object sym
, val
;
2925 extern struct buffer buffer_local_symbols
;
2927 sym
= intern (namestring
);
2928 val
= allocate_misc ();
2929 offset
= (char *)address
- (char *)current_buffer
;
2931 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
2932 XBUFFER_OBJFWD (val
)->offset
= offset
;
2933 XSYMBOL (sym
)->value
= val
;
2934 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
2935 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
2936 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
2937 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
2938 slot of buffer_local_flags */
2942 #endif /* standalone */
2944 /* Similar but define a variable whose value is the Lisp Object stored
2945 at a particular offset in the current kboard object. */
2948 defvar_kboard (namestring
, offset
)
2952 Lisp_Object sym
, val
;
2953 sym
= intern (namestring
);
2954 val
= allocate_misc ();
2955 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
2956 XKBOARD_OBJFWD (val
)->offset
= offset
;
2957 XSYMBOL (sym
)->value
= val
;
2960 /* Record the value of load-path used at the start of dumping
2961 so we can see if the site changed it later during dumping. */
2962 static Lisp_Object dump_path
;
2968 int turn_off_warning
= 0;
2970 #ifdef HAVE_SETLOCALE
2971 /* Make sure numbers are parsed as we expect. */
2972 setlocale (LC_NUMERIC
, "C");
2973 #endif /* HAVE_SETLOCALE */
2975 /* Compute the default load-path. */
2977 normal
= PATH_LOADSEARCH
;
2978 Vload_path
= decode_env_path (0, normal
);
2980 if (NILP (Vpurify_flag
))
2981 normal
= PATH_LOADSEARCH
;
2983 normal
= PATH_DUMPLOADSEARCH
;
2985 /* In a dumped Emacs, we normally have to reset the value of
2986 Vload_path from PATH_LOADSEARCH, since the value that was dumped
2987 uses ../lisp, instead of the path of the installed elisp
2988 libraries. However, if it appears that Vload_path was changed
2989 from the default before dumping, don't override that value. */
2992 if (! NILP (Fequal (dump_path
, Vload_path
)))
2994 Vload_path
= decode_env_path (0, normal
);
2995 if (!NILP (Vinstallation_directory
))
2997 /* Add to the path the lisp subdir of the
2998 installation dir, if it exists. */
2999 Lisp_Object tem
, tem1
;
3000 tem
= Fexpand_file_name (build_string ("lisp"),
3001 Vinstallation_directory
);
3002 tem1
= Ffile_exists_p (tem
);
3005 if (NILP (Fmember (tem
, Vload_path
)))
3007 turn_off_warning
= 1;
3008 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3012 /* That dir doesn't exist, so add the build-time
3013 Lisp dirs instead. */
3014 Vload_path
= nconc2 (Vload_path
, dump_path
);
3016 /* Add leim under the installation dir, if it exists. */
3017 tem
= Fexpand_file_name (build_string ("leim"),
3018 Vinstallation_directory
);
3019 tem1
= Ffile_exists_p (tem
);
3022 if (NILP (Fmember (tem
, Vload_path
)))
3023 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3026 /* Add site-list under the installation dir, if it exists. */
3027 tem
= Fexpand_file_name (build_string ("site-lisp"),
3028 Vinstallation_directory
);
3029 tem1
= Ffile_exists_p (tem
);
3032 if (NILP (Fmember (tem
, Vload_path
)))
3033 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3036 /* If Emacs was not built in the source directory,
3037 and it is run from where it was built, add to load-path
3038 the lisp, leim and site-lisp dirs under that directory. */
3040 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3044 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3045 Vinstallation_directory
);
3046 tem1
= Ffile_exists_p (tem
);
3048 /* Don't be fooled if they moved the entire source tree
3049 AFTER dumping Emacs. If the build directory is indeed
3050 different from the source dir, src/Makefile.in and
3051 src/Makefile will not be found together. */
3052 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3053 Vinstallation_directory
);
3054 tem2
= Ffile_exists_p (tem
);
3055 if (!NILP (tem1
) && NILP (tem2
))
3057 tem
= Fexpand_file_name (build_string ("lisp"),
3060 if (NILP (Fmember (tem
, Vload_path
)))
3061 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3063 tem
= Fexpand_file_name (build_string ("leim"),
3066 if (NILP (Fmember (tem
, Vload_path
)))
3067 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3069 tem
= Fexpand_file_name (build_string ("site-lisp"),
3072 if (NILP (Fmember (tem
, Vload_path
)))
3073 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3081 /* NORMAL refers to the lisp dir in the source directory. */
3082 /* We used to add ../lisp at the front here, but
3083 that caused trouble because it was copied from dump_path
3084 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3085 It should be unnecessary. */
3086 Vload_path
= decode_env_path (0, normal
);
3087 dump_path
= Vload_path
;
3092 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3093 almost never correct, thereby causing a warning to be printed out that
3094 confuses users. Since PATH_LOADSEARCH is always overridden by the
3095 EMACSLOADPATH environment variable below, disable the warning on NT. */
3097 /* Warn if dirs in the *standard* path don't exist. */
3098 if (!turn_off_warning
)
3100 Lisp_Object path_tail
;
3102 for (path_tail
= Vload_path
;
3104 path_tail
= XCONS (path_tail
)->cdr
)
3106 Lisp_Object dirfile
;
3107 dirfile
= Fcar (path_tail
);
3108 if (STRINGP (dirfile
))
3110 dirfile
= Fdirectory_file_name (dirfile
);
3111 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3112 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3113 XCONS (path_tail
)->car
);
3117 #endif /* WINDOWSNT */
3119 /* If the EMACSLOADPATH environment variable is set, use its value.
3120 This doesn't apply if we're dumping. */
3122 if (NILP (Vpurify_flag
)
3123 && egetenv ("EMACSLOADPATH"))
3125 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3129 load_in_progress
= 0;
3130 Vload_file_name
= Qnil
;
3132 load_descriptor_list
= Qnil
;
3134 Vstandard_input
= Qt
;
3137 /* Print a warning, using format string FORMAT, that directory DIRNAME
3138 does not exist. Print it on stderr and put it in *Message*. */
3141 dir_warning (format
, dirname
)
3143 Lisp_Object dirname
;
3146 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3148 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3149 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3150 /* Don't log the warning before we've initialized!! */
3152 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3159 defsubr (&Sread_from_string
);
3161 defsubr (&Sintern_soft
);
3162 defsubr (&Sunintern
);
3164 defsubr (&Seval_buffer
);
3165 defsubr (&Seval_region
);
3166 defsubr (&Sread_char
);
3167 defsubr (&Sread_char_exclusive
);
3168 defsubr (&Sread_event
);
3169 defsubr (&Sget_file_char
);
3170 defsubr (&Smapatoms
);
3172 DEFVAR_LISP ("obarray", &Vobarray
,
3173 "Symbol table for use by `intern' and `read'.\n\
3174 It is a vector whose length ought to be prime for best results.\n\
3175 The vector's contents don't make sense if examined from Lisp programs;\n\
3176 to find all the symbols in an obarray, use `mapatoms'.");
3178 DEFVAR_LISP ("values", &Vvalues
,
3179 "List of values of all expressions which were read, evaluated and printed.\n\
3180 Order is reverse chronological.");
3182 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3183 "Stream for read to get input from.\n\
3184 See documentation of `read' for possible values.");
3185 Vstandard_input
= Qt
;
3187 DEFVAR_LISP ("load-path", &Vload_path
,
3188 "*List of directories to search for files to load.\n\
3189 Each element is a string (directory name) or nil (try default directory).\n\
3190 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3191 otherwise to default specified by file `epaths.h' when Emacs was built.");
3193 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3194 "Non-nil iff inside of `load'.");
3196 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3197 "An alist of expressions to be evalled when particular files are loaded.\n\
3198 Each element looks like (FILENAME FORMS...).\n\
3199 When `load' is run and the file-name argument is FILENAME,\n\
3200 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3201 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3202 with no directory specified, since that is how `load' is normally called.\n\
3203 An error in FORMS does not undo the load,\n\
3204 but does prevent execution of the rest of the FORMS.");
3205 Vafter_load_alist
= Qnil
;
3207 DEFVAR_LISP ("load-history", &Vload_history
,
3208 "Alist mapping source file names to symbols and features.\n\
3209 Each alist element is a list that starts with a file name,\n\
3210 except for one element (optional) that starts with nil and describes\n\
3211 definitions evaluated from buffers not visiting files.\n\
3212 The remaining elements of each list are symbols defined as functions\n\
3213 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3214 Vload_history
= Qnil
;
3216 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3217 "Full name of file being loaded by `load'.");
3218 Vload_file_name
= Qnil
;
3220 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3221 "File name, including directory, of user's initialization file.");
3222 Vuser_init_file
= Qnil
;
3224 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3225 "Used for internal purposes by `load'.");
3226 Vcurrent_load_list
= Qnil
;
3228 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3229 "Function used by `load' and `eval-region' for reading expressions.\n\
3230 The default is nil, which means use the function `read'.");
3231 Vload_read_function
= Qnil
;
3233 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3234 "Function called in `load' for loading an Emacs lisp source file.\n\
3235 This function is for doing code conversion before reading the source file.\n\
3236 If nil, loading is done without any code conversion.\n\
3237 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3238 FULLNAME is the full name of FILE.\n\
3239 See `load' for the meaning of the remaining arguments.");
3240 Vload_source_file_function
= Qnil
;
3242 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3243 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3244 This is useful when the file being loaded is a temporary copy.");
3245 load_force_doc_strings
= 0;
3247 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3248 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3249 This is normally used in `load-with-code-conversion'\n\
3250 for loading non-compiled files.");
3251 load_convert_to_unibyte
= 0;
3253 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3254 "Directory in which Emacs sources were found when Emacs was built.\n\
3255 You cannot count on them to still be there!");
3257 = Fexpand_file_name (build_string ("../"),
3258 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3260 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3261 "List of files that were preloaded (when dumping Emacs).");
3262 Vpreloaded_file_list
= Qnil
;
3264 /* Vsource_directory was initialized in init_lread. */
3266 load_descriptor_list
= Qnil
;
3267 staticpro (&load_descriptor_list
);
3269 Qcurrent_load_list
= intern ("current-load-list");
3270 staticpro (&Qcurrent_load_list
);
3272 Qstandard_input
= intern ("standard-input");
3273 staticpro (&Qstandard_input
);
3275 Qread_char
= intern ("read-char");
3276 staticpro (&Qread_char
);
3278 Qget_file_char
= intern ("get-file-char");
3279 staticpro (&Qget_file_char
);
3281 Qbackquote
= intern ("`");
3282 staticpro (&Qbackquote
);
3283 Qcomma
= intern (",");
3284 staticpro (&Qcomma
);
3285 Qcomma_at
= intern (",@");
3286 staticpro (&Qcomma_at
);
3287 Qcomma_dot
= intern (",.");
3288 staticpro (&Qcomma_dot
);
3290 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3291 staticpro (&Qinhibit_file_name_operation
);
3293 Qascii_character
= intern ("ascii-character");
3294 staticpro (&Qascii_character
);
3296 Qfunction
= intern ("function");
3297 staticpro (&Qfunction
);
3299 Qload
= intern ("load");
3302 Qload_file_name
= intern ("load-file-name");
3303 staticpro (&Qload_file_name
);
3305 staticpro (&dump_path
);
3307 staticpro (&read_objects
);
3308 read_objects
= Qnil
;