1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 1999
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>
30 #include "intervals.h"
38 #include "termhooks.h"
42 #include <sys/inode.h>
47 #include <unistd.h> /* to get X_OK */
60 #ifdef LISP_FLOAT_TYPE
62 #endif /* LISP_FLOAT_TYPE */
66 #endif /* HAVE_SETLOCALE */
73 #define file_offset off_t
74 #define file_tell ftello
76 #define file_offset long
77 #define file_tell ftell
82 Lisp_Object Qread_char
, Qget_file_char
, Qstandard_input
, Qcurrent_load_list
;
83 Lisp_Object Qvariable_documentation
, Vvalues
, Vstandard_input
, Vafter_load_alist
;
84 Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
85 Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
86 Lisp_Object Qinhibit_file_name_operation
;
88 extern Lisp_Object Qevent_symbol_element_mask
;
89 extern Lisp_Object Qfile_exists_p
;
91 /* non-zero if inside `load' */
94 /* Directory in which the sources were found. */
95 Lisp_Object Vsource_directory
;
97 /* Search path for files to be loaded. */
98 Lisp_Object Vload_path
;
100 /* File name of user's init file. */
101 Lisp_Object Vuser_init_file
;
103 /* This is the user-visible association list that maps features to
104 lists of defs in their load files. */
105 Lisp_Object Vload_history
;
107 /* This is used to build the load history. */
108 Lisp_Object Vcurrent_load_list
;
110 /* List of files that were preloaded. */
111 Lisp_Object Vpreloaded_file_list
;
113 /* Name of file actually being read by `load'. */
114 Lisp_Object Vload_file_name
;
116 /* Function to use for reading, in `load' and friends. */
117 Lisp_Object Vload_read_function
;
119 /* The association list of objects read with the #n=object form.
120 Each member of the list has the form (n . object), and is used to
121 look up the object for the corresponding #n# construct.
122 It must be set to nil before all top-level calls to read0. */
123 Lisp_Object read_objects
;
125 /* Nonzero means load should forcibly load all dynamic doc strings. */
126 static int load_force_doc_strings
;
128 /* Nonzero means read should convert strings to unibyte. */
129 static int load_convert_to_unibyte
;
131 /* Function to use for loading an Emacs lisp source file (not
132 compiled) instead of readevalloop. */
133 Lisp_Object Vload_source_file_function
;
135 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
136 Lisp_Object Vbyte_boolean_vars
;
138 /* List of descriptors now open for Fload. */
139 static Lisp_Object load_descriptor_list
;
141 /* File for get_file_char to read from. Use by load. */
142 static FILE *instream
;
144 /* When nonzero, read conses in pure space */
145 static int read_pure
;
147 /* For use within read-from-string (this reader is non-reentrant!!) */
148 static int read_from_string_index
;
149 static int read_from_string_index_byte
;
150 static int read_from_string_limit
;
152 /* Number of bytes left to read in the buffer character
153 that `readchar' has already advanced over. */
154 static int readchar_backlog
;
156 /* This contains the last string skipped with #@. */
157 static char *saved_doc_string
;
158 /* Length of buffer allocated in saved_doc_string. */
159 static int saved_doc_string_size
;
160 /* Length of actual data in saved_doc_string. */
161 static int saved_doc_string_length
;
162 /* This is the file position that string came from. */
163 static file_offset saved_doc_string_position
;
165 /* This contains the previous string skipped with #@.
166 We copy it from saved_doc_string when a new string
167 is put in saved_doc_string. */
168 static char *prev_saved_doc_string
;
169 /* Length of buffer allocated in prev_saved_doc_string. */
170 static int prev_saved_doc_string_size
;
171 /* Length of actual data in prev_saved_doc_string. */
172 static int prev_saved_doc_string_length
;
173 /* This is the file position that string came from. */
174 static file_offset prev_saved_doc_string_position
;
176 /* Nonzero means inside a new-style backquote
177 with no surrounding parentheses.
178 Fread initializes this to zero, so we need not specbind it
179 or worry about what happens to it when there is an error. */
180 static int new_backquote_flag
;
182 /* Handle unreading and rereading of characters.
183 Write READCHAR to read a character,
184 UNREAD(c) to unread c to be read again.
186 These macros actually read/unread a byte code, multibyte characters
187 are not handled here. The caller should manage them if necessary.
190 #define READCHAR readchar (readcharfun)
191 #define UNREAD(c) unreadchar (readcharfun, c)
194 readchar (readcharfun
)
195 Lisp_Object readcharfun
;
200 if (BUFFERP (readcharfun
))
202 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
204 int pt_byte
= BUF_PT_BYTE (inbuffer
);
205 int orig_pt_byte
= pt_byte
;
207 if (readchar_backlog
> 0)
208 /* We get the address of the byte just passed,
209 which is the last byte of the character.
210 The other bytes in this character are consecutive with it,
211 because the gap can't be in the middle of a character. */
212 return *(BUF_BYTE_ADDRESS (inbuffer
, BUF_PT_BYTE (inbuffer
) - 1)
213 - --readchar_backlog
);
215 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
218 readchar_backlog
= -1;
220 if (! NILP (inbuffer
->enable_multibyte_characters
))
222 /* Fetch the character code from the buffer. */
223 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
224 BUF_INC_POS (inbuffer
, pt_byte
);
225 c
= STRING_CHAR (p
, pt_byte
- orig_pt_byte
);
229 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
232 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
236 if (MARKERP (readcharfun
))
238 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
240 int bytepos
= marker_byte_position (readcharfun
);
241 int orig_bytepos
= bytepos
;
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
);
251 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
254 readchar_backlog
= -1;
256 if (! NILP (inbuffer
->enable_multibyte_characters
))
258 /* Fetch the character code from the buffer. */
259 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
260 BUF_INC_POS (inbuffer
, bytepos
);
261 c
= STRING_CHAR (p
, bytepos
- orig_bytepos
);
265 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
269 XMARKER (readcharfun
)->bytepos
= bytepos
;
270 XMARKER (readcharfun
)->charpos
++;
275 if (EQ (readcharfun
, Qlambda
))
276 return read_bytecode_char (0);
278 if (EQ (readcharfun
, Qget_file_char
))
282 /* Interrupted reads have been observed while reading over the network */
283 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
292 if (STRINGP (readcharfun
))
294 if (read_from_string_index
>= read_from_string_limit
)
296 else if (STRING_MULTIBYTE (readcharfun
))
297 FETCH_STRING_CHAR_ADVANCE (c
, readcharfun
,
298 read_from_string_index
,
299 read_from_string_index_byte
);
301 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
306 tem
= call0 (readcharfun
);
313 /* Unread the character C in the way appropriate for the stream READCHARFUN.
314 If the stream is a user function, call it with the char as argument. */
317 unreadchar (readcharfun
, c
)
318 Lisp_Object readcharfun
;
322 /* Don't back up the pointer if we're unreading the end-of-input mark,
323 since readchar didn't advance it when we read it. */
325 else if (BUFFERP (readcharfun
))
327 struct buffer
*b
= XBUFFER (readcharfun
);
328 int bytepos
= BUF_PT_BYTE (b
);
330 if (readchar_backlog
>= 0)
335 if (! NILP (b
->enable_multibyte_characters
))
336 BUF_DEC_POS (b
, bytepos
);
340 BUF_PT_BYTE (b
) = bytepos
;
343 else if (MARKERP (readcharfun
))
345 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
346 int bytepos
= XMARKER (readcharfun
)->bytepos
;
348 if (readchar_backlog
>= 0)
352 XMARKER (readcharfun
)->charpos
--;
353 if (! NILP (b
->enable_multibyte_characters
))
354 BUF_DEC_POS (b
, bytepos
);
358 XMARKER (readcharfun
)->bytepos
= bytepos
;
361 else if (STRINGP (readcharfun
))
363 read_from_string_index
--;
364 read_from_string_index_byte
365 = string_char_to_byte (readcharfun
, read_from_string_index
);
367 else if (EQ (readcharfun
, Qlambda
))
368 read_bytecode_char (1);
369 else if (EQ (readcharfun
, Qget_file_char
))
370 ungetc (c
, instream
);
372 call1 (readcharfun
, make_number (c
));
375 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
376 static int read_multibyte ();
377 static Lisp_Object
substitute_object_recurse ();
378 static void substitute_object_in_subtree (), substitute_in_interval ();
381 /* Get a character from the tty. */
383 extern Lisp_Object
read_char ();
385 /* Read input events until we get one that's acceptable for our purposes.
387 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
388 until we get a character we like, and then stuffed into
391 If ASCII_REQUIRED is non-zero, we check function key events to see
392 if the unmodified version of the symbol has a Qascii_character
393 property, and use that character, if present.
395 If ERROR_NONASCII is non-zero, we signal an error if the input we
396 get isn't an ASCII character with modifiers. If it's zero but
397 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
400 If INPUT_METHOD is nonzero, we invoke the current input method
401 if the character warrants that. */
404 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
406 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
409 return make_number (getchar ());
411 register Lisp_Object val
, delayed_switch_frame
;
413 delayed_switch_frame
= Qnil
;
415 /* Read until we get an acceptable event. */
417 val
= read_char (0, 0, 0,
418 (input_method
? Qnil
: Qt
),
424 /* switch-frame events are put off until after the next ASCII
425 character. This is better than signaling an error just because
426 the last characters were typed to a separate minibuffer frame,
427 for example. Eventually, some code which can deal with
428 switch-frame events will read it and process it. */
430 && EVENT_HAS_PARAMETERS (val
)
431 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
433 delayed_switch_frame
= val
;
439 /* Convert certain symbols to their ASCII equivalents. */
442 Lisp_Object tem
, tem1
;
443 tem
= Fget (val
, Qevent_symbol_element_mask
);
446 tem1
= Fget (Fcar (tem
), Qascii_character
);
447 /* Merge this symbol's modifier bits
448 with the ASCII equivalent of its basic code. */
450 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
454 /* If we don't have a character now, deal with it appropriately. */
459 Vunread_command_events
= Fcons (val
, Qnil
);
460 error ("Non-character input-event");
467 if (! NILP (delayed_switch_frame
))
468 unread_switch_frame
= delayed_switch_frame
;
474 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 2, 0,
475 "Read a character from the command input (keyboard or macro).\n\
476 It is returned as a number.\n\
477 If the user generates an event which is not a character (i.e. a mouse\n\
478 click or function key event), `read-char' signals an error. As an\n\
479 exception, switch-frame events are put off until non-ASCII events can\n\
481 If you want to read non-character events, or ignore them, call\n\
482 `read-event' or `read-char-exclusive' instead.\n\
484 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
485 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
486 input method is turned on in the current buffer, that input method\n\
487 is used for reading a character.")
488 (prompt
, inherit_input_method
)
489 Lisp_Object prompt
, inherit_input_method
;
492 message_with_string ("%s", prompt
, 0);
493 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
));
496 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 2, 0,
497 "Read an event object from the input stream.\n\
498 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
499 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
500 input method is turned on in the current buffer, that input method\n\
501 is used for reading a character.")
502 (prompt
, inherit_input_method
)
503 Lisp_Object prompt
, inherit_input_method
;
506 message_with_string ("%s", prompt
, 0);
507 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
));
510 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 2, 0,
511 "Read a character from the command input (keyboard or macro).\n\
512 It is returned as a number. Non-character events are ignored.\n\
514 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
515 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
516 input method is turned on in the current buffer, that input method\n\
517 is used for reading a character.")
518 (prompt
, inherit_input_method
)
519 Lisp_Object prompt
, inherit_input_method
;
522 message_with_string ("%s", prompt
, 0);
523 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
));
526 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
527 "Don't use this yourself.")
530 register Lisp_Object val
;
531 XSETINT (val
, getc (instream
));
535 static void readevalloop ();
536 static Lisp_Object
load_unwind ();
537 static Lisp_Object
load_descriptor_unwind ();
539 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
540 "Execute a file of Lisp code named FILE.\n\
541 First try FILE with `.elc' appended, then try with `.el',\n\
542 then try FILE unmodified.\n\
543 This function searches the directories in `load-path'.\n\
544 If optional second arg NOERROR is non-nil,\n\
545 report no error if FILE doesn't exist.\n\
546 Print messages at start and end of loading unless\n\
547 optional third arg NOMESSAGE is non-nil.\n\
548 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
549 suffixes `.elc' or `.el' to the specified name FILE.\n\
550 If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
551 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
552 it ends in one of those suffixes or includes a directory name.\n\
553 Return t if file exists.")
554 (file
, noerror
, nomessage
, nosuffix
, must_suffix
)
555 Lisp_Object file
, noerror
, nomessage
, nosuffix
, must_suffix
;
557 register FILE *stream
;
558 register int fd
= -1;
559 register Lisp_Object lispstream
;
560 int count
= specpdl_ptr
- specpdl
;
564 /* 1 means we printed the ".el is newer" message. */
566 /* 1 means we are loading a compiled file. */
574 CHECK_STRING (file
, 0);
576 /* If file name is magic, call the handler. */
577 handler
= Ffind_file_name_handler (file
, Qload
);
579 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
581 /* Do this after the handler to avoid
582 the need to gcpro noerror, nomessage and nosuffix.
583 (Below here, we care only whether they are nil or not.) */
584 file
= Fsubstitute_in_file_name (file
);
586 /* Avoid weird lossage with null string as arg,
587 since it would try to load a directory as a Lisp file */
588 if (XSTRING (file
)->size
> 0)
590 int size
= STRING_BYTES (XSTRING (file
));
594 if (! NILP (must_suffix
))
596 /* Don't insist on adding a suffix if FILE already ends with one. */
598 && !strcmp (XSTRING (file
)->data
+ size
- 3, ".el"))
601 && !strcmp (XSTRING (file
)->data
+ size
- 4, ".elc"))
603 /* Don't insist on adding a suffix
604 if the argument includes a directory name. */
605 else if (! NILP (Ffile_name_directory (file
)))
609 fd
= openp (Vload_path
, file
,
610 (!NILP (nosuffix
) ? ""
611 : ! NILP (must_suffix
) ? ".elc:.el"
621 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
622 Fcons (file
, Qnil
)));
627 if (EQ (Qt
, Vuser_init_file
))
628 Vuser_init_file
= found
;
630 /* If FD is 0, that means openp found a magic file. */
633 if (NILP (Fequal (found
, file
)))
634 /* If FOUND is a different file name from FILE,
635 find its handler even if we have already inhibited
636 the `load' operation on FILE. */
637 handler
= Ffind_file_name_handler (found
, Qt
);
639 handler
= Ffind_file_name_handler (found
, Qload
);
640 if (! NILP (handler
))
641 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
644 /* Load .elc files directly, but not when they are
645 remote and have no handler! */
646 if (!bcmp (&(XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 4]),
658 stat ((char *)XSTRING (found
)->data
, &s1
);
659 XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 1] = 0;
660 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
661 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
663 /* Make the progress messages mention that source is newer. */
666 /* If we won't print another message, mention this anyway. */
667 if (! NILP (nomessage
))
668 message_with_string ("Source file `%s' newer than byte-compiled file",
671 XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 1] = 'c';
675 /* We are loading a source file (*.el). */
676 if (!NILP (Vload_source_file_function
))
680 return call4 (Vload_source_file_function
, found
, file
,
681 NILP (noerror
) ? Qnil
: Qt
,
682 NILP (nomessage
) ? Qnil
: Qt
);
688 stream
= fopen ((char *) XSTRING (found
)->data
, fmode
);
689 #else /* not WINDOWSNT */
690 stream
= fdopen (fd
, fmode
);
691 #endif /* not WINDOWSNT */
695 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
698 if (! NILP (Vpurify_flag
))
699 Vpreloaded_file_list
= Fcons (file
, Vpreloaded_file_list
);
701 if (NILP (nomessage
))
704 message_with_string ("Loading %s (source)...", file
, 1);
706 message_with_string ("Loading %s (compiled; note, source file is newer)...",
708 else /* The typical case; compiled file newer than source file. */
709 message_with_string ("Loading %s...", file
, 1);
713 lispstream
= Fcons (Qnil
, Qnil
);
714 XSETFASTINT (XCAR (lispstream
), (EMACS_UINT
)stream
>> 16);
715 XSETFASTINT (XCDR (lispstream
), (EMACS_UINT
)stream
& 0xffff);
716 record_unwind_protect (load_unwind
, lispstream
);
717 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
718 specbind (Qload_file_name
, found
);
719 specbind (Qinhibit_file_name_operation
, Qnil
);
721 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
723 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0, Qnil
, Qnil
);
724 unbind_to (count
, Qnil
);
726 /* Run any load-hooks for this file. */
727 temp
= Fassoc (file
, Vafter_load_alist
);
729 Fprogn (Fcdr (temp
));
732 if (saved_doc_string
)
733 free (saved_doc_string
);
734 saved_doc_string
= 0;
735 saved_doc_string_size
= 0;
737 if (prev_saved_doc_string
)
738 free (prev_saved_doc_string
);
739 prev_saved_doc_string
= 0;
740 prev_saved_doc_string_size
= 0;
742 if (!noninteractive
&& NILP (nomessage
))
745 message_with_string ("Loading %s (source)...done", file
, 1);
747 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
749 else /* The typical case; compiled file newer than source file. */
750 message_with_string ("Loading %s...done", file
, 1);
756 load_unwind (stream
) /* used as unwind-protect function in load */
759 fclose ((FILE *) (XFASTINT (XCAR (stream
)) << 16
760 | XFASTINT (XCDR (stream
))));
761 if (--load_in_progress
< 0) load_in_progress
= 0;
766 load_descriptor_unwind (oldlist
)
769 load_descriptor_list
= oldlist
;
773 /* Close all descriptors in use for Floads.
774 This is used when starting a subprocess. */
781 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCDR (tail
))
782 emacs_close (XFASTINT (XCAR (tail
)));
787 complete_filename_p (pathname
)
788 Lisp_Object pathname
;
790 register unsigned char *s
= XSTRING (pathname
)->data
;
791 return (IS_DIRECTORY_SEP (s
[0])
792 || (XSTRING (pathname
)->size
> 2
793 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
803 /* Search for a file whose name is STR, looking in directories
804 in the Lisp list PATH, and trying suffixes from SUFFIX.
805 SUFFIX is a string containing possible suffixes separated by colons.
806 On success, returns a file descriptor. On failure, returns -1.
808 EXEC_ONLY nonzero means don't open the files,
809 just look for one that is executable. In this case,
810 returns 1 on success.
812 If STOREPTR is nonzero, it points to a slot where the name of
813 the file actually found should be stored as a Lisp string.
814 nil is stored there on failure.
816 If the file we find is remote, return 0
817 but store the found remote file name in *STOREPTR.
818 We do not check for remote files if EXEC_ONLY is nonzero. */
821 openp (path
, str
, suffix
, storeptr
, exec_only
)
822 Lisp_Object path
, str
;
824 Lisp_Object
*storeptr
;
830 register char *fn
= buf
;
833 Lisp_Object filename
;
841 if (complete_filename_p (str
))
844 for (; !NILP (path
); path
= Fcdr (path
))
848 filename
= Fexpand_file_name (str
, Fcar (path
));
849 if (!complete_filename_p (filename
))
850 /* If there are non-absolute elts in PATH (eg ".") */
851 /* Of course, this could conceivably lose if luser sets
852 default-directory to be something non-absolute... */
854 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
855 if (!complete_filename_p (filename
))
856 /* Give up on this path element! */
860 /* Calculate maximum size of any filename made from
861 this path element/specified file name and any possible suffix. */
862 want_size
= strlen (suffix
) + STRING_BYTES (XSTRING (filename
)) + 1;
863 if (fn_size
< want_size
)
864 fn
= (char *) alloca (fn_size
= 100 + want_size
);
868 /* Loop over suffixes. */
871 char *esuffix
= (char *) index (nsuffix
, ':');
872 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
875 /* Concatenate path element/specified name with the suffix.
876 If the directory starts with /:, remove that. */
877 if (XSTRING (filename
)->size
> 2
878 && XSTRING (filename
)->data
[0] == '/'
879 && XSTRING (filename
)->data
[1] == ':')
881 strncpy (fn
, XSTRING (filename
)->data
+ 2,
882 STRING_BYTES (XSTRING (filename
)) - 2);
883 fn
[STRING_BYTES (XSTRING (filename
)) - 2] = 0;
887 strncpy (fn
, XSTRING (filename
)->data
,
888 STRING_BYTES (XSTRING (filename
)));
889 fn
[STRING_BYTES (XSTRING (filename
))] = 0;
892 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
893 strncat (fn
, nsuffix
, lsuffix
);
895 /* Check that the file exists and is not a directory. */
899 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
900 if (! NILP (handler
) && ! exec_only
)
905 string
= build_string (fn
);
906 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
907 : Ffile_readable_p (string
));
909 && ! NILP (Ffile_directory_p (build_string (fn
))))
914 /* We succeeded; return this descriptor and filename. */
916 *storeptr
= build_string (fn
);
923 int exists
= (stat (fn
, &st
) >= 0
924 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
927 /* Check that we can access or open it. */
929 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
931 fd
= emacs_open (fn
, O_RDONLY
, 0);
935 /* We succeeded; return this descriptor and filename. */
937 *storeptr
= build_string (fn
);
944 /* Advance to next suffix. */
947 nsuffix
+= lsuffix
+ 1;
958 /* Merge the list we've accumulated of globals from the current input source
959 into the load_history variable. The details depend on whether
960 the source has an associated file name or not. */
963 build_load_history (stream
, source
)
967 register Lisp_Object tail
, prev
, newelt
;
968 register Lisp_Object tem
, tem2
;
969 register int foundit
, loading
;
971 loading
= stream
|| !NARROWED
;
973 tail
= Vload_history
;
980 /* Find the feature's previous assoc list... */
981 if (!NILP (Fequal (source
, Fcar (tem
))))
985 /* If we're loading, remove it. */
989 Vload_history
= Fcdr (tail
);
991 Fsetcdr (prev
, Fcdr (tail
));
994 /* Otherwise, cons on new symbols that are not already members. */
997 tem2
= Vcurrent_load_list
;
1001 newelt
= Fcar (tem2
);
1003 if (NILP (Fmemq (newelt
, tem
)))
1004 Fsetcar (tail
, Fcons (Fcar (tem
),
1005 Fcons (newelt
, Fcdr (tem
))));
1018 /* If we're loading, cons the new assoc onto the front of load-history,
1019 the most-recently-loaded position. Also do this if we didn't find
1020 an existing member for the current source. */
1021 if (loading
|| !foundit
)
1022 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1027 unreadpure () /* Used as unwind-protect function in readevalloop */
1034 readevalloop_1 (old
)
1037 load_convert_to_unibyte
= ! NILP (old
);
1041 /* UNIBYTE specifies how to set load_convert_to_unibyte
1042 for this invocation.
1043 READFUN, if non-nil, is used instead of `read'. */
1046 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
, unibyte
, readfun
)
1047 Lisp_Object readcharfun
;
1049 Lisp_Object sourcename
;
1050 Lisp_Object (*evalfun
) ();
1052 Lisp_Object unibyte
, readfun
;
1055 register Lisp_Object val
;
1056 int count
= specpdl_ptr
- specpdl
;
1057 struct gcpro gcpro1
;
1058 struct buffer
*b
= 0;
1060 if (BUFFERP (readcharfun
))
1061 b
= XBUFFER (readcharfun
);
1062 else if (MARKERP (readcharfun
))
1063 b
= XMARKER (readcharfun
)->buffer
;
1065 specbind (Qstandard_input
, readcharfun
);
1066 specbind (Qcurrent_load_list
, Qnil
);
1067 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1068 load_convert_to_unibyte
= !NILP (unibyte
);
1070 readchar_backlog
= -1;
1072 GCPRO1 (sourcename
);
1074 LOADHIST_ATTACH (sourcename
);
1078 if (b
!= 0 && NILP (b
->name
))
1079 error ("Reading from killed buffer");
1085 while ((c
= READCHAR
) != '\n' && c
!= -1);
1090 /* Ignore whitespace here, so we can detect eof. */
1091 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
1094 if (!NILP (Vpurify_flag
) && c
== '(')
1096 int count1
= specpdl_ptr
- specpdl
;
1097 record_unwind_protect (unreadpure
, Qnil
);
1098 val
= read_list (-1, readcharfun
);
1099 unbind_to (count1
, Qnil
);
1104 read_objects
= Qnil
;
1105 if (! NILP (readfun
))
1106 val
= call1 (readfun
, readcharfun
);
1107 else if (! NILP (Vload_read_function
))
1108 val
= call1 (Vload_read_function
, readcharfun
);
1110 val
= read0 (readcharfun
);
1113 val
= (*evalfun
) (val
);
1116 Vvalues
= Fcons (val
, Vvalues
);
1117 if (EQ (Vstandard_output
, Qt
))
1124 build_load_history (stream
, sourcename
);
1127 unbind_to (count
, Qnil
);
1132 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1133 "Execute the current buffer as Lisp code.\n\
1134 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1135 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1136 PRINTFLAG controls printing of output:\n\
1137 nil means discard it; anything else is stream for print.\n\
1139 If the optional third argument FILENAME is non-nil,\n\
1140 it specifies the file name to use for `load-history'.\n\
1141 The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
1142 for this invocation.\n\
1144 The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
1145 `print' and related functions should work normally even if PRINTFLAG is nil.\n\
1147 This function preserves the position of point.")
1148 (buffer
, printflag
, filename
, unibyte
, do_allow_print
)
1149 Lisp_Object buffer
, printflag
, filename
, unibyte
, do_allow_print
;
1151 int count
= specpdl_ptr
- specpdl
;
1152 Lisp_Object tem
, buf
;
1155 buf
= Fcurrent_buffer ();
1157 buf
= Fget_buffer (buffer
);
1159 error ("No such buffer");
1161 if (NILP (printflag
) && NILP (do_allow_print
))
1166 if (NILP (filename
))
1167 filename
= XBUFFER (buf
)->filename
;
1169 specbind (Qstandard_output
, tem
);
1170 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1171 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1172 readevalloop (buf
, 0, filename
, Feval
, !NILP (printflag
), unibyte
, Qnil
);
1173 unbind_to (count
, Qnil
);
1179 XDEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
1180 "Execute the current buffer as Lisp code.\n\
1181 Programs can pass argument PRINTFLAG which controls printing of output:\n\
1182 nil means discard it; anything else is stream for print.\n\
1184 If there is no error, point does not move. If there is an error,\n\
1185 point remains at the end of the last character read from the buffer.")
1187 Lisp_Object printflag
;
1189 int count
= specpdl_ptr
- specpdl
;
1190 Lisp_Object tem
, cbuf
;
1192 cbuf
= Fcurrent_buffer ()
1194 if (NILP (printflag
))
1198 specbind (Qstandard_output
, tem
);
1199 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1201 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1202 !NILP (printflag
), Qnil
, Qnil
);
1203 return unbind_to (count
, Qnil
);
1207 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1208 "Execute the region as Lisp code.\n\
1209 When called from programs, expects two arguments,\n\
1210 giving starting and ending indices in the current buffer\n\
1211 of the text to be executed.\n\
1212 Programs can pass third argument PRINTFLAG which controls output:\n\
1213 nil means discard it; anything else is stream for printing it.\n\
1214 Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1215 instead of `read' to read each expression. It gets one argument\n\
1216 which is the input stream for reading characters.\n\
1218 This function does not move point.")
1219 (start
, end
, printflag
, read_function
)
1220 Lisp_Object start
, end
, printflag
, read_function
;
1222 int count
= specpdl_ptr
- specpdl
;
1223 Lisp_Object tem
, cbuf
;
1225 cbuf
= Fcurrent_buffer ();
1227 if (NILP (printflag
))
1231 specbind (Qstandard_output
, tem
);
1233 if (NILP (printflag
))
1234 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1235 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1237 /* This both uses start and checks its type. */
1239 Fnarrow_to_region (make_number (BEGV
), end
);
1240 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1241 !NILP (printflag
), Qnil
, read_function
);
1243 return unbind_to (count
, Qnil
);
1246 #endif /* standalone */
1248 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1249 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1250 If STREAM is nil, use the value of `standard-input' (which see).\n\
1251 STREAM or the value of `standard-input' may be:\n\
1252 a buffer (read from point and advance it)\n\
1253 a marker (read from where it points and advance it)\n\
1254 a function (call it with no arguments for each character,\n\
1255 call it with a char as argument to push a char back)\n\
1256 a string (takes text from string, starting at the beginning)\n\
1257 t (read text line using minibuffer and use it).")
1261 extern Lisp_Object
Fread_minibuffer ();
1264 stream
= Vstandard_input
;
1265 if (EQ (stream
, Qt
))
1266 stream
= Qread_char
;
1268 readchar_backlog
= -1;
1269 new_backquote_flag
= 0;
1270 read_objects
= Qnil
;
1273 if (EQ (stream
, Qread_char
))
1274 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1277 if (STRINGP (stream
))
1278 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1280 return read0 (stream
);
1283 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1284 "Read one Lisp expression which is represented as text by STRING.\n\
1285 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1286 START and END optionally delimit a substring of STRING from which to read;\n\
1287 they default to 0 and (length STRING) respectively.")
1288 (string
, start
, end
)
1289 Lisp_Object string
, start
, end
;
1291 int startval
, endval
;
1294 CHECK_STRING (string
,0);
1297 endval
= XSTRING (string
)->size
;
1300 CHECK_NUMBER (end
, 2);
1301 endval
= XINT (end
);
1302 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1303 args_out_of_range (string
, end
);
1310 CHECK_NUMBER (start
, 1);
1311 startval
= XINT (start
);
1312 if (startval
< 0 || startval
> endval
)
1313 args_out_of_range (string
, start
);
1316 read_from_string_index
= startval
;
1317 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1318 read_from_string_limit
= endval
;
1320 new_backquote_flag
= 0;
1321 read_objects
= Qnil
;
1323 tem
= read0 (string
);
1324 return Fcons (tem
, make_number (read_from_string_index
));
1327 /* Use this for recursive reads, in contexts where internal tokens
1332 Lisp_Object readcharfun
;
1334 register Lisp_Object val
;
1337 val
= read1 (readcharfun
, &c
, 0);
1339 Fsignal (Qinvalid_read_syntax
, Fcons (Fmake_string (make_number (1),
1346 static int read_buffer_size
;
1347 static char *read_buffer
;
1349 /* Read multibyte form and return it as a character. C is a first
1350 byte of multibyte form, and rest of them are read from
1354 read_multibyte (c
, readcharfun
)
1356 Lisp_Object readcharfun
;
1358 /* We need the actual character code of this multibyte
1360 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
1364 while ((c
= READCHAR
) >= 0xA0
1365 && len
< MAX_MULTIBYTE_LENGTH
)
1368 return STRING_CHAR (str
, len
);
1371 /* Read a \-escape sequence, assuming we already read the `\'. */
1374 read_escape (readcharfun
, stringp
)
1375 Lisp_Object readcharfun
;
1378 register int c
= READCHAR
;
1382 error ("End of file");
1412 error ("Invalid escape character syntax");
1415 c
= read_escape (readcharfun
, 0);
1416 return c
| meta_modifier
;
1421 error ("Invalid escape character syntax");
1424 c
= read_escape (readcharfun
, 0);
1425 return c
| shift_modifier
;
1430 error ("Invalid escape character syntax");
1433 c
= read_escape (readcharfun
, 0);
1434 return c
| hyper_modifier
;
1439 error ("Invalid escape character syntax");
1442 c
= read_escape (readcharfun
, 0);
1443 return c
| alt_modifier
;
1448 error ("Invalid escape character syntax");
1451 c
= read_escape (readcharfun
, 0);
1452 return c
| super_modifier
;
1457 error ("Invalid escape character syntax");
1461 c
= read_escape (readcharfun
, 0);
1462 if ((c
& ~CHAR_MODIFIER_MASK
) == '?')
1463 return 0177 | (c
& CHAR_MODIFIER_MASK
);
1464 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1465 return c
| ctrl_modifier
;
1466 /* ASCII control chars are made from letters (both cases),
1467 as well as the non-letters within 0100...0137. */
1468 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1469 return (c
& (037 | ~0177));
1470 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1471 return (c
& (037 | ~0177));
1473 return c
| ctrl_modifier
;
1483 /* An octal escape, as in ANSI C. */
1485 register int i
= c
- '0';
1486 register int count
= 0;
1489 if ((c
= READCHAR
) >= '0' && c
<= '7')
1504 /* A hex escape, as in ANSI C. */
1510 if (c
>= '0' && c
<= '9')
1515 else if ((c
>= 'a' && c
<= 'f')
1516 || (c
>= 'A' && c
<= 'F'))
1519 if (c
>= 'a' && c
<= 'f')
1534 if (BASE_LEADING_CODE_P (c
))
1535 c
= read_multibyte (c
, readcharfun
);
1540 /* If the next token is ')' or ']' or '.', we store that character
1541 in *PCH and the return value is not interesting. Else, we store
1542 zero in *PCH and we read and return one lisp object.
1544 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1547 read1 (readcharfun
, pch
, first_in_list
)
1548 register Lisp_Object readcharfun
;
1553 int uninterned_symbol
= 0;
1560 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1565 return read_list (0, readcharfun
);
1568 return read_vector (readcharfun
, 0);
1585 tmp
= read_vector (readcharfun
, 0);
1586 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1587 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1588 error ("Invalid size char-table");
1589 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1590 XCHAR_TABLE (tmp
)->top
= Qt
;
1599 tmp
= read_vector (readcharfun
, 0);
1600 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1601 error ("Invalid size char-table");
1602 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1603 XCHAR_TABLE (tmp
)->top
= Qnil
;
1606 Fsignal (Qinvalid_read_syntax
,
1607 Fcons (make_string ("#^^", 3), Qnil
));
1609 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1614 length
= read1 (readcharfun
, pch
, first_in_list
);
1618 Lisp_Object tmp
, val
;
1619 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1623 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1624 if (size_in_chars
!= XSTRING (tmp
)->size
1625 /* We used to print 1 char too many
1626 when the number of bits was a multiple of 8.
1627 Accept such input in case it came from an old version. */
1628 && ! (XFASTINT (length
)
1629 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1630 Fsignal (Qinvalid_read_syntax
,
1631 Fcons (make_string ("#&...", 5), Qnil
));
1633 val
= Fmake_bool_vector (length
, Qnil
);
1634 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1636 /* Clear the extraneous bits in the last byte. */
1637 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1638 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1639 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1642 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1647 /* Accept compiled functions at read-time so that we don't have to
1648 build them using function calls. */
1650 tmp
= read_vector (readcharfun
, 1);
1651 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1652 XVECTOR (tmp
)->contents
);
1657 struct gcpro gcpro1
;
1660 /* Read the string itself. */
1661 tmp
= read1 (readcharfun
, &ch
, 0);
1662 if (ch
!= 0 || !STRINGP (tmp
))
1663 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1665 /* Read the intervals and their properties. */
1668 Lisp_Object beg
, end
, plist
;
1670 beg
= read1 (readcharfun
, &ch
, 0);
1674 end
= read1 (readcharfun
, &ch
, 0);
1676 plist
= read1 (readcharfun
, &ch
, 0);
1678 Fsignal (Qinvalid_read_syntax
,
1679 Fcons (build_string ("invalid string property list"),
1681 Fset_text_properties (beg
, end
, plist
, tmp
);
1687 /* #@NUMBER is used to skip NUMBER following characters.
1688 That's used in .elc files to skip over doc strings
1689 and function definitions. */
1694 /* Read a decimal integer. */
1695 while ((c
= READCHAR
) >= 0
1696 && c
>= '0' && c
<= '9')
1704 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1706 /* If we are supposed to force doc strings into core right now,
1707 record the last string that we skipped,
1708 and record where in the file it comes from. */
1710 /* But first exchange saved_doc_string
1711 with prev_saved_doc_string, so we save two strings. */
1713 char *temp
= saved_doc_string
;
1714 int temp_size
= saved_doc_string_size
;
1715 file_offset temp_pos
= saved_doc_string_position
;
1716 int temp_len
= saved_doc_string_length
;
1718 saved_doc_string
= prev_saved_doc_string
;
1719 saved_doc_string_size
= prev_saved_doc_string_size
;
1720 saved_doc_string_position
= prev_saved_doc_string_position
;
1721 saved_doc_string_length
= prev_saved_doc_string_length
;
1723 prev_saved_doc_string
= temp
;
1724 prev_saved_doc_string_size
= temp_size
;
1725 prev_saved_doc_string_position
= temp_pos
;
1726 prev_saved_doc_string_length
= temp_len
;
1729 if (saved_doc_string_size
== 0)
1731 saved_doc_string_size
= nskip
+ 100;
1732 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1734 if (nskip
> saved_doc_string_size
)
1736 saved_doc_string_size
= nskip
+ 100;
1737 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1738 saved_doc_string_size
);
1741 saved_doc_string_position
= file_tell (instream
);
1743 /* Copy that many characters into saved_doc_string. */
1744 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1745 saved_doc_string
[i
] = c
= READCHAR
;
1747 saved_doc_string_length
= i
;
1751 /* Skip that many characters. */
1752 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1759 return Vload_file_name
;
1761 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1762 /* #:foo is the uninterned symbol named foo. */
1765 uninterned_symbol
= 1;
1769 /* Reader forms that can reuse previously read objects. */
1770 if (c
>= '0' && c
<= '9')
1775 /* Read a non-negative integer. */
1776 while (c
>= '0' && c
<= '9')
1782 /* #n=object returns object, but associates it with n for #n#. */
1785 /* Make a placeholder for #n# to use temporarily */
1786 Lisp_Object placeholder
;
1789 placeholder
= Fcons(Qnil
, Qnil
);
1790 cell
= Fcons (make_number (n
), placeholder
);
1791 read_objects
= Fcons (cell
, read_objects
);
1793 /* Read the object itself. */
1794 tem
= read0 (readcharfun
);
1796 /* Now put it everywhere the placeholder was... */
1797 substitute_object_in_subtree (tem
, placeholder
);
1799 /* ...and #n# will use the real value from now on. */
1800 Fsetcdr (cell
, tem
);
1804 /* #n# returns a previously read object. */
1807 tem
= Fassq (make_number (n
), read_objects
);
1810 /* Fall through to error message. */
1812 /* Fall through to error message. */
1816 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1819 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1824 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1834 new_backquote_flag
= 1;
1835 value
= read0 (readcharfun
);
1836 new_backquote_flag
= 0;
1838 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1842 if (new_backquote_flag
)
1844 Lisp_Object comma_type
= Qnil
;
1849 comma_type
= Qcomma_at
;
1851 comma_type
= Qcomma_dot
;
1854 if (ch
>= 0) UNREAD (ch
);
1855 comma_type
= Qcomma
;
1858 new_backquote_flag
= 0;
1859 value
= read0 (readcharfun
);
1860 new_backquote_flag
= 1;
1861 return Fcons (comma_type
, Fcons (value
, Qnil
));
1869 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1872 c
= read_escape (readcharfun
, 0);
1873 else if (BASE_LEADING_CODE_P (c
))
1874 c
= read_multibyte (c
, readcharfun
);
1876 return make_number (c
);
1881 register char *p
= read_buffer
;
1882 register char *end
= read_buffer
+ read_buffer_size
;
1884 /* Nonzero if we saw an escape sequence specifying
1885 a multibyte character. */
1886 int force_multibyte
= 0;
1887 /* Nonzero if we saw an escape sequence specifying
1888 a single-byte character. */
1889 int force_singlebyte
= 0;
1893 while ((c
= READCHAR
) >= 0
1896 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
1898 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1899 p
+= new - read_buffer
;
1900 read_buffer
+= new - read_buffer
;
1901 end
= read_buffer
+ read_buffer_size
;
1906 c
= read_escape (readcharfun
, 1);
1908 /* C is -1 if \ newline has just been seen */
1911 if (p
== read_buffer
)
1916 /* If an escape specifies a non-ASCII single-byte character,
1917 this must be a unibyte string. */
1918 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
))
1919 && ! ASCII_BYTE_P ((c
& ~CHAR_MODIFIER_MASK
)))
1920 force_singlebyte
= 1;
1923 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1925 /* Any modifiers for a multibyte character are invalid. */
1926 if (c
& CHAR_MODIFIER_MASK
)
1927 error ("Invalid modifier in string");
1928 p
+= CHAR_STRING (c
, p
);
1929 force_multibyte
= 1;
1933 /* Allow `\C- ' and `\C-?'. */
1934 if (c
== (CHAR_CTL
| ' '))
1936 else if (c
== (CHAR_CTL
| '?'))
1941 /* Shift modifier is valid only with [A-Za-z]. */
1942 if ((c
& 0377) >= 'A' && (c
& 0377) <= 'Z')
1944 else if ((c
& 0377) >= 'a' && (c
& 0377) <= 'z')
1945 c
= (c
& ~CHAR_SHIFT
) - ('a' - 'A');
1949 /* Move the meta bit to the right place for a string. */
1950 c
= (c
& ~CHAR_META
) | 0x80;
1952 error ("Invalid modifier in string");
1957 return Fsignal (Qend_of_file
, Qnil
);
1959 /* If purifying, and string starts with \ newline,
1960 return zero instead. This is for doc strings
1961 that we are really going to find in etc/DOC.nn.nn */
1962 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
1963 return make_number (0);
1965 if (force_multibyte
)
1966 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1967 else if (force_singlebyte
)
1968 nchars
= p
- read_buffer
;
1969 else if (load_convert_to_unibyte
)
1972 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1973 if (p
- read_buffer
!= nchars
)
1975 string
= make_multibyte_string (read_buffer
, nchars
,
1977 return Fstring_make_unibyte (string
);
1980 else if (EQ (readcharfun
, Qget_file_char
)
1981 || EQ (readcharfun
, Qlambda
))
1982 /* Nowadays, reading directly from a file
1983 is used only for compiled Emacs Lisp files,
1984 and those always use the Emacs internal encoding.
1985 Meanwhile, Qlambda is used for reading dynamic byte code
1986 (compiled with byte-compile-dynamic = t). */
1987 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1989 /* In all other cases, if we read these bytes as
1990 separate characters, treat them as separate characters now. */
1991 nchars
= p
- read_buffer
;
1994 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
1996 || (p
- read_buffer
!= nchars
)));
1997 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
1999 || (p
- read_buffer
!= nchars
)));
2004 #ifdef LISP_FLOAT_TYPE
2005 /* If a period is followed by a number, then we should read it
2006 as a floating point number. Otherwise, it denotes a dotted
2008 int next_char
= READCHAR
;
2011 if (! (next_char
>= '0' && next_char
<= '9'))
2018 /* Otherwise, we fall through! Note that the atom-reading loop
2019 below will now loop at least once, assuring that we will not
2020 try to UNREAD two characters in a row. */
2024 if (c
<= 040) goto retry
;
2026 register char *p
= read_buffer
;
2030 register char *end
= read_buffer
+ read_buffer_size
;
2033 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2034 || c
== '(' || c
== ')'
2035 #ifndef LISP_FLOAT_TYPE
2036 /* If we have floating-point support, then we need
2037 to allow <digits><dot><digits>. */
2039 #endif /* not LISP_FLOAT_TYPE */
2040 || c
== '[' || c
== ']' || c
== '#'
2043 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
2045 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2046 p
+= new - read_buffer
;
2047 read_buffer
+= new - read_buffer
;
2048 end
= read_buffer
+ read_buffer_size
;
2056 if (! SINGLE_BYTE_CHAR_P (c
))
2057 p
+= CHAR_STRING (c
, p
);
2066 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2067 p
+= new - read_buffer
;
2068 read_buffer
+= new - read_buffer
;
2069 /* end = read_buffer + read_buffer_size; */
2076 if (!quoted
&& !uninterned_symbol
)
2079 register Lisp_Object val
;
2081 if (*p1
== '+' || *p1
== '-') p1
++;
2082 /* Is it an integer? */
2085 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2086 #ifdef LISP_FLOAT_TYPE
2087 /* Integers can have trailing decimal points. */
2088 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2091 /* It is an integer. */
2093 #ifdef LISP_FLOAT_TYPE
2097 if (sizeof (int) == sizeof (EMACS_INT
))
2098 XSETINT (val
, atoi (read_buffer
));
2099 else if (sizeof (long) == sizeof (EMACS_INT
))
2100 XSETINT (val
, atol (read_buffer
));
2106 #ifdef LISP_FLOAT_TYPE
2107 if (isfloat_string (read_buffer
))
2109 /* Compute NaN and infinities using 0.0 in a variable,
2110 to cope with compilers that think they are smarter
2116 /* Negate the value ourselves. This treats 0, NaNs,
2117 and infinity properly on IEEE floating point hosts,
2118 and works around a common bug where atof ("-0.0")
2120 int negative
= read_buffer
[0] == '-';
2122 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2123 returns 1, is if the input ends in e+INF or e+NaN. */
2130 value
= zero
/ zero
;
2133 value
= atof (read_buffer
+ negative
);
2137 return make_float (negative
? - value
: value
);
2142 if (uninterned_symbol
)
2143 return make_symbol (read_buffer
);
2145 return intern (read_buffer
);
2151 /* List of nodes we've seen during substitute_object_in_subtree. */
2152 static Lisp_Object seen_list
;
2155 substitute_object_in_subtree (object
, placeholder
)
2157 Lisp_Object placeholder
;
2159 Lisp_Object check_object
;
2161 /* We haven't seen any objects when we start. */
2164 /* Make all the substitutions. */
2166 = substitute_object_recurse (object
, placeholder
, object
);
2168 /* Clear seen_list because we're done with it. */
2171 /* The returned object here is expected to always eq the
2173 if (!EQ (check_object
, object
))
2174 error ("Unexpected mutation error in reader");
2177 /* Feval doesn't get called from here, so no gc protection is needed. */
2178 #define SUBSTITUTE(get_val, set_val) \
2180 Lisp_Object old_value = get_val; \
2181 Lisp_Object true_value \
2182 = substitute_object_recurse (object, placeholder,\
2185 if (!EQ (old_value, true_value)) \
2192 substitute_object_recurse (object
, placeholder
, subtree
)
2194 Lisp_Object placeholder
;
2195 Lisp_Object subtree
;
2197 /* If we find the placeholder, return the target object. */
2198 if (EQ (placeholder
, subtree
))
2201 /* If we've been to this node before, don't explore it again. */
2202 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2205 /* If this node can be the entry point to a cycle, remember that
2206 we've seen it. It can only be such an entry point if it was made
2207 by #n=, which means that we can find it as a value in
2209 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2210 seen_list
= Fcons (subtree
, seen_list
);
2212 /* Recurse according to subtree's type.
2213 Every branch must return a Lisp_Object. */
2214 switch (XTYPE (subtree
))
2216 case Lisp_Vectorlike
:
2219 int length
= Flength(subtree
);
2220 for (i
= 0; i
< length
; i
++)
2222 Lisp_Object idx
= make_number (i
);
2223 SUBSTITUTE (Faref (subtree
, idx
),
2224 Faset (subtree
, idx
, true_value
));
2231 SUBSTITUTE (Fcar_safe (subtree
),
2232 Fsetcar (subtree
, true_value
));
2233 SUBSTITUTE (Fcdr_safe (subtree
),
2234 Fsetcdr (subtree
, true_value
));
2240 /* Check for text properties in each interval.
2241 substitute_in_interval contains part of the logic. */
2243 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2244 Lisp_Object arg
= Fcons (object
, placeholder
);
2246 traverse_intervals (root_interval
, 1, 0,
2247 &substitute_in_interval
, arg
);
2252 /* Other types don't recurse any further. */
2258 /* Helper function for substitute_object_recurse. */
2260 substitute_in_interval (interval
, arg
)
2264 Lisp_Object object
= Fcar (arg
);
2265 Lisp_Object placeholder
= Fcdr (arg
);
2267 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2271 #ifdef LISP_FLOAT_TYPE
2288 if (*cp
== '+' || *cp
== '-')
2291 if (*cp
>= '0' && *cp
<= '9')
2294 while (*cp
>= '0' && *cp
<= '9')
2302 if (*cp
>= '0' && *cp
<= '9')
2305 while (*cp
>= '0' && *cp
<= '9')
2308 if (*cp
== 'e' || *cp
== 'E')
2312 if (*cp
== '+' || *cp
== '-')
2316 if (*cp
>= '0' && *cp
<= '9')
2319 while (*cp
>= '0' && *cp
<= '9')
2322 else if (cp
== start
)
2324 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2329 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2335 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2336 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2337 || state
== (DOT_CHAR
|TRAIL_INT
)
2338 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2339 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2340 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2342 #endif /* LISP_FLOAT_TYPE */
2345 read_vector (readcharfun
, bytecodeflag
)
2346 Lisp_Object readcharfun
;
2351 register Lisp_Object
*ptr
;
2352 register Lisp_Object tem
, item
, vector
;
2353 register struct Lisp_Cons
*otem
;
2356 tem
= read_list (1, readcharfun
);
2357 len
= Flength (tem
);
2358 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2360 size
= XVECTOR (vector
)->size
;
2361 ptr
= XVECTOR (vector
)->contents
;
2362 for (i
= 0; i
< size
; i
++)
2365 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2366 bytecode object, the docstring containing the bytecode and
2367 constants values must be treated as unibyte and passed to
2368 Fread, to get the actual bytecode string and constants vector. */
2369 if (bytecodeflag
&& load_force_doc_strings
)
2371 if (i
== COMPILED_BYTECODE
)
2373 if (!STRINGP (item
))
2374 error ("invalid byte code");
2376 /* Delay handling the bytecode slot until we know whether
2377 it is lazily-loaded (we can tell by whether the
2378 constants slot is nil). */
2379 ptr
[COMPILED_CONSTANTS
] = item
;
2382 else if (i
== COMPILED_CONSTANTS
)
2384 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2388 /* Coerce string to unibyte (like string-as-unibyte,
2389 but without generating extra garbage and
2390 guaranteeing no change in the contents). */
2391 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2392 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2394 item
= Fread (bytestr
);
2396 error ("invalid byte code");
2398 otem
= XCONS (item
);
2399 bytestr
= XCAR (item
);
2404 /* Now handle the bytecode slot. */
2405 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2408 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2416 /* FLAG = 1 means check for ] to terminate rather than ) and .
2417 FLAG = -1 means check for starting with defun
2418 and make structure pure. */
2421 read_list (flag
, readcharfun
)
2423 register Lisp_Object readcharfun
;
2425 /* -1 means check next element for defun,
2426 0 means don't check,
2427 1 means already checked and found defun. */
2428 int defunflag
= flag
< 0 ? -1 : 0;
2429 Lisp_Object val
, tail
;
2430 register Lisp_Object elt
, tem
;
2431 struct gcpro gcpro1
, gcpro2
;
2432 /* 0 is the normal case.
2433 1 means this list is a doc reference; replace it with the number 0.
2434 2 means this list is a doc reference; replace it with the doc string. */
2435 int doc_reference
= 0;
2437 /* Initialize this to 1 if we are reading a list. */
2438 int first_in_list
= flag
<= 0;
2447 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2452 /* While building, if the list starts with #$, treat it specially. */
2453 if (EQ (elt
, Vload_file_name
)
2455 && !NILP (Vpurify_flag
))
2457 if (NILP (Vdoc_file_name
))
2458 /* We have not yet called Snarf-documentation, so assume
2459 this file is described in the DOC-MM.NN file
2460 and Snarf-documentation will fill in the right value later.
2461 For now, replace the whole list with 0. */
2464 /* We have already called Snarf-documentation, so make a relative
2465 file name for this file, so it can be found properly
2466 in the installed Lisp directory.
2467 We don't use Fexpand_file_name because that would make
2468 the directory absolute now. */
2469 elt
= concat2 (build_string ("../lisp/"),
2470 Ffile_name_nondirectory (elt
));
2472 else if (EQ (elt
, Vload_file_name
)
2474 && load_force_doc_strings
)
2483 Fsignal (Qinvalid_read_syntax
,
2484 Fcons (make_string (") or . in a vector", 18), Qnil
));
2492 XCDR (tail
) = read0 (readcharfun
);
2494 val
= read0 (readcharfun
);
2495 read1 (readcharfun
, &ch
, 0);
2499 if (doc_reference
== 1)
2500 return make_number (0);
2501 if (doc_reference
== 2)
2503 /* Get a doc string from the file we are loading.
2504 If it's in saved_doc_string, get it from there. */
2505 int pos
= XINT (XCDR (val
));
2506 /* Position is negative for user variables. */
2507 if (pos
< 0) pos
= -pos
;
2508 if (pos
>= saved_doc_string_position
2509 && pos
< (saved_doc_string_position
2510 + saved_doc_string_length
))
2512 int start
= pos
- saved_doc_string_position
;
2515 /* Process quoting with ^A,
2516 and find the end of the string,
2517 which is marked with ^_ (037). */
2518 for (from
= start
, to
= start
;
2519 saved_doc_string
[from
] != 037;)
2521 int c
= saved_doc_string
[from
++];
2524 c
= saved_doc_string
[from
++];
2526 saved_doc_string
[to
++] = c
;
2528 saved_doc_string
[to
++] = 0;
2530 saved_doc_string
[to
++] = 037;
2533 saved_doc_string
[to
++] = c
;
2536 return make_string (saved_doc_string
+ start
,
2539 /* Look in prev_saved_doc_string the same way. */
2540 else if (pos
>= prev_saved_doc_string_position
2541 && pos
< (prev_saved_doc_string_position
2542 + prev_saved_doc_string_length
))
2544 int start
= pos
- prev_saved_doc_string_position
;
2547 /* Process quoting with ^A,
2548 and find the end of the string,
2549 which is marked with ^_ (037). */
2550 for (from
= start
, to
= start
;
2551 prev_saved_doc_string
[from
] != 037;)
2553 int c
= prev_saved_doc_string
[from
++];
2556 c
= prev_saved_doc_string
[from
++];
2558 prev_saved_doc_string
[to
++] = c
;
2560 prev_saved_doc_string
[to
++] = 0;
2562 prev_saved_doc_string
[to
++] = 037;
2565 prev_saved_doc_string
[to
++] = c
;
2568 return make_string (prev_saved_doc_string
+ start
,
2572 return get_doc_string (val
, 0, 0);
2577 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2579 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2581 tem
= (read_pure
&& flag
<= 0
2582 ? pure_cons (elt
, Qnil
)
2583 : Fcons (elt
, Qnil
));
2590 defunflag
= EQ (elt
, Qdefun
);
2591 else if (defunflag
> 0)
2596 Lisp_Object Vobarray
;
2597 Lisp_Object initial_obarray
;
2599 /* oblookup stores the bucket number here, for the sake of Funintern. */
2601 int oblookup_last_bucket_number
;
2603 static int hash_string ();
2604 Lisp_Object
oblookup ();
2606 /* Get an error if OBARRAY is not an obarray.
2607 If it is one, return it. */
2610 check_obarray (obarray
)
2611 Lisp_Object obarray
;
2613 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2615 /* If Vobarray is now invalid, force it to be valid. */
2616 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2618 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2623 /* Intern the C string STR: return a symbol with that name,
2624 interned in the current obarray. */
2631 int len
= strlen (str
);
2632 Lisp_Object obarray
;
2635 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2636 obarray
= check_obarray (obarray
);
2637 tem
= oblookup (obarray
, str
, len
, len
);
2640 return Fintern (make_string (str
, len
), obarray
);
2643 /* Create an uninterned symbol with name STR. */
2649 int len
= strlen (str
);
2651 return Fmake_symbol ((!NILP (Vpurify_flag
)
2652 ? make_pure_string (str
, len
, len
, 0)
2653 : make_string (str
, len
)));
2656 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2657 "Return the canonical symbol whose name is STRING.\n\
2658 If there is none, one is created by this function and returned.\n\
2659 A second optional argument specifies the obarray to use;\n\
2660 it defaults to the value of `obarray'.")
2662 Lisp_Object string
, obarray
;
2664 register Lisp_Object tem
, sym
, *ptr
;
2666 if (NILP (obarray
)) obarray
= Vobarray
;
2667 obarray
= check_obarray (obarray
);
2669 CHECK_STRING (string
, 0);
2671 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2672 XSTRING (string
)->size
,
2673 STRING_BYTES (XSTRING (string
)));
2674 if (!INTEGERP (tem
))
2677 if (!NILP (Vpurify_flag
))
2678 string
= Fpurecopy (string
);
2679 sym
= Fmake_symbol (string
);
2680 XSYMBOL (sym
)->obarray
= obarray
;
2682 if ((XSTRING (string
)->data
[0] == ':')
2683 && EQ (obarray
, initial_obarray
))
2684 XSYMBOL (sym
)->value
= sym
;
2686 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2688 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2690 XSYMBOL (sym
)->next
= 0;
2695 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2696 "Return the canonical symbol named NAME, or nil if none exists.\n\
2697 NAME may be a string or a symbol. If it is a symbol, that exact\n\
2698 symbol is searched for.\n\
2699 A second optional argument specifies the obarray to use;\n\
2700 it defaults to the value of `obarray'.")
2702 Lisp_Object name
, obarray
;
2704 register Lisp_Object tem
;
2705 struct Lisp_String
*string
;
2707 if (NILP (obarray
)) obarray
= Vobarray
;
2708 obarray
= check_obarray (obarray
);
2710 if (!SYMBOLP (name
))
2712 CHECK_STRING (name
, 0);
2713 string
= XSTRING (name
);
2716 string
= XSYMBOL (name
)->name
;
2718 tem
= oblookup (obarray
, string
->data
, string
->size
, STRING_BYTES (string
));
2719 if (INTEGERP (tem
) || (SYMBOLP (name
) && !EQ (name
, tem
)))
2725 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2726 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2727 The value is t if a symbol was found and deleted, nil otherwise.\n\
2728 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2729 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2730 OBARRAY defaults to the value of the variable `obarray'.")
2732 Lisp_Object name
, obarray
;
2734 register Lisp_Object string
, tem
;
2737 if (NILP (obarray
)) obarray
= Vobarray
;
2738 obarray
= check_obarray (obarray
);
2741 XSETSTRING (string
, XSYMBOL (name
)->name
);
2744 CHECK_STRING (name
, 0);
2748 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2749 XSTRING (string
)->size
,
2750 STRING_BYTES (XSTRING (string
)));
2753 /* If arg was a symbol, don't delete anything but that symbol itself. */
2754 if (SYMBOLP (name
) && !EQ (name
, tem
))
2757 XSYMBOL (tem
)->obarray
= Qnil
;
2759 hash
= oblookup_last_bucket_number
;
2761 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2763 if (XSYMBOL (tem
)->next
)
2764 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2766 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2770 Lisp_Object tail
, following
;
2772 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2773 XSYMBOL (tail
)->next
;
2776 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2777 if (EQ (following
, tem
))
2779 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2788 /* Return the symbol in OBARRAY whose names matches the string
2789 of SIZE characters (SIZE_BYTE bytes) at PTR.
2790 If there is no such symbol in OBARRAY, return nil.
2792 Also store the bucket number in oblookup_last_bucket_number. */
2795 oblookup (obarray
, ptr
, size
, size_byte
)
2796 Lisp_Object obarray
;
2798 int size
, size_byte
;
2802 register Lisp_Object tail
;
2803 Lisp_Object bucket
, tem
;
2805 if (!VECTORP (obarray
)
2806 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2808 obarray
= check_obarray (obarray
);
2809 obsize
= XVECTOR (obarray
)->size
;
2811 /* This is sometimes needed in the middle of GC. */
2812 obsize
&= ~ARRAY_MARK_FLAG
;
2813 /* Combining next two lines breaks VMS C 2.3. */
2814 hash
= hash_string (ptr
, size_byte
);
2816 bucket
= XVECTOR (obarray
)->contents
[hash
];
2817 oblookup_last_bucket_number
= hash
;
2818 if (XFASTINT (bucket
) == 0)
2820 else if (!SYMBOLP (bucket
))
2821 error ("Bad data in guts of obarray"); /* Like CADR error message */
2823 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2825 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2826 && XSYMBOL (tail
)->name
->size
== size
2827 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2829 else if (XSYMBOL (tail
)->next
== 0)
2832 XSETINT (tem
, hash
);
2837 hash_string (ptr
, len
)
2841 register unsigned char *p
= ptr
;
2842 register unsigned char *end
= p
+ len
;
2843 register unsigned char c
;
2844 register int hash
= 0;
2849 if (c
>= 0140) c
-= 40;
2850 hash
= ((hash
<<3) + (hash
>>28) + c
);
2852 return hash
& 07777777777;
2856 map_obarray (obarray
, fn
, arg
)
2857 Lisp_Object obarray
;
2858 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2862 register Lisp_Object tail
;
2863 CHECK_VECTOR (obarray
, 1);
2864 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2866 tail
= XVECTOR (obarray
)->contents
[i
];
2871 if (XSYMBOL (tail
)->next
== 0)
2873 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2879 mapatoms_1 (sym
, function
)
2880 Lisp_Object sym
, function
;
2882 call1 (function
, sym
);
2885 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2886 "Call FUNCTION on every symbol in OBARRAY.\n\
2887 OBARRAY defaults to the value of `obarray'.")
2889 Lisp_Object function
, obarray
;
2891 if (NILP (obarray
)) obarray
= Vobarray
;
2892 obarray
= check_obarray (obarray
);
2894 map_obarray (obarray
, mapatoms_1
, function
);
2898 #define OBARRAY_SIZE 1511
2903 Lisp_Object oblength
;
2907 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2909 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2910 Vobarray
= Fmake_vector (oblength
, make_number (0));
2911 initial_obarray
= Vobarray
;
2912 staticpro (&initial_obarray
);
2913 /* Intern nil in the obarray */
2914 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2915 /* These locals are to kludge around a pyramid compiler bug. */
2916 hash
= hash_string ("nil", 3);
2917 /* Separate statement here to avoid VAXC bug. */
2918 hash
%= OBARRAY_SIZE
;
2919 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2922 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2923 XSYMBOL (Qnil
)->function
= Qunbound
;
2924 XSYMBOL (Qunbound
)->value
= Qunbound
;
2925 XSYMBOL (Qunbound
)->function
= Qunbound
;
2928 XSYMBOL (Qnil
)->value
= Qnil
;
2929 XSYMBOL (Qnil
)->plist
= Qnil
;
2930 XSYMBOL (Qt
)->value
= Qt
;
2932 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2935 Qvariable_documentation
= intern ("variable-documentation");
2936 staticpro (&Qvariable_documentation
);
2938 read_buffer_size
= 100 + MAX_MULTIBYTE_LENGTH
;
2939 read_buffer
= (char *) malloc (read_buffer_size
);
2944 struct Lisp_Subr
*sname
;
2947 sym
= intern (sname
->symbol_name
);
2948 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2951 #ifdef NOTDEF /* use fset in subr.el now */
2953 defalias (sname
, string
)
2954 struct Lisp_Subr
*sname
;
2958 sym
= intern (string
);
2959 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2963 /* Define an "integer variable"; a symbol whose value is forwarded
2964 to a C variable of type int. Sample call: */
2965 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
2967 defvar_int (namestring
, address
)
2971 Lisp_Object sym
, val
;
2972 sym
= intern (namestring
);
2973 val
= allocate_misc ();
2974 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
2975 XINTFWD (val
)->intvar
= address
;
2976 XSYMBOL (sym
)->value
= val
;
2979 /* Similar but define a variable whose value is T if address contains 1,
2980 NIL if address contains 0 */
2982 defvar_bool (namestring
, address
)
2986 Lisp_Object sym
, val
;
2987 sym
= intern (namestring
);
2988 val
= allocate_misc ();
2989 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
2990 XBOOLFWD (val
)->boolvar
= address
;
2991 XSYMBOL (sym
)->value
= val
;
2992 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
2995 /* Similar but define a variable whose value is the Lisp Object stored
2996 at address. Two versions: with and without gc-marking of the C
2997 variable. The nopro version is used when that variable will be
2998 gc-marked for some other reason, since marking the same slot twice
2999 can cause trouble with strings. */
3001 defvar_lisp_nopro (namestring
, address
)
3003 Lisp_Object
*address
;
3005 Lisp_Object sym
, val
;
3006 sym
= intern (namestring
);
3007 val
= allocate_misc ();
3008 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3009 XOBJFWD (val
)->objvar
= address
;
3010 XSYMBOL (sym
)->value
= val
;
3014 defvar_lisp (namestring
, address
)
3016 Lisp_Object
*address
;
3018 defvar_lisp_nopro (namestring
, address
);
3019 staticpro (address
);
3024 /* Similar but define a variable whose value is the Lisp Object stored in
3025 the current buffer. address is the address of the slot in the buffer
3026 that is current now. */
3029 defvar_per_buffer (namestring
, address
, type
, doc
)
3031 Lisp_Object
*address
;
3035 Lisp_Object sym
, val
;
3037 extern struct buffer buffer_local_symbols
;
3039 sym
= intern (namestring
);
3040 val
= allocate_misc ();
3041 offset
= (char *)address
- (char *)current_buffer
;
3043 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3044 XBUFFER_OBJFWD (val
)->offset
= offset
;
3045 XSYMBOL (sym
)->value
= val
;
3046 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
3047 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
3048 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
3049 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3050 slot of buffer_local_flags */
3054 #endif /* standalone */
3056 /* Similar but define a variable whose value is the Lisp Object stored
3057 at a particular offset in the current kboard object. */
3060 defvar_kboard (namestring
, offset
)
3064 Lisp_Object sym
, val
;
3065 sym
= intern (namestring
);
3066 val
= allocate_misc ();
3067 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3068 XKBOARD_OBJFWD (val
)->offset
= offset
;
3069 XSYMBOL (sym
)->value
= val
;
3072 /* Record the value of load-path used at the start of dumping
3073 so we can see if the site changed it later during dumping. */
3074 static Lisp_Object dump_path
;
3080 int turn_off_warning
= 0;
3082 /* Compute the default load-path. */
3084 normal
= PATH_LOADSEARCH
;
3085 Vload_path
= decode_env_path (0, normal
);
3087 if (NILP (Vpurify_flag
))
3088 normal
= PATH_LOADSEARCH
;
3090 normal
= PATH_DUMPLOADSEARCH
;
3092 /* In a dumped Emacs, we normally have to reset the value of
3093 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3094 uses ../lisp, instead of the path of the installed elisp
3095 libraries. However, if it appears that Vload_path was changed
3096 from the default before dumping, don't override that value. */
3099 if (! NILP (Fequal (dump_path
, Vload_path
)))
3101 Vload_path
= decode_env_path (0, normal
);
3102 if (!NILP (Vinstallation_directory
))
3104 /* Add to the path the lisp subdir of the
3105 installation dir, if it exists. */
3106 Lisp_Object tem
, tem1
;
3107 tem
= Fexpand_file_name (build_string ("lisp"),
3108 Vinstallation_directory
);
3109 tem1
= Ffile_exists_p (tem
);
3112 if (NILP (Fmember (tem
, Vload_path
)))
3114 turn_off_warning
= 1;
3115 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3119 /* That dir doesn't exist, so add the build-time
3120 Lisp dirs instead. */
3121 Vload_path
= nconc2 (Vload_path
, dump_path
);
3123 /* Add leim under the installation dir, if it exists. */
3124 tem
= Fexpand_file_name (build_string ("leim"),
3125 Vinstallation_directory
);
3126 tem1
= Ffile_exists_p (tem
);
3129 if (NILP (Fmember (tem
, Vload_path
)))
3130 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3133 /* Add site-list under the installation dir, if it exists. */
3134 tem
= Fexpand_file_name (build_string ("site-lisp"),
3135 Vinstallation_directory
);
3136 tem1
= Ffile_exists_p (tem
);
3139 if (NILP (Fmember (tem
, Vload_path
)))
3140 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3143 /* If Emacs was not built in the source directory,
3144 and it is run from where it was built, add to load-path
3145 the lisp, leim and site-lisp dirs under that directory. */
3147 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3151 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3152 Vinstallation_directory
);
3153 tem1
= Ffile_exists_p (tem
);
3155 /* Don't be fooled if they moved the entire source tree
3156 AFTER dumping Emacs. If the build directory is indeed
3157 different from the source dir, src/Makefile.in and
3158 src/Makefile will not be found together. */
3159 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3160 Vinstallation_directory
);
3161 tem2
= Ffile_exists_p (tem
);
3162 if (!NILP (tem1
) && NILP (tem2
))
3164 tem
= Fexpand_file_name (build_string ("lisp"),
3167 if (NILP (Fmember (tem
, Vload_path
)))
3168 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3170 tem
= Fexpand_file_name (build_string ("leim"),
3173 if (NILP (Fmember (tem
, Vload_path
)))
3174 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3176 tem
= Fexpand_file_name (build_string ("site-lisp"),
3179 if (NILP (Fmember (tem
, Vload_path
)))
3180 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3188 /* NORMAL refers to the lisp dir in the source directory. */
3189 /* We used to add ../lisp at the front here, but
3190 that caused trouble because it was copied from dump_path
3191 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3192 It should be unnecessary. */
3193 Vload_path
= decode_env_path (0, normal
);
3194 dump_path
= Vload_path
;
3199 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3200 almost never correct, thereby causing a warning to be printed out that
3201 confuses users. Since PATH_LOADSEARCH is always overridden by the
3202 EMACSLOADPATH environment variable below, disable the warning on NT. */
3204 /* Warn if dirs in the *standard* path don't exist. */
3205 if (!turn_off_warning
)
3207 Lisp_Object path_tail
;
3209 for (path_tail
= Vload_path
;
3211 path_tail
= XCDR (path_tail
))
3213 Lisp_Object dirfile
;
3214 dirfile
= Fcar (path_tail
);
3215 if (STRINGP (dirfile
))
3217 dirfile
= Fdirectory_file_name (dirfile
);
3218 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3219 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3224 #endif /* WINDOWSNT */
3226 /* If the EMACSLOADPATH environment variable is set, use its value.
3227 This doesn't apply if we're dumping. */
3229 if (NILP (Vpurify_flag
)
3230 && egetenv ("EMACSLOADPATH"))
3232 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3236 load_in_progress
= 0;
3237 Vload_file_name
= Qnil
;
3239 load_descriptor_list
= Qnil
;
3241 Vstandard_input
= Qt
;
3244 /* Print a warning, using format string FORMAT, that directory DIRNAME
3245 does not exist. Print it on stderr and put it in *Message*. */
3248 dir_warning (format
, dirname
)
3250 Lisp_Object dirname
;
3253 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3255 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3256 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3257 /* Don't log the warning before we've initialized!! */
3259 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3266 defsubr (&Sread_from_string
);
3268 defsubr (&Sintern_soft
);
3269 defsubr (&Sunintern
);
3271 defsubr (&Seval_buffer
);
3272 defsubr (&Seval_region
);
3273 defsubr (&Sread_char
);
3274 defsubr (&Sread_char_exclusive
);
3275 defsubr (&Sread_event
);
3276 defsubr (&Sget_file_char
);
3277 defsubr (&Smapatoms
);
3279 DEFVAR_LISP ("obarray", &Vobarray
,
3280 "Symbol table for use by `intern' and `read'.\n\
3281 It is a vector whose length ought to be prime for best results.\n\
3282 The vector's contents don't make sense if examined from Lisp programs;\n\
3283 to find all the symbols in an obarray, use `mapatoms'.");
3285 DEFVAR_LISP ("values", &Vvalues
,
3286 "List of values of all expressions which were read, evaluated and printed.\n\
3287 Order is reverse chronological.");
3289 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3290 "Stream for read to get input from.\n\
3291 See documentation of `read' for possible values.");
3292 Vstandard_input
= Qt
;
3294 DEFVAR_LISP ("load-path", &Vload_path
,
3295 "*List of directories to search for files to load.\n\
3296 Each element is a string (directory name) or nil (try default directory).\n\
3297 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3298 otherwise to default specified by file `epaths.h' when Emacs was built.");
3300 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3301 "Non-nil iff inside of `load'.");
3303 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3304 "An alist of expressions to be evalled when particular files are loaded.\n\
3305 Each element looks like (FILENAME FORMS...).\n\
3306 When `load' is run and the file-name argument is FILENAME,\n\
3307 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3308 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3309 with no directory specified, since that is how `load' is normally called.\n\
3310 An error in FORMS does not undo the load,\n\
3311 but does prevent execution of the rest of the FORMS.");
3312 Vafter_load_alist
= Qnil
;
3314 DEFVAR_LISP ("load-history", &Vload_history
,
3315 "Alist mapping source file names to symbols and features.\n\
3316 Each alist element is a list that starts with a file name,\n\
3317 except for one element (optional) that starts with nil and describes\n\
3318 definitions evaluated from buffers not visiting files.\n\
3319 The remaining elements of each list are symbols defined as functions\n\
3320 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3321 Vload_history
= Qnil
;
3323 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3324 "Full name of file being loaded by `load'.");
3325 Vload_file_name
= Qnil
;
3327 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3328 "File name, including directory, of user's initialization file.
3329 If the file loaded had extension `.elc' and there was a corresponding `.el'
3330 file, this variable contains the name of the .el file, suitable for use
3331 by functions like `custom-save-all' which edit the init file.");
3332 Vuser_init_file
= Qnil
;
3334 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3335 "Used for internal purposes by `load'.");
3336 Vcurrent_load_list
= Qnil
;
3338 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3339 "Function used by `load' and `eval-region' for reading expressions.\n\
3340 The default is nil, which means use the function `read'.");
3341 Vload_read_function
= Qnil
;
3343 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3344 "Function called in `load' for loading an Emacs lisp source file.\n\
3345 This function is for doing code conversion before reading the source file.\n\
3346 If nil, loading is done without any code conversion.\n\
3347 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3348 FULLNAME is the full name of FILE.\n\
3349 See `load' for the meaning of the remaining arguments.");
3350 Vload_source_file_function
= Qnil
;
3352 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3353 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3354 This is useful when the file being loaded is a temporary copy.");
3355 load_force_doc_strings
= 0;
3357 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3358 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3359 This is normally used in `load-with-code-conversion'\n\
3360 for loading non-compiled files.");
3361 load_convert_to_unibyte
= 0;
3363 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3364 "Directory in which Emacs sources were found when Emacs was built.\n\
3365 You cannot count on them to still be there!");
3367 = Fexpand_file_name (build_string ("../"),
3368 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3370 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3371 "List of files that were preloaded (when dumping Emacs).");
3372 Vpreloaded_file_list
= Qnil
;
3374 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars
,
3375 "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
3376 Vbyte_boolean_vars
= Qnil
;
3378 /* Vsource_directory was initialized in init_lread. */
3380 load_descriptor_list
= Qnil
;
3381 staticpro (&load_descriptor_list
);
3383 Qcurrent_load_list
= intern ("current-load-list");
3384 staticpro (&Qcurrent_load_list
);
3386 Qstandard_input
= intern ("standard-input");
3387 staticpro (&Qstandard_input
);
3389 Qread_char
= intern ("read-char");
3390 staticpro (&Qread_char
);
3392 Qget_file_char
= intern ("get-file-char");
3393 staticpro (&Qget_file_char
);
3395 Qbackquote
= intern ("`");
3396 staticpro (&Qbackquote
);
3397 Qcomma
= intern (",");
3398 staticpro (&Qcomma
);
3399 Qcomma_at
= intern (",@");
3400 staticpro (&Qcomma_at
);
3401 Qcomma_dot
= intern (",.");
3402 staticpro (&Qcomma_dot
);
3404 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3405 staticpro (&Qinhibit_file_name_operation
);
3407 Qascii_character
= intern ("ascii-character");
3408 staticpro (&Qascii_character
);
3410 Qfunction
= intern ("function");
3411 staticpro (&Qfunction
);
3413 Qload
= intern ("load");
3416 Qload_file_name
= intern ("load-file-name");
3417 staticpro (&Qload_file_name
);
3419 staticpro (&dump_path
);
3421 staticpro (&read_objects
);
3422 read_objects
= Qnil
;
3423 staticpro (&seen_list
);