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 all DEFVAR_BOOL variables. Used by the byte optimizer. */
131 Lisp_Object Vbyte_boolean_vars
;
133 /* List of descriptors now open for Fload. */
134 static Lisp_Object load_descriptor_list
;
136 /* File for get_file_char to read from. Use by load. */
137 static FILE *instream
;
139 /* When nonzero, read conses in pure space */
140 static int read_pure
;
142 /* For use within read-from-string (this reader is non-reentrant!!) */
143 static int read_from_string_index
;
144 static int read_from_string_index_byte
;
145 static int read_from_string_limit
;
147 /* Number of bytes left to read in the buffer character
148 that `readchar' has already advanced over. */
149 static int readchar_backlog
;
151 /* This contains the last string skipped with #@. */
152 static char *saved_doc_string
;
153 /* Length of buffer allocated in saved_doc_string. */
154 static int saved_doc_string_size
;
155 /* Length of actual data in saved_doc_string. */
156 static int saved_doc_string_length
;
157 /* This is the file position that string came from. */
158 static int saved_doc_string_position
;
160 /* This contains the previous string skipped with #@.
161 We copy it from saved_doc_string when a new string
162 is put in saved_doc_string. */
163 static char *prev_saved_doc_string
;
164 /* Length of buffer allocated in prev_saved_doc_string. */
165 static int prev_saved_doc_string_size
;
166 /* Length of actual data in prev_saved_doc_string. */
167 static int prev_saved_doc_string_length
;
168 /* This is the file position that string came from. */
169 static int prev_saved_doc_string_position
;
171 /* Nonzero means inside a new-style backquote
172 with no surrounding parentheses.
173 Fread initializes this to zero, so we need not specbind it
174 or worry about what happens to it when there is an error. */
175 static int new_backquote_flag
;
177 /* Handle unreading and rereading of characters.
178 Write READCHAR to read a character,
179 UNREAD(c) to unread c to be read again.
181 These macros actually read/unread a byte code, multibyte characters
182 are not handled here. The caller should manage them if necessary.
185 #define READCHAR readchar (readcharfun)
186 #define UNREAD(c) unreadchar (readcharfun, c)
189 readchar (readcharfun
)
190 Lisp_Object readcharfun
;
193 register int c
, mpos
;
195 if (BUFFERP (readcharfun
))
197 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
199 int pt_byte
= BUF_PT_BYTE (inbuffer
);
200 int orig_pt_byte
= pt_byte
;
202 if (readchar_backlog
> 0)
203 /* We get the address of the byte just passed,
204 which is the last byte of the character.
205 The other bytes in this character are consecutive with it,
206 because the gap can't be in the middle of a character. */
207 return *(BUF_BYTE_ADDRESS (inbuffer
, BUF_PT_BYTE (inbuffer
) - 1)
208 - --readchar_backlog
);
210 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
213 readchar_backlog
= -1;
215 if (! NILP (inbuffer
->enable_multibyte_characters
))
217 unsigned char workbuf
[4];
218 unsigned char *str
= workbuf
;
221 /* Fetch the character code from the buffer. */
222 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
223 BUF_INC_POS (inbuffer
, pt_byte
);
224 c
= STRING_CHAR (p
, pt_byte
- orig_pt_byte
);
226 /* Find the byte-sequence representation of that character. */
227 if (SINGLE_BYTE_CHAR_P (c
))
228 length
= 1, workbuf
[0] = c
;
230 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
232 /* If the bytes for this character in the buffer
233 are not identical with what the character code implies,
234 read the bytes one by one from the buffer. */
235 if (length
!= pt_byte
- orig_pt_byte
236 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
238 readchar_backlog
= pt_byte
- orig_pt_byte
;
239 c
= BUF_FETCH_BYTE (inbuffer
, orig_pt_byte
);
245 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
248 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
252 if (MARKERP (readcharfun
))
254 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
256 int bytepos
= marker_byte_position (readcharfun
);
257 int orig_bytepos
= bytepos
;
259 if (readchar_backlog
> 0)
260 /* We get the address of the byte just passed,
261 which is the last byte of the character.
262 The other bytes in this character are consecutive with it,
263 because the gap can't be in the middle of a character. */
264 return *(BUF_BYTE_ADDRESS (inbuffer
, XMARKER (readcharfun
)->bytepos
- 1)
265 - --readchar_backlog
);
267 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
270 readchar_backlog
= -1;
272 if (! NILP (inbuffer
->enable_multibyte_characters
))
274 unsigned char workbuf
[4];
275 unsigned char *str
= workbuf
;
278 /* Fetch the character code from the buffer. */
279 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
280 BUF_INC_POS (inbuffer
, bytepos
);
281 c
= STRING_CHAR (p
, bytepos
- orig_bytepos
);
283 /* Find the byte-sequence representation of that character. */
284 if (SINGLE_BYTE_CHAR_P (c
))
285 length
= 1, workbuf
[0] = c
;
287 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
289 /* If the bytes for this character in the buffer
290 are not identical with what the character code implies,
291 read the bytes one by one from the buffer. */
292 if (length
!= bytepos
- orig_bytepos
293 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
295 readchar_backlog
= bytepos
- orig_bytepos
;
296 c
= BUF_FETCH_BYTE (inbuffer
, orig_bytepos
);
302 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
306 XMARKER (readcharfun
)->bytepos
= bytepos
;
307 XMARKER (readcharfun
)->charpos
++;
312 if (EQ (readcharfun
, Qlambda
))
313 return read_bytecode_char (0);
315 if (EQ (readcharfun
, Qget_file_char
))
319 /* Interrupted reads have been observed while reading over the network */
320 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
329 if (STRINGP (readcharfun
))
331 if (read_from_string_index
>= read_from_string_limit
)
333 else if (STRING_MULTIBYTE (readcharfun
))
334 FETCH_STRING_CHAR_ADVANCE (c
, readcharfun
,
335 read_from_string_index
,
336 read_from_string_index_byte
);
338 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
343 tem
= call0 (readcharfun
);
350 /* Unread the character C in the way appropriate for the stream READCHARFUN.
351 If the stream is a user function, call it with the char as argument. */
354 unreadchar (readcharfun
, c
)
355 Lisp_Object readcharfun
;
359 /* Don't back up the pointer if we're unreading the end-of-input mark,
360 since readchar didn't advance it when we read it. */
362 else if (BUFFERP (readcharfun
))
364 struct buffer
*b
= XBUFFER (readcharfun
);
365 int bytepos
= BUF_PT_BYTE (b
);
367 if (readchar_backlog
>= 0)
372 if (! NILP (b
->enable_multibyte_characters
))
373 BUF_DEC_POS (b
, bytepos
);
377 BUF_PT_BYTE (b
) = bytepos
;
380 else if (MARKERP (readcharfun
))
382 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
383 int bytepos
= XMARKER (readcharfun
)->bytepos
;
385 if (readchar_backlog
>= 0)
389 XMARKER (readcharfun
)->charpos
--;
390 if (! NILP (b
->enable_multibyte_characters
))
391 BUF_DEC_POS (b
, bytepos
);
395 XMARKER (readcharfun
)->bytepos
= bytepos
;
398 else if (STRINGP (readcharfun
))
400 read_from_string_index
--;
401 read_from_string_index_byte
402 = string_char_to_byte (readcharfun
, read_from_string_index
);
404 else if (EQ (readcharfun
, Qlambda
))
405 read_bytecode_char (1);
406 else if (EQ (readcharfun
, Qget_file_char
))
407 ungetc (c
, instream
);
409 call1 (readcharfun
, make_number (c
));
412 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
413 static int read_multibyte ();
414 static Lisp_Object
substitute_object_recurse ();
415 static void substitute_object_in_subtree (), substitute_in_interval ();
418 /* Get a character from the tty. */
420 extern Lisp_Object
read_char ();
422 /* Read input events until we get one that's acceptable for our purposes.
424 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
425 until we get a character we like, and then stuffed into
428 If ASCII_REQUIRED is non-zero, we check function key events to see
429 if the unmodified version of the symbol has a Qascii_character
430 property, and use that character, if present.
432 If ERROR_NONASCII is non-zero, we signal an error if the input we
433 get isn't an ASCII character with modifiers. If it's zero but
434 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
437 If INPUT_METHOD is nonzero, we invoke the current input method
438 if the character warrants that. */
441 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
443 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
446 return make_number (getchar ());
448 register Lisp_Object val
, delayed_switch_frame
;
450 delayed_switch_frame
= Qnil
;
452 /* Read until we get an acceptable event. */
454 val
= read_char (0, 0, 0,
455 (input_method
? Qnil
: Qt
),
461 /* switch-frame events are put off until after the next ASCII
462 character. This is better than signaling an error just because
463 the last characters were typed to a separate minibuffer frame,
464 for example. Eventually, some code which can deal with
465 switch-frame events will read it and process it. */
467 && EVENT_HAS_PARAMETERS (val
)
468 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
470 delayed_switch_frame
= val
;
476 /* Convert certain symbols to their ASCII equivalents. */
479 Lisp_Object tem
, tem1
, tem2
;
480 tem
= Fget (val
, Qevent_symbol_element_mask
);
483 tem1
= Fget (Fcar (tem
), Qascii_character
);
484 /* Merge this symbol's modifier bits
485 with the ASCII equivalent of its basic code. */
487 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
491 /* If we don't have a character now, deal with it appropriately. */
496 Vunread_command_events
= Fcons (val
, Qnil
);
497 error ("Non-character input-event");
504 if (! NILP (delayed_switch_frame
))
505 unread_switch_frame
= delayed_switch_frame
;
511 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 2, 0,
512 "Read a character from the command input (keyboard or macro).\n\
513 It is returned as a number.\n\
514 If the user generates an event which is not a character (i.e. a mouse\n\
515 click or function key event), `read-char' signals an error. As an\n\
516 exception, switch-frame events are put off until non-ASCII events can\n\
518 If you want to read non-character events, or ignore them, call\n\
519 `read-event' or `read-char-exclusive' instead.\n\
521 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
522 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
523 input method is turned on in the current buffer, that input method\n\
524 is used for reading a character.")
525 (prompt
, inherit_input_method
)
526 Lisp_Object prompt
, inherit_input_method
;
529 message_with_string ("%s", prompt
, 0);
530 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
));
533 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 2, 0,
534 "Read an event object from the input stream.\n\
535 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
536 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
537 input method is turned on in the current buffer, that input method\n\
538 is used for reading a character.")
539 (prompt
, inherit_input_method
)
540 Lisp_Object prompt
, inherit_input_method
;
543 message_with_string ("%s", prompt
, 0);
544 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
));
547 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 2, 0,
548 "Read a character from the command input (keyboard or macro).\n\
549 It is returned as a number. Non-character events are ignored.\n\
551 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
552 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
553 input method is turned on in the current buffer, that input method\n\
554 is used for reading a character.")
555 (prompt
, inherit_input_method
)
556 Lisp_Object prompt
, inherit_input_method
;
559 message_with_string ("%s", prompt
, 0);
560 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
));
563 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
564 "Don't use this yourself.")
567 register Lisp_Object val
;
568 XSETINT (val
, getc (instream
));
572 static void readevalloop ();
573 static Lisp_Object
load_unwind ();
574 static Lisp_Object
load_descriptor_unwind ();
576 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
577 "Execute a file of Lisp code named FILE.\n\
578 First try FILE with `.elc' appended, then try with `.el',\n\
579 then try FILE unmodified.\n\
580 This function searches the directories in `load-path'.\n\
581 If optional second arg NOERROR is non-nil,\n\
582 report no error if FILE doesn't exist.\n\
583 Print messages at start and end of loading unless\n\
584 optional third arg NOMESSAGE is non-nil.\n\
585 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
586 suffixes `.elc' or `.el' to the specified name FILE.\n\
587 If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
588 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
589 it ends in one of those suffixes or includes a directory name.\n\
590 Return t if file exists.")
591 (file
, noerror
, nomessage
, nosuffix
, must_suffix
)
592 Lisp_Object file
, noerror
, nomessage
, nosuffix
, must_suffix
;
594 register FILE *stream
;
595 register int fd
= -1;
596 register Lisp_Object lispstream
;
597 int count
= specpdl_ptr
- specpdl
;
601 /* 1 means we printed the ".el is newer" message. */
603 /* 1 means we are loading a compiled file. */
611 CHECK_STRING (file
, 0);
613 /* If file name is magic, call the handler. */
614 handler
= Ffind_file_name_handler (file
, Qload
);
616 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
618 /* Do this after the handler to avoid
619 the need to gcpro noerror, nomessage and nosuffix.
620 (Below here, we care only whether they are nil or not.) */
621 file
= Fsubstitute_in_file_name (file
);
623 /* Avoid weird lossage with null string as arg,
624 since it would try to load a directory as a Lisp file */
625 if (XSTRING (file
)->size
> 0)
627 int size
= XSTRING (file
)->size
;
631 if (! NILP (must_suffix
))
633 /* Don't insist on adding a suffix if FILE already ends with one. */
635 && !strcmp (XSTRING (file
)->data
+ size
- 3, ".el"))
638 && !strcmp (XSTRING (file
)->data
+ size
- 4, ".elc"))
640 /* Don't insist on adding a suffix
641 if the argument includes a directory name. */
642 else if (! NILP (Ffile_name_directory (file
)))
646 fd
= openp (Vload_path
, file
,
647 (!NILP (nosuffix
) ? ""
648 : ! NILP (must_suffix
) ? ".elc:.el"
658 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
659 Fcons (file
, Qnil
)));
664 if (EQ (Qt
, Vuser_init_file
))
665 Vuser_init_file
= found
;
667 /* If FD is 0, that means openp found a magic file. */
670 if (NILP (Fequal (found
, file
)))
671 /* If FOUND is a different file name from FILE,
672 find its handler even if we have already inhibited
673 the `load' operation on FILE. */
674 handler
= Ffind_file_name_handler (found
, Qt
);
676 handler
= Ffind_file_name_handler (found
, Qload
);
677 if (! NILP (handler
))
678 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
681 /* Load .elc files directly, but not when they are
682 remote and have no handler! */
683 if (!bcmp (&(XSTRING (found
)->data
[XSTRING (found
)->size
- 4]),
695 stat ((char *)XSTRING (found
)->data
, &s1
);
696 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 0;
697 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
698 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
700 /* Make the progress messages mention that source is newer. */
703 /* If we won't print another message, mention this anyway. */
704 if (! NILP (nomessage
))
705 message_with_string ("Source file `%s' newer than byte-compiled file",
708 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 'c';
712 /* We are loading a source file (*.el). */
713 if (!NILP (Vload_source_file_function
))
717 return call4 (Vload_source_file_function
, found
, file
,
718 NILP (noerror
) ? Qnil
: Qt
,
719 NILP (nomessage
) ? Qnil
: Qt
);
725 stream
= fopen ((char *) XSTRING (found
)->data
, fmode
);
726 #else /* not WINDOWSNT */
727 stream
= fdopen (fd
, fmode
);
728 #endif /* not WINDOWSNT */
732 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
735 if (! NILP (Vpurify_flag
))
736 Vpreloaded_file_list
= Fcons (file
, Vpreloaded_file_list
);
738 if (NILP (nomessage
))
741 message_with_string ("Loading %s (source)...", file
, 1);
743 message_with_string ("Loading %s (compiled; note, source file is newer)...",
745 else /* The typical case; compiled file newer than source file. */
746 message_with_string ("Loading %s...", file
, 1);
750 lispstream
= Fcons (Qnil
, Qnil
);
751 XSETFASTINT (XCAR (lispstream
), (EMACS_UINT
)stream
>> 16);
752 XSETFASTINT (XCDR (lispstream
), (EMACS_UINT
)stream
& 0xffff);
753 record_unwind_protect (load_unwind
, lispstream
);
754 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
755 specbind (Qload_file_name
, found
);
756 specbind (Qinhibit_file_name_operation
, Qnil
);
758 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
760 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0, Qnil
, Qnil
);
761 unbind_to (count
, Qnil
);
763 /* Run any load-hooks for this file. */
764 temp
= Fassoc (file
, Vafter_load_alist
);
766 Fprogn (Fcdr (temp
));
769 if (saved_doc_string
)
770 free (saved_doc_string
);
771 saved_doc_string
= 0;
772 saved_doc_string_size
= 0;
774 if (prev_saved_doc_string
)
775 free (prev_saved_doc_string
);
776 prev_saved_doc_string
= 0;
777 prev_saved_doc_string_size
= 0;
779 if (!noninteractive
&& NILP (nomessage
))
782 message_with_string ("Loading %s (source)...done", file
, 1);
784 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
786 else /* The typical case; compiled file newer than source file. */
787 message_with_string ("Loading %s...done", file
, 1);
793 load_unwind (stream
) /* used as unwind-protect function in load */
796 fclose ((FILE *) (XFASTINT (XCAR (stream
)) << 16
797 | XFASTINT (XCDR (stream
))));
798 if (--load_in_progress
< 0) load_in_progress
= 0;
803 load_descriptor_unwind (oldlist
)
806 load_descriptor_list
= oldlist
;
810 /* Close all descriptors in use for Floads.
811 This is used when starting a subprocess. */
818 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCDR (tail
))
819 close (XFASTINT (XCAR (tail
)));
824 complete_filename_p (pathname
)
825 Lisp_Object pathname
;
827 register unsigned char *s
= XSTRING (pathname
)->data
;
828 return (IS_DIRECTORY_SEP (s
[0])
829 || (XSTRING (pathname
)->size
> 2
830 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
840 /* Search for a file whose name is STR, looking in directories
841 in the Lisp list PATH, and trying suffixes from SUFFIX.
842 SUFFIX is a string containing possible suffixes separated by colons.
843 On success, returns a file descriptor. On failure, returns -1.
845 EXEC_ONLY nonzero means don't open the files,
846 just look for one that is executable. In this case,
847 returns 1 on success.
849 If STOREPTR is nonzero, it points to a slot where the name of
850 the file actually found should be stored as a Lisp string.
851 nil is stored there on failure.
853 If the file we find is remote, return 0
854 but store the found remote file name in *STOREPTR.
855 We do not check for remote files if EXEC_ONLY is nonzero. */
858 openp (path
, str
, suffix
, storeptr
, exec_only
)
859 Lisp_Object path
, str
;
861 Lisp_Object
*storeptr
;
867 register char *fn
= buf
;
870 Lisp_Object filename
;
878 if (complete_filename_p (str
))
881 for (; !NILP (path
); path
= Fcdr (path
))
885 filename
= Fexpand_file_name (str
, Fcar (path
));
886 if (!complete_filename_p (filename
))
887 /* If there are non-absolute elts in PATH (eg ".") */
888 /* Of course, this could conceivably lose if luser sets
889 default-directory to be something non-absolute... */
891 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
892 if (!complete_filename_p (filename
))
893 /* Give up on this path element! */
897 /* Calculate maximum size of any filename made from
898 this path element/specified file name and any possible suffix. */
899 want_size
= strlen (suffix
) + XSTRING (filename
)->size
+ 1;
900 if (fn_size
< want_size
)
901 fn
= (char *) alloca (fn_size
= 100 + want_size
);
905 /* Loop over suffixes. */
908 char *esuffix
= (char *) index (nsuffix
, ':');
909 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
912 /* Concatenate path element/specified name with the suffix.
913 If the directory starts with /:, remove that. */
914 if (XSTRING (filename
)->size
> 2
915 && XSTRING (filename
)->data
[0] == '/'
916 && XSTRING (filename
)->data
[1] == ':')
918 strncpy (fn
, XSTRING (filename
)->data
+ 2,
919 XSTRING (filename
)->size
- 2);
920 fn
[XSTRING (filename
)->size
- 2] = 0;
924 strncpy (fn
, XSTRING (filename
)->data
, XSTRING (filename
)->size
);
925 fn
[XSTRING (filename
)->size
] = 0;
928 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
929 strncat (fn
, nsuffix
, lsuffix
);
931 /* Check that the file exists and is not a directory. */
935 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
936 if (! NILP (handler
) && ! exec_only
)
941 string
= build_string (fn
);
942 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
943 : Ffile_readable_p (string
));
945 && ! NILP (Ffile_directory_p (build_string (fn
))))
950 /* We succeeded; return this descriptor and filename. */
952 *storeptr
= build_string (fn
);
959 int exists
= (stat (fn
, &st
) >= 0
960 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
963 /* Check that we can access or open it. */
965 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
967 fd
= open (fn
, O_RDONLY
, 0);
971 /* We succeeded; return this descriptor and filename. */
973 *storeptr
= build_string (fn
);
980 /* Advance to next suffix. */
983 nsuffix
+= lsuffix
+ 1;
994 /* Merge the list we've accumulated of globals from the current input source
995 into the load_history variable. The details depend on whether
996 the source has an associated file name or not. */
999 build_load_history (stream
, source
)
1003 register Lisp_Object tail
, prev
, newelt
;
1004 register Lisp_Object tem
, tem2
;
1005 register int foundit
, loading
;
1007 loading
= stream
|| !NARROWED
;
1009 tail
= Vload_history
;
1012 while (!NILP (tail
))
1016 /* Find the feature's previous assoc list... */
1017 if (!NILP (Fequal (source
, Fcar (tem
))))
1021 /* If we're loading, remove it. */
1025 Vload_history
= Fcdr (tail
);
1027 Fsetcdr (prev
, Fcdr (tail
));
1030 /* Otherwise, cons on new symbols that are not already members. */
1033 tem2
= Vcurrent_load_list
;
1035 while (CONSP (tem2
))
1037 newelt
= Fcar (tem2
);
1039 if (NILP (Fmemq (newelt
, tem
)))
1040 Fsetcar (tail
, Fcons (Fcar (tem
),
1041 Fcons (newelt
, Fcdr (tem
))));
1054 /* If we're loading, cons the new assoc onto the front of load-history,
1055 the most-recently-loaded position. Also do this if we didn't find
1056 an existing member for the current source. */
1057 if (loading
|| !foundit
)
1058 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1063 unreadpure () /* Used as unwind-protect function in readevalloop */
1070 readevalloop_1 (old
)
1073 load_convert_to_unibyte
= ! NILP (old
);
1077 /* UNIBYTE specifies how to set load_convert_to_unibyte
1078 for this invocation.
1079 READFUN, if non-nil, is used instead of `read'. */
1082 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
, unibyte
, readfun
)
1083 Lisp_Object readcharfun
;
1085 Lisp_Object sourcename
;
1086 Lisp_Object (*evalfun
) ();
1088 Lisp_Object unibyte
, readfun
;
1091 register Lisp_Object val
;
1092 int count
= specpdl_ptr
- specpdl
;
1093 struct gcpro gcpro1
;
1094 struct buffer
*b
= 0;
1096 if (BUFFERP (readcharfun
))
1097 b
= XBUFFER (readcharfun
);
1098 else if (MARKERP (readcharfun
))
1099 b
= XMARKER (readcharfun
)->buffer
;
1101 specbind (Qstandard_input
, readcharfun
);
1102 specbind (Qcurrent_load_list
, Qnil
);
1103 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1104 load_convert_to_unibyte
= !NILP (unibyte
);
1106 readchar_backlog
= -1;
1108 GCPRO1 (sourcename
);
1110 LOADHIST_ATTACH (sourcename
);
1114 if (b
!= 0 && NILP (b
->name
))
1115 error ("Reading from killed buffer");
1121 while ((c
= READCHAR
) != '\n' && c
!= -1);
1126 /* Ignore whitespace here, so we can detect eof. */
1127 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
1130 if (!NILP (Vpurify_flag
) && c
== '(')
1132 int count1
= specpdl_ptr
- specpdl
;
1133 record_unwind_protect (unreadpure
, Qnil
);
1134 val
= read_list (-1, readcharfun
);
1135 unbind_to (count1
, Qnil
);
1140 read_objects
= Qnil
;
1141 if (! NILP (readfun
))
1142 val
= call1 (readfun
, readcharfun
);
1143 else if (! NILP (Vload_read_function
))
1144 val
= call1 (Vload_read_function
, readcharfun
);
1146 val
= read0 (readcharfun
);
1149 val
= (*evalfun
) (val
);
1152 Vvalues
= Fcons (val
, Vvalues
);
1153 if (EQ (Vstandard_output
, Qt
))
1160 build_load_history (stream
, sourcename
);
1163 unbind_to (count
, Qnil
);
1168 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1169 "Execute the current buffer as Lisp code.\n\
1170 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1171 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1172 PRINTFLAG controls printing of output:\n\
1173 nil means discard it; anything else is stream for print.\n\
1175 If the optional third argument FILENAME is non-nil,\n\
1176 it specifies the file name to use for `load-history'.\n\
1177 The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
1178 for this invocation.\n\
1180 The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
1181 `print' and related functions should work normally even if PRINTFLAG is nil.\n\
1183 This function preserves the position of point.")
1184 (buffer
, printflag
, filename
, unibyte
, do_allow_print
)
1185 Lisp_Object buffer
, printflag
, filename
, unibyte
, do_allow_print
;
1187 int count
= specpdl_ptr
- specpdl
;
1188 Lisp_Object tem
, buf
;
1191 buf
= Fcurrent_buffer ();
1193 buf
= Fget_buffer (buffer
);
1195 error ("No such buffer");
1197 if (NILP (printflag
) && NILP (do_allow_print
))
1202 if (NILP (filename
))
1203 filename
= XBUFFER (buf
)->filename
;
1205 specbind (Qstandard_output
, tem
);
1206 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1207 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1208 readevalloop (buf
, 0, filename
, Feval
, !NILP (printflag
), unibyte
, Qnil
);
1209 unbind_to (count
, Qnil
);
1215 XDEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
1216 "Execute the current buffer as Lisp code.\n\
1217 Programs can pass argument PRINTFLAG which controls printing of output:\n\
1218 nil means discard it; anything else is stream for print.\n\
1220 If there is no error, point does not move. If there is an error,\n\
1221 point remains at the end of the last character read from the buffer.")
1223 Lisp_Object printflag
;
1225 int count
= specpdl_ptr
- specpdl
;
1226 Lisp_Object tem
, cbuf
;
1228 cbuf
= Fcurrent_buffer ()
1230 if (NILP (printflag
))
1234 specbind (Qstandard_output
, tem
);
1235 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1237 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1238 !NILP (printflag
), Qnil
, Qnil
);
1239 return unbind_to (count
, Qnil
);
1243 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1244 "Execute the region as Lisp code.\n\
1245 When called from programs, expects two arguments,\n\
1246 giving starting and ending indices in the current buffer\n\
1247 of the text to be executed.\n\
1248 Programs can pass third argument PRINTFLAG which controls output:\n\
1249 nil means discard it; anything else is stream for printing it.\n\
1250 Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1251 instead of `read' to read each expression. It gets one argument\n\
1252 which is the input stream for reading characters.\n\
1254 This function does not move point.")
1255 (start
, end
, printflag
, read_function
)
1256 Lisp_Object start
, end
, printflag
, read_function
;
1258 int count
= specpdl_ptr
- specpdl
;
1259 Lisp_Object tem
, cbuf
;
1261 cbuf
= Fcurrent_buffer ();
1263 if (NILP (printflag
))
1267 specbind (Qstandard_output
, tem
);
1269 if (NILP (printflag
))
1270 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1271 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1273 /* This both uses start and checks its type. */
1275 Fnarrow_to_region (make_number (BEGV
), end
);
1276 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1277 !NILP (printflag
), Qnil
, read_function
);
1279 return unbind_to (count
, Qnil
);
1282 #endif /* standalone */
1284 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1285 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1286 If STREAM is nil, use the value of `standard-input' (which see).\n\
1287 STREAM or the value of `standard-input' may be:\n\
1288 a buffer (read from point and advance it)\n\
1289 a marker (read from where it points and advance it)\n\
1290 a function (call it with no arguments for each character,\n\
1291 call it with a char as argument to push a char back)\n\
1292 a string (takes text from string, starting at the beginning)\n\
1293 t (read text line using minibuffer and use it).")
1297 extern Lisp_Object
Fread_minibuffer ();
1300 stream
= Vstandard_input
;
1301 if (EQ (stream
, Qt
))
1302 stream
= Qread_char
;
1304 readchar_backlog
= -1;
1305 new_backquote_flag
= 0;
1306 read_objects
= Qnil
;
1309 if (EQ (stream
, Qread_char
))
1310 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1313 if (STRINGP (stream
))
1314 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1316 return read0 (stream
);
1319 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1320 "Read one Lisp expression which is represented as text by STRING.\n\
1321 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1322 START and END optionally delimit a substring of STRING from which to read;\n\
1323 they default to 0 and (length STRING) respectively.")
1324 (string
, start
, end
)
1325 Lisp_Object string
, start
, end
;
1327 int startval
, endval
;
1330 CHECK_STRING (string
,0);
1333 endval
= XSTRING (string
)->size
;
1336 CHECK_NUMBER (end
, 2);
1337 endval
= XINT (end
);
1338 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1339 args_out_of_range (string
, end
);
1346 CHECK_NUMBER (start
, 1);
1347 startval
= XINT (start
);
1348 if (startval
< 0 || startval
> endval
)
1349 args_out_of_range (string
, start
);
1352 read_from_string_index
= startval
;
1353 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1354 read_from_string_limit
= endval
;
1356 new_backquote_flag
= 0;
1357 read_objects
= Qnil
;
1359 tem
= read0 (string
);
1360 return Fcons (tem
, make_number (read_from_string_index
));
1363 /* Use this for recursive reads, in contexts where internal tokens
1368 Lisp_Object readcharfun
;
1370 register Lisp_Object val
;
1373 val
= read1 (readcharfun
, &c
, 0);
1375 Fsignal (Qinvalid_read_syntax
, Fcons (Fmake_string (make_number (1),
1382 static int read_buffer_size
;
1383 static char *read_buffer
;
1385 /* Read multibyte form and return it as a character. C is a first
1386 byte of multibyte form, and rest of them are read from
1390 read_multibyte (c
, readcharfun
)
1392 Lisp_Object readcharfun
;
1394 /* We need the actual character code of this multibyte
1396 unsigned char str
[MAX_LENGTH_OF_MULTI_BYTE_FORM
];
1400 while ((c
= READCHAR
) >= 0xA0
1401 && len
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1404 return STRING_CHAR (str
, len
);
1407 /* Read a \-escape sequence, assuming we already read the `\'. */
1410 read_escape (readcharfun
, stringp
)
1411 Lisp_Object readcharfun
;
1414 register int c
= READCHAR
;
1418 error ("End of file");
1448 error ("Invalid escape character syntax");
1451 c
= read_escape (readcharfun
, 0);
1452 return c
| meta_modifier
;
1457 error ("Invalid escape character syntax");
1460 c
= read_escape (readcharfun
, 0);
1461 return c
| shift_modifier
;
1466 error ("Invalid escape character syntax");
1469 c
= read_escape (readcharfun
, 0);
1470 return c
| hyper_modifier
;
1475 error ("Invalid escape character syntax");
1478 c
= read_escape (readcharfun
, 0);
1479 return c
| alt_modifier
;
1484 error ("Invalid escape character syntax");
1487 c
= read_escape (readcharfun
, 0);
1488 return c
| super_modifier
;
1493 error ("Invalid escape character syntax");
1497 c
= read_escape (readcharfun
, 0);
1498 if ((c
& ~CHAR_MODIFIER_MASK
) == '?')
1499 return 0177 | (c
& CHAR_MODIFIER_MASK
);
1500 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1501 return c
| ctrl_modifier
;
1502 /* ASCII control chars are made from letters (both cases),
1503 as well as the non-letters within 0100...0137. */
1504 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1505 return (c
& (037 | ~0177));
1506 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1507 return (c
& (037 | ~0177));
1509 return c
| ctrl_modifier
;
1519 /* An octal escape, as in ANSI C. */
1521 register int i
= c
- '0';
1522 register int count
= 0;
1525 if ((c
= READCHAR
) >= '0' && c
<= '7')
1540 /* A hex escape, as in ANSI C. */
1546 if (c
>= '0' && c
<= '9')
1551 else if ((c
>= 'a' && c
<= 'f')
1552 || (c
>= 'A' && c
<= 'F'))
1555 if (c
>= 'a' && c
<= 'f')
1570 if (BASE_LEADING_CODE_P (c
))
1571 c
= read_multibyte (c
, readcharfun
);
1576 /* If the next token is ')' or ']' or '.', we store that character
1577 in *PCH and the return value is not interesting. Else, we store
1578 zero in *PCH and we read and return one lisp object.
1580 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1583 read1 (readcharfun
, pch
, first_in_list
)
1584 register Lisp_Object readcharfun
;
1589 int uninterned_symbol
= 0;
1596 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1601 return read_list (0, readcharfun
);
1604 return read_vector (readcharfun
, 0);
1621 tmp
= read_vector (readcharfun
, 0);
1622 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1623 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1624 error ("Invalid size char-table");
1625 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1626 XCHAR_TABLE (tmp
)->top
= Qt
;
1635 tmp
= read_vector (readcharfun
, 0);
1636 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1637 error ("Invalid size char-table");
1638 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1639 XCHAR_TABLE (tmp
)->top
= Qnil
;
1642 Fsignal (Qinvalid_read_syntax
,
1643 Fcons (make_string ("#^^", 3), Qnil
));
1645 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1650 length
= read1 (readcharfun
, pch
, first_in_list
);
1654 Lisp_Object tmp
, val
;
1655 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1659 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1660 if (size_in_chars
!= XSTRING (tmp
)->size
1661 /* We used to print 1 char too many
1662 when the number of bits was a multiple of 8.
1663 Accept such input in case it came from an old version. */
1664 && ! (XFASTINT (length
)
1665 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1666 Fsignal (Qinvalid_read_syntax
,
1667 Fcons (make_string ("#&...", 5), Qnil
));
1669 val
= Fmake_bool_vector (length
, Qnil
);
1670 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1672 /* Clear the extraneous bits in the last byte. */
1673 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1674 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1675 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1678 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1683 /* Accept compiled functions at read-time so that we don't have to
1684 build them using function calls. */
1686 tmp
= read_vector (readcharfun
, 1);
1687 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1688 XVECTOR (tmp
)->contents
);
1690 #ifdef USE_TEXT_PROPERTIES
1694 struct gcpro gcpro1
;
1697 /* Read the string itself. */
1698 tmp
= read1 (readcharfun
, &ch
, 0);
1699 if (ch
!= 0 || !STRINGP (tmp
))
1700 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1702 /* Read the intervals and their properties. */
1705 Lisp_Object beg
, end
, plist
;
1707 beg
= read1 (readcharfun
, &ch
, 0);
1711 end
= read1 (readcharfun
, &ch
, 0);
1713 plist
= read1 (readcharfun
, &ch
, 0);
1715 Fsignal (Qinvalid_read_syntax
,
1716 Fcons (build_string ("invalid string property list"),
1718 Fset_text_properties (beg
, end
, plist
, tmp
);
1724 /* #@NUMBER is used to skip NUMBER following characters.
1725 That's used in .elc files to skip over doc strings
1726 and function definitions. */
1731 /* Read a decimal integer. */
1732 while ((c
= READCHAR
) >= 0
1733 && c
>= '0' && c
<= '9')
1741 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1743 /* If we are supposed to force doc strings into core right now,
1744 record the last string that we skipped,
1745 and record where in the file it comes from. */
1747 /* But first exchange saved_doc_string
1748 with prev_saved_doc_string, so we save two strings. */
1750 char *temp
= saved_doc_string
;
1751 int temp_size
= saved_doc_string_size
;
1752 int temp_pos
= saved_doc_string_position
;
1753 int temp_len
= saved_doc_string_length
;
1755 saved_doc_string
= prev_saved_doc_string
;
1756 saved_doc_string_size
= prev_saved_doc_string_size
;
1757 saved_doc_string_position
= prev_saved_doc_string_position
;
1758 saved_doc_string_length
= prev_saved_doc_string_length
;
1760 prev_saved_doc_string
= temp
;
1761 prev_saved_doc_string_size
= temp_size
;
1762 prev_saved_doc_string_position
= temp_pos
;
1763 prev_saved_doc_string_length
= temp_len
;
1766 if (saved_doc_string_size
== 0)
1768 saved_doc_string_size
= nskip
+ 100;
1769 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1771 if (nskip
> saved_doc_string_size
)
1773 saved_doc_string_size
= nskip
+ 100;
1774 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1775 saved_doc_string_size
);
1778 saved_doc_string_position
= ftell (instream
);
1780 /* Copy that many characters into saved_doc_string. */
1781 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1782 saved_doc_string
[i
] = c
= READCHAR
;
1784 saved_doc_string_length
= i
;
1788 /* Skip that many characters. */
1789 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1796 return Vload_file_name
;
1798 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1799 /* #:foo is the uninterned symbol named foo. */
1802 uninterned_symbol
= 1;
1806 /* Reader forms that can reuse previously read objects. */
1807 if (c
>= '0' && c
<= '9')
1812 /* Read a non-negative integer. */
1813 while (c
>= '0' && c
<= '9')
1819 /* #n=object returns object, but associates it with n for #n#. */
1822 /* Make a placeholder for #n# to use temporarily */
1823 Lisp_Object placeholder
;
1826 placeholder
= Fcons(Qnil
, Qnil
);
1827 cell
= Fcons (make_number (n
), placeholder
);
1828 read_objects
= Fcons (cell
, read_objects
);
1830 /* Read the object itself. */
1831 tem
= read0 (readcharfun
);
1833 /* Now put it everywhere the placeholder was... */
1834 substitute_object_in_subtree (tem
, placeholder
);
1836 /* ...and #n# will use the real value from now on. */
1837 Fsetcdr (cell
, tem
);
1841 /* #n# returns a previously read object. */
1844 tem
= Fassq (make_number (n
), read_objects
);
1847 /* Fall through to error message. */
1849 /* Fall through to error message. */
1853 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1856 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1861 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1871 new_backquote_flag
= 1;
1872 value
= read0 (readcharfun
);
1873 new_backquote_flag
= 0;
1875 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1879 if (new_backquote_flag
)
1881 Lisp_Object comma_type
= Qnil
;
1886 comma_type
= Qcomma_at
;
1888 comma_type
= Qcomma_dot
;
1891 if (ch
>= 0) UNREAD (ch
);
1892 comma_type
= Qcomma
;
1895 new_backquote_flag
= 0;
1896 value
= read0 (readcharfun
);
1897 new_backquote_flag
= 1;
1898 return Fcons (comma_type
, Fcons (value
, Qnil
));
1905 register Lisp_Object val
;
1908 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1911 c
= read_escape (readcharfun
, 0);
1912 else if (BASE_LEADING_CODE_P (c
))
1913 c
= read_multibyte (c
, readcharfun
);
1915 return make_number (c
);
1920 register char *p
= read_buffer
;
1921 register char *end
= read_buffer
+ read_buffer_size
;
1923 /* Nonzero if we saw an escape sequence specifying
1924 a multibyte character. */
1925 int force_multibyte
= 0;
1926 /* Nonzero if we saw an escape sequence specifying
1927 a single-byte character. */
1928 int force_singlebyte
= 0;
1932 while ((c
= READCHAR
) >= 0
1935 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1937 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1938 p
+= new - read_buffer
;
1939 read_buffer
+= new - read_buffer
;
1940 end
= read_buffer
+ read_buffer_size
;
1945 c
= read_escape (readcharfun
, 1);
1947 /* C is -1 if \ newline has just been seen */
1950 if (p
== read_buffer
)
1955 /* If an escape specifies a non-ASCII single-byte character,
1956 this must be a unibyte string. */
1957 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
))
1958 && ! ASCII_BYTE_P ((c
& ~CHAR_MODIFIER_MASK
)))
1959 force_singlebyte
= 1;
1962 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1964 unsigned char workbuf
[4];
1965 unsigned char *str
= workbuf
;
1968 /* Any modifiers for a multibyte character are invalid. */
1969 if (c
& CHAR_MODIFIER_MASK
)
1970 error ("Invalid modifier in string");
1971 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
1973 force_multibyte
= 1;
1975 bcopy (str
, p
, length
);
1980 /* Allow `\C- ' and `\C-?'. */
1981 if (c
== (CHAR_CTL
| ' '))
1983 else if (c
== (CHAR_CTL
| '?'))
1988 /* Shift modifier is valid only with [A-Za-z]. */
1989 if ((c
& 0377) >= 'A' && (c
& 0377) <= 'Z')
1991 else if ((c
& 0377) >= 'a' && (c
& 0377) <= 'z')
1992 c
= (c
& ~CHAR_SHIFT
) - ('a' - 'A');
1996 /* Move the meta bit to the right place for a string. */
1997 c
= (c
& ~CHAR_META
) | 0x80;
1999 error ("Invalid modifier in string");
2004 return Fsignal (Qend_of_file
, Qnil
);
2006 /* If purifying, and string starts with \ newline,
2007 return zero instead. This is for doc strings
2008 that we are really going to find in etc/DOC.nn.nn */
2009 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2010 return make_number (0);
2012 if (force_multibyte
)
2013 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2014 else if (force_singlebyte
)
2015 nchars
= p
- read_buffer
;
2016 else if (load_convert_to_unibyte
)
2019 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2020 if (p
- read_buffer
!= nchars
)
2022 string
= make_multibyte_string (read_buffer
, nchars
,
2024 return Fstring_make_unibyte (string
);
2027 else if (EQ (readcharfun
, Qget_file_char
)
2028 || EQ (readcharfun
, Qlambda
))
2029 /* Nowadays, reading directly from a file
2030 is used only for compiled Emacs Lisp files,
2031 and those always use the Emacs internal encoding.
2032 Meanwhile, Qlambda is used for reading dynamic byte code
2033 (compiled with byte-compile-dynamic = t). */
2034 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2036 /* In all other cases, if we read these bytes as
2037 separate characters, treat them as separate characters now. */
2038 nchars
= p
- read_buffer
;
2041 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2043 || (p
- read_buffer
!= nchars
)));
2044 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2046 || (p
- read_buffer
!= nchars
)));
2051 #ifdef LISP_FLOAT_TYPE
2052 /* If a period is followed by a number, then we should read it
2053 as a floating point number. Otherwise, it denotes a dotted
2055 int next_char
= READCHAR
;
2058 if (! (next_char
>= '0' && next_char
<= '9'))
2065 /* Otherwise, we fall through! Note that the atom-reading loop
2066 below will now loop at least once, assuring that we will not
2067 try to UNREAD two characters in a row. */
2071 if (c
<= 040) goto retry
;
2073 register char *p
= read_buffer
;
2077 register char *end
= read_buffer
+ read_buffer_size
;
2080 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2081 || c
== '(' || c
== ')'
2082 #ifndef LISP_FLOAT_TYPE
2083 /* If we have floating-point support, then we need
2084 to allow <digits><dot><digits>. */
2086 #endif /* not LISP_FLOAT_TYPE */
2087 || c
== '[' || c
== ']' || c
== '#'
2090 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
2092 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2093 p
+= new - read_buffer
;
2094 read_buffer
+= new - read_buffer
;
2095 end
= read_buffer
+ read_buffer_size
;
2103 if (! SINGLE_BYTE_CHAR_P (c
))
2105 unsigned char workbuf
[4];
2106 unsigned char *str
= workbuf
;
2109 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
2111 bcopy (str
, p
, length
);
2122 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2123 p
+= new - read_buffer
;
2124 read_buffer
+= new - read_buffer
;
2125 /* end = read_buffer + read_buffer_size; */
2132 if (!quoted
&& !uninterned_symbol
)
2135 register Lisp_Object val
;
2137 if (*p1
== '+' || *p1
== '-') p1
++;
2138 /* Is it an integer? */
2141 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2142 #ifdef LISP_FLOAT_TYPE
2143 /* Integers can have trailing decimal points. */
2144 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2147 /* It is an integer. */
2149 #ifdef LISP_FLOAT_TYPE
2153 if (sizeof (int) == sizeof (EMACS_INT
))
2154 XSETINT (val
, atoi (read_buffer
));
2155 else if (sizeof (long) == sizeof (EMACS_INT
))
2156 XSETINT (val
, atol (read_buffer
));
2162 #ifdef LISP_FLOAT_TYPE
2163 if (isfloat_string (read_buffer
))
2165 /* Compute NaN and infinities using 0.0 in a variable,
2166 to cope with compilers that think they are smarter
2172 /* Negate the value ourselves. This treats 0, NaNs,
2173 and infinity properly on IEEE floating point hosts,
2174 and works around a common bug where atof ("-0.0")
2176 int negative
= read_buffer
[0] == '-';
2178 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2179 returns 1, is if the input ends in e+INF or e+NaN. */
2186 value
= zero
/ zero
;
2189 value
= atof (read_buffer
+ negative
);
2193 return make_float (negative
? - value
: value
);
2198 if (uninterned_symbol
)
2199 return make_symbol (read_buffer
);
2201 return intern (read_buffer
);
2207 /* List of nodes we've seen during substitute_object_in_subtree. */
2208 static Lisp_Object seen_list
;
2211 substitute_object_in_subtree (object
, placeholder
)
2213 Lisp_Object placeholder
;
2215 Lisp_Object check_object
;
2217 /* We haven't seen any objects when we start. */
2220 /* Make all the substitutions. */
2222 = substitute_object_recurse (object
, placeholder
, object
);
2224 /* Clear seen_list because we're done with it. */
2227 /* The returned object here is expected to always eq the
2229 if (!EQ (check_object
, object
))
2230 error ("Unexpected mutation error in reader");
2233 /* Feval doesn't get called from here, so no gc protection is needed. */
2234 #define SUBSTITUTE(get_val, set_val) \
2236 Lisp_Object old_value = get_val; \
2237 Lisp_Object true_value \
2238 = substitute_object_recurse (object, placeholder,\
2241 if (!EQ (old_value, true_value)) \
2248 substitute_object_recurse (object
, placeholder
, subtree
)
2250 Lisp_Object placeholder
;
2251 Lisp_Object subtree
;
2253 /* If we find the placeholder, return the target object. */
2254 if (EQ (placeholder
, subtree
))
2257 /* If we've been to this node before, don't explore it again. */
2258 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2261 /* If this node can be the entry point to a cycle, remember that
2262 we've seen it. It can only be such an entry point if it was made
2263 by #n=, which means that we can find it as a value in
2265 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2266 seen_list
= Fcons (subtree
, seen_list
);
2268 /* Recurse according to subtree's type.
2269 Every branch must return a Lisp_Object. */
2270 switch (XTYPE (subtree
))
2272 case Lisp_Vectorlike
:
2275 int length
= Flength(subtree
);
2276 for (i
= 0; i
< length
; i
++)
2278 Lisp_Object idx
= make_number (i
);
2279 SUBSTITUTE (Faref (subtree
, idx
),
2280 Faset (subtree
, idx
, true_value
));
2287 SUBSTITUTE (Fcar_safe (subtree
),
2288 Fsetcar (subtree
, true_value
));
2289 SUBSTITUTE (Fcdr_safe (subtree
),
2290 Fsetcdr (subtree
, true_value
));
2294 #ifdef USE_TEXT_PROPERTIES
2297 /* Check for text properties in each interval.
2298 substitute_in_interval contains part of the logic. */
2300 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2301 Lisp_Object arg
= Fcons (object
, placeholder
);
2303 traverse_intervals (root_interval
, 1, 0,
2304 &substitute_in_interval
, arg
);
2308 #endif /* defined USE_TEXT_PROPERTIES */
2310 /* Other types don't recurse any further. */
2316 /* Helper function for substitute_object_recurse. */
2318 substitute_in_interval (interval
, arg
)
2322 Lisp_Object object
= Fcar (arg
);
2323 Lisp_Object placeholder
= Fcdr (arg
);
2325 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2329 #ifdef LISP_FLOAT_TYPE
2346 if (*cp
== '+' || *cp
== '-')
2349 if (*cp
>= '0' && *cp
<= '9')
2352 while (*cp
>= '0' && *cp
<= '9')
2360 if (*cp
>= '0' && *cp
<= '9')
2363 while (*cp
>= '0' && *cp
<= '9')
2366 if (*cp
== 'e' || *cp
== 'E')
2370 if (*cp
== '+' || *cp
== '-')
2374 if (*cp
>= '0' && *cp
<= '9')
2377 while (*cp
>= '0' && *cp
<= '9')
2380 else if (cp
== start
)
2382 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2387 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2393 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2394 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2395 || state
== (DOT_CHAR
|TRAIL_INT
)
2396 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2397 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2398 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2400 #endif /* LISP_FLOAT_TYPE */
2403 read_vector (readcharfun
, bytecodeflag
)
2404 Lisp_Object readcharfun
;
2409 register Lisp_Object
*ptr
;
2410 register Lisp_Object tem
, item
, vector
;
2411 register struct Lisp_Cons
*otem
;
2414 tem
= read_list (1, readcharfun
);
2415 len
= Flength (tem
);
2416 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2418 size
= XVECTOR (vector
)->size
;
2419 ptr
= XVECTOR (vector
)->contents
;
2420 for (i
= 0; i
< size
; i
++)
2423 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2424 bytecode object, the docstring containing the bytecode and
2425 constants values must be treated as unibyte and passed to
2426 Fread, to get the actual bytecode string and constants vector. */
2427 if (bytecodeflag
&& load_force_doc_strings
)
2429 if (i
== COMPILED_BYTECODE
)
2431 if (!STRINGP (item
))
2432 error ("invalid byte code");
2434 /* Delay handling the bytecode slot until we know whether
2435 it is lazily-loaded (we can tell by whether the
2436 constants slot is nil). */
2437 ptr
[COMPILED_CONSTANTS
] = item
;
2440 else if (i
== COMPILED_CONSTANTS
)
2442 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2446 /* Coerce string to unibyte (like string-as-unibyte,
2447 but without generating extra garbage and
2448 guaranteeing no change in the contents). */
2449 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2450 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2452 item
= Fread (bytestr
);
2454 error ("invalid byte code");
2456 otem
= XCONS (item
);
2457 bytestr
= XCAR (item
);
2462 /* Now handle the bytecode slot. */
2463 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2466 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2474 /* FLAG = 1 means check for ] to terminate rather than ) and .
2475 FLAG = -1 means check for starting with defun
2476 and make structure pure. */
2479 read_list (flag
, readcharfun
)
2481 register Lisp_Object readcharfun
;
2483 /* -1 means check next element for defun,
2484 0 means don't check,
2485 1 means already checked and found defun. */
2486 int defunflag
= flag
< 0 ? -1 : 0;
2487 Lisp_Object val
, tail
;
2488 register Lisp_Object elt
, tem
;
2489 struct gcpro gcpro1
, gcpro2
;
2490 /* 0 is the normal case.
2491 1 means this list is a doc reference; replace it with the number 0.
2492 2 means this list is a doc reference; replace it with the doc string. */
2493 int doc_reference
= 0;
2495 /* Initialize this to 1 if we are reading a list. */
2496 int first_in_list
= flag
<= 0;
2505 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2510 /* While building, if the list starts with #$, treat it specially. */
2511 if (EQ (elt
, Vload_file_name
)
2513 && !NILP (Vpurify_flag
))
2515 if (NILP (Vdoc_file_name
))
2516 /* We have not yet called Snarf-documentation, so assume
2517 this file is described in the DOC-MM.NN file
2518 and Snarf-documentation will fill in the right value later.
2519 For now, replace the whole list with 0. */
2522 /* We have already called Snarf-documentation, so make a relative
2523 file name for this file, so it can be found properly
2524 in the installed Lisp directory.
2525 We don't use Fexpand_file_name because that would make
2526 the directory absolute now. */
2527 elt
= concat2 (build_string ("../lisp/"),
2528 Ffile_name_nondirectory (elt
));
2530 else if (EQ (elt
, Vload_file_name
)
2532 && load_force_doc_strings
)
2541 Fsignal (Qinvalid_read_syntax
,
2542 Fcons (make_string (") or . in a vector", 18), Qnil
));
2550 XCDR (tail
) = read0 (readcharfun
);
2552 val
= read0 (readcharfun
);
2553 read1 (readcharfun
, &ch
, 0);
2557 if (doc_reference
== 1)
2558 return make_number (0);
2559 if (doc_reference
== 2)
2561 /* Get a doc string from the file we are loading.
2562 If it's in saved_doc_string, get it from there. */
2563 int pos
= XINT (XCDR (val
));
2564 /* Position is negative for user variables. */
2565 if (pos
< 0) pos
= -pos
;
2566 if (pos
>= saved_doc_string_position
2567 && pos
< (saved_doc_string_position
2568 + saved_doc_string_length
))
2570 int start
= pos
- saved_doc_string_position
;
2573 /* Process quoting with ^A,
2574 and find the end of the string,
2575 which is marked with ^_ (037). */
2576 for (from
= start
, to
= start
;
2577 saved_doc_string
[from
] != 037;)
2579 int c
= saved_doc_string
[from
++];
2582 c
= saved_doc_string
[from
++];
2584 saved_doc_string
[to
++] = c
;
2586 saved_doc_string
[to
++] = 0;
2588 saved_doc_string
[to
++] = 037;
2591 saved_doc_string
[to
++] = c
;
2594 return make_string (saved_doc_string
+ start
,
2597 /* Look in prev_saved_doc_string the same way. */
2598 else if (pos
>= prev_saved_doc_string_position
2599 && pos
< (prev_saved_doc_string_position
2600 + prev_saved_doc_string_length
))
2602 int start
= pos
- prev_saved_doc_string_position
;
2605 /* Process quoting with ^A,
2606 and find the end of the string,
2607 which is marked with ^_ (037). */
2608 for (from
= start
, to
= start
;
2609 prev_saved_doc_string
[from
] != 037;)
2611 int c
= prev_saved_doc_string
[from
++];
2614 c
= prev_saved_doc_string
[from
++];
2616 prev_saved_doc_string
[to
++] = c
;
2618 prev_saved_doc_string
[to
++] = 0;
2620 prev_saved_doc_string
[to
++] = 037;
2623 prev_saved_doc_string
[to
++] = c
;
2626 return make_string (prev_saved_doc_string
+ start
,
2630 return get_doc_string (val
, 0, 0);
2635 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2637 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2639 tem
= (read_pure
&& flag
<= 0
2640 ? pure_cons (elt
, Qnil
)
2641 : Fcons (elt
, Qnil
));
2648 defunflag
= EQ (elt
, Qdefun
);
2649 else if (defunflag
> 0)
2654 Lisp_Object Vobarray
;
2655 Lisp_Object initial_obarray
;
2657 /* oblookup stores the bucket number here, for the sake of Funintern. */
2659 int oblookup_last_bucket_number
;
2661 static int hash_string ();
2662 Lisp_Object
oblookup ();
2664 /* Get an error if OBARRAY is not an obarray.
2665 If it is one, return it. */
2668 check_obarray (obarray
)
2669 Lisp_Object obarray
;
2671 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2673 /* If Vobarray is now invalid, force it to be valid. */
2674 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2676 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2681 /* Intern the C string STR: return a symbol with that name,
2682 interned in the current obarray. */
2689 int len
= strlen (str
);
2690 Lisp_Object obarray
;
2693 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2694 obarray
= check_obarray (obarray
);
2695 tem
= oblookup (obarray
, str
, len
, len
);
2698 return Fintern (make_string (str
, len
), obarray
);
2701 /* Create an uninterned symbol with name STR. */
2707 int len
= strlen (str
);
2709 return Fmake_symbol ((!NILP (Vpurify_flag
)
2710 ? make_pure_string (str
, len
, len
, 0)
2711 : make_string (str
, len
)));
2714 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2715 "Return the canonical symbol whose name is STRING.\n\
2716 If there is none, one is created by this function and returned.\n\
2717 A second optional argument specifies the obarray to use;\n\
2718 it defaults to the value of `obarray'.")
2720 Lisp_Object string
, obarray
;
2722 register Lisp_Object tem
, sym
, *ptr
;
2724 if (NILP (obarray
)) obarray
= Vobarray
;
2725 obarray
= check_obarray (obarray
);
2727 CHECK_STRING (string
, 0);
2729 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2730 XSTRING (string
)->size
,
2731 STRING_BYTES (XSTRING (string
)));
2732 if (!INTEGERP (tem
))
2735 if (!NILP (Vpurify_flag
))
2736 string
= Fpurecopy (string
);
2737 sym
= Fmake_symbol (string
);
2738 XSYMBOL (sym
)->obarray
= obarray
;
2740 if ((XSTRING (string
)->data
[0] == ':')
2741 && EQ (obarray
, initial_obarray
))
2742 XSYMBOL (sym
)->value
= sym
;
2744 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2746 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2748 XSYMBOL (sym
)->next
= 0;
2753 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2754 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
2755 A second optional argument specifies the obarray to use;\n\
2756 it defaults to the value of `obarray'.")
2758 Lisp_Object string
, obarray
;
2760 register Lisp_Object tem
;
2762 if (NILP (obarray
)) obarray
= Vobarray
;
2763 obarray
= check_obarray (obarray
);
2765 CHECK_STRING (string
, 0);
2767 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2768 XSTRING (string
)->size
,
2769 STRING_BYTES (XSTRING (string
)));
2770 if (!INTEGERP (tem
))
2775 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2776 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2777 The value is t if a symbol was found and deleted, nil otherwise.\n\
2778 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2779 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2780 OBARRAY defaults to the value of the variable `obarray'.")
2782 Lisp_Object name
, obarray
;
2784 register Lisp_Object string
, tem
;
2787 if (NILP (obarray
)) obarray
= Vobarray
;
2788 obarray
= check_obarray (obarray
);
2791 XSETSTRING (string
, XSYMBOL (name
)->name
);
2794 CHECK_STRING (name
, 0);
2798 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2799 XSTRING (string
)->size
,
2800 STRING_BYTES (XSTRING (string
)));
2803 /* If arg was a symbol, don't delete anything but that symbol itself. */
2804 if (SYMBOLP (name
) && !EQ (name
, tem
))
2807 XSYMBOL (tem
)->obarray
= Qnil
;
2809 hash
= oblookup_last_bucket_number
;
2811 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2813 if (XSYMBOL (tem
)->next
)
2814 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2816 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2820 Lisp_Object tail
, following
;
2822 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2823 XSYMBOL (tail
)->next
;
2826 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2827 if (EQ (following
, tem
))
2829 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2838 /* Return the symbol in OBARRAY whose names matches the string
2839 of SIZE characters (SIZE_BYTE bytes) at PTR.
2840 If there is no such symbol in OBARRAY, return nil.
2842 Also store the bucket number in oblookup_last_bucket_number. */
2845 oblookup (obarray
, ptr
, size
, size_byte
)
2846 Lisp_Object obarray
;
2848 int size
, size_byte
;
2852 register Lisp_Object tail
;
2853 Lisp_Object bucket
, tem
;
2855 if (!VECTORP (obarray
)
2856 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2858 obarray
= check_obarray (obarray
);
2859 obsize
= XVECTOR (obarray
)->size
;
2861 /* This is sometimes needed in the middle of GC. */
2862 obsize
&= ~ARRAY_MARK_FLAG
;
2863 /* Combining next two lines breaks VMS C 2.3. */
2864 hash
= hash_string (ptr
, size_byte
);
2866 bucket
= XVECTOR (obarray
)->contents
[hash
];
2867 oblookup_last_bucket_number
= hash
;
2868 if (XFASTINT (bucket
) == 0)
2870 else if (!SYMBOLP (bucket
))
2871 error ("Bad data in guts of obarray"); /* Like CADR error message */
2873 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2875 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2876 && XSYMBOL (tail
)->name
->size
== size
2877 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2879 else if (XSYMBOL (tail
)->next
== 0)
2882 XSETINT (tem
, hash
);
2887 hash_string (ptr
, len
)
2891 register unsigned char *p
= ptr
;
2892 register unsigned char *end
= p
+ len
;
2893 register unsigned char c
;
2894 register int hash
= 0;
2899 if (c
>= 0140) c
-= 40;
2900 hash
= ((hash
<<3) + (hash
>>28) + c
);
2902 return hash
& 07777777777;
2906 map_obarray (obarray
, fn
, arg
)
2907 Lisp_Object obarray
;
2908 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2912 register Lisp_Object tail
;
2913 CHECK_VECTOR (obarray
, 1);
2914 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2916 tail
= XVECTOR (obarray
)->contents
[i
];
2921 if (XSYMBOL (tail
)->next
== 0)
2923 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2929 mapatoms_1 (sym
, function
)
2930 Lisp_Object sym
, function
;
2932 call1 (function
, sym
);
2935 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2936 "Call FUNCTION on every symbol in OBARRAY.\n\
2937 OBARRAY defaults to the value of `obarray'.")
2939 Lisp_Object function
, obarray
;
2943 if (NILP (obarray
)) obarray
= Vobarray
;
2944 obarray
= check_obarray (obarray
);
2946 map_obarray (obarray
, mapatoms_1
, function
);
2950 #define OBARRAY_SIZE 1511
2955 Lisp_Object oblength
;
2959 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2961 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2962 Vobarray
= Fmake_vector (oblength
, make_number (0));
2963 initial_obarray
= Vobarray
;
2964 staticpro (&initial_obarray
);
2965 /* Intern nil in the obarray */
2966 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2967 /* These locals are to kludge around a pyramid compiler bug. */
2968 hash
= hash_string ("nil", 3);
2969 /* Separate statement here to avoid VAXC bug. */
2970 hash
%= OBARRAY_SIZE
;
2971 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2974 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2975 XSYMBOL (Qnil
)->function
= Qunbound
;
2976 XSYMBOL (Qunbound
)->value
= Qunbound
;
2977 XSYMBOL (Qunbound
)->function
= Qunbound
;
2980 XSYMBOL (Qnil
)->value
= Qnil
;
2981 XSYMBOL (Qnil
)->plist
= Qnil
;
2982 XSYMBOL (Qt
)->value
= Qt
;
2984 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2987 Qvariable_documentation
= intern ("variable-documentation");
2988 staticpro (&Qvariable_documentation
);
2990 read_buffer_size
= 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM
;
2991 read_buffer
= (char *) malloc (read_buffer_size
);
2996 struct Lisp_Subr
*sname
;
2999 sym
= intern (sname
->symbol_name
);
3000 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3003 #ifdef NOTDEF /* use fset in subr.el now */
3005 defalias (sname
, string
)
3006 struct Lisp_Subr
*sname
;
3010 sym
= intern (string
);
3011 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3015 /* Define an "integer variable"; a symbol whose value is forwarded
3016 to a C variable of type int. Sample call: */
3017 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3019 defvar_int (namestring
, address
)
3023 Lisp_Object sym
, val
;
3024 sym
= intern (namestring
);
3025 val
= allocate_misc ();
3026 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
3027 XINTFWD (val
)->intvar
= address
;
3028 XSYMBOL (sym
)->value
= val
;
3031 /* Similar but define a variable whose value is T if address contains 1,
3032 NIL if address contains 0 */
3034 defvar_bool (namestring
, address
)
3038 Lisp_Object sym
, val
;
3039 sym
= intern (namestring
);
3040 val
= allocate_misc ();
3041 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
3042 XBOOLFWD (val
)->boolvar
= address
;
3043 XSYMBOL (sym
)->value
= val
;
3044 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
3047 /* Similar but define a variable whose value is the Lisp Object stored
3048 at address. Two versions: with and without gc-marking of the C
3049 variable. The nopro version is used when that variable will be
3050 gc-marked for some other reason, since marking the same slot twice
3051 can cause trouble with strings. */
3053 defvar_lisp_nopro (namestring
, address
)
3055 Lisp_Object
*address
;
3057 Lisp_Object sym
, val
;
3058 sym
= intern (namestring
);
3059 val
= allocate_misc ();
3060 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3061 XOBJFWD (val
)->objvar
= address
;
3062 XSYMBOL (sym
)->value
= val
;
3066 defvar_lisp (namestring
, address
)
3068 Lisp_Object
*address
;
3070 defvar_lisp_nopro (namestring
, address
);
3071 staticpro (address
);
3076 /* Similar but define a variable whose value is the Lisp Object stored in
3077 the current buffer. address is the address of the slot in the buffer
3078 that is current now. */
3081 defvar_per_buffer (namestring
, address
, type
, doc
)
3083 Lisp_Object
*address
;
3087 Lisp_Object sym
, val
;
3089 extern struct buffer buffer_local_symbols
;
3091 sym
= intern (namestring
);
3092 val
= allocate_misc ();
3093 offset
= (char *)address
- (char *)current_buffer
;
3095 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3096 XBUFFER_OBJFWD (val
)->offset
= offset
;
3097 XSYMBOL (sym
)->value
= val
;
3098 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
3099 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
3100 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
3101 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3102 slot of buffer_local_flags */
3106 #endif /* standalone */
3108 /* Similar but define a variable whose value is the Lisp Object stored
3109 at a particular offset in the current kboard object. */
3112 defvar_kboard (namestring
, offset
)
3116 Lisp_Object sym
, val
;
3117 sym
= intern (namestring
);
3118 val
= allocate_misc ();
3119 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3120 XKBOARD_OBJFWD (val
)->offset
= offset
;
3121 XSYMBOL (sym
)->value
= val
;
3124 /* Record the value of load-path used at the start of dumping
3125 so we can see if the site changed it later during dumping. */
3126 static Lisp_Object dump_path
;
3132 int turn_off_warning
= 0;
3134 #ifdef HAVE_SETLOCALE
3135 /* Make sure numbers are parsed as we expect. */
3136 setlocale (LC_NUMERIC
, "C");
3137 #endif /* HAVE_SETLOCALE */
3139 /* Compute the default load-path. */
3141 normal
= PATH_LOADSEARCH
;
3142 Vload_path
= decode_env_path (0, normal
);
3144 if (NILP (Vpurify_flag
))
3145 normal
= PATH_LOADSEARCH
;
3147 normal
= PATH_DUMPLOADSEARCH
;
3149 /* In a dumped Emacs, we normally have to reset the value of
3150 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3151 uses ../lisp, instead of the path of the installed elisp
3152 libraries. However, if it appears that Vload_path was changed
3153 from the default before dumping, don't override that value. */
3156 if (! NILP (Fequal (dump_path
, Vload_path
)))
3158 Vload_path
= decode_env_path (0, normal
);
3159 if (!NILP (Vinstallation_directory
))
3161 /* Add to the path the lisp subdir of the
3162 installation dir, if it exists. */
3163 Lisp_Object tem
, tem1
;
3164 tem
= Fexpand_file_name (build_string ("lisp"),
3165 Vinstallation_directory
);
3166 tem1
= Ffile_exists_p (tem
);
3169 if (NILP (Fmember (tem
, Vload_path
)))
3171 turn_off_warning
= 1;
3172 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3176 /* That dir doesn't exist, so add the build-time
3177 Lisp dirs instead. */
3178 Vload_path
= nconc2 (Vload_path
, dump_path
);
3180 /* Add leim under the installation dir, if it exists. */
3181 tem
= Fexpand_file_name (build_string ("leim"),
3182 Vinstallation_directory
);
3183 tem1
= Ffile_exists_p (tem
);
3186 if (NILP (Fmember (tem
, Vload_path
)))
3187 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3190 /* Add site-list under the installation dir, if it exists. */
3191 tem
= Fexpand_file_name (build_string ("site-lisp"),
3192 Vinstallation_directory
);
3193 tem1
= Ffile_exists_p (tem
);
3196 if (NILP (Fmember (tem
, Vload_path
)))
3197 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3200 /* If Emacs was not built in the source directory,
3201 and it is run from where it was built, add to load-path
3202 the lisp, leim and site-lisp dirs under that directory. */
3204 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3208 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3209 Vinstallation_directory
);
3210 tem1
= Ffile_exists_p (tem
);
3212 /* Don't be fooled if they moved the entire source tree
3213 AFTER dumping Emacs. If the build directory is indeed
3214 different from the source dir, src/Makefile.in and
3215 src/Makefile will not be found together. */
3216 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3217 Vinstallation_directory
);
3218 tem2
= Ffile_exists_p (tem
);
3219 if (!NILP (tem1
) && NILP (tem2
))
3221 tem
= Fexpand_file_name (build_string ("lisp"),
3224 if (NILP (Fmember (tem
, Vload_path
)))
3225 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3227 tem
= Fexpand_file_name (build_string ("leim"),
3230 if (NILP (Fmember (tem
, Vload_path
)))
3231 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3233 tem
= Fexpand_file_name (build_string ("site-lisp"),
3236 if (NILP (Fmember (tem
, Vload_path
)))
3237 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3245 /* NORMAL refers to the lisp dir in the source directory. */
3246 /* We used to add ../lisp at the front here, but
3247 that caused trouble because it was copied from dump_path
3248 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3249 It should be unnecessary. */
3250 Vload_path
= decode_env_path (0, normal
);
3251 dump_path
= Vload_path
;
3256 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3257 almost never correct, thereby causing a warning to be printed out that
3258 confuses users. Since PATH_LOADSEARCH is always overridden by the
3259 EMACSLOADPATH environment variable below, disable the warning on NT. */
3261 /* Warn if dirs in the *standard* path don't exist. */
3262 if (!turn_off_warning
)
3264 Lisp_Object path_tail
;
3266 for (path_tail
= Vload_path
;
3268 path_tail
= XCDR (path_tail
))
3270 Lisp_Object dirfile
;
3271 dirfile
= Fcar (path_tail
);
3272 if (STRINGP (dirfile
))
3274 dirfile
= Fdirectory_file_name (dirfile
);
3275 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3276 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3281 #endif /* WINDOWSNT */
3283 /* If the EMACSLOADPATH environment variable is set, use its value.
3284 This doesn't apply if we're dumping. */
3286 if (NILP (Vpurify_flag
)
3287 && egetenv ("EMACSLOADPATH"))
3289 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3293 load_in_progress
= 0;
3294 Vload_file_name
= Qnil
;
3296 load_descriptor_list
= Qnil
;
3298 Vstandard_input
= Qt
;
3301 /* Print a warning, using format string FORMAT, that directory DIRNAME
3302 does not exist. Print it on stderr and put it in *Message*. */
3305 dir_warning (format
, dirname
)
3307 Lisp_Object dirname
;
3310 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3312 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3313 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3314 /* Don't log the warning before we've initialized!! */
3316 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3323 defsubr (&Sread_from_string
);
3325 defsubr (&Sintern_soft
);
3326 defsubr (&Sunintern
);
3328 defsubr (&Seval_buffer
);
3329 defsubr (&Seval_region
);
3330 defsubr (&Sread_char
);
3331 defsubr (&Sread_char_exclusive
);
3332 defsubr (&Sread_event
);
3333 defsubr (&Sget_file_char
);
3334 defsubr (&Smapatoms
);
3336 DEFVAR_LISP ("obarray", &Vobarray
,
3337 "Symbol table for use by `intern' and `read'.\n\
3338 It is a vector whose length ought to be prime for best results.\n\
3339 The vector's contents don't make sense if examined from Lisp programs;\n\
3340 to find all the symbols in an obarray, use `mapatoms'.");
3342 DEFVAR_LISP ("values", &Vvalues
,
3343 "List of values of all expressions which were read, evaluated and printed.\n\
3344 Order is reverse chronological.");
3346 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3347 "Stream for read to get input from.\n\
3348 See documentation of `read' for possible values.");
3349 Vstandard_input
= Qt
;
3351 DEFVAR_LISP ("load-path", &Vload_path
,
3352 "*List of directories to search for files to load.\n\
3353 Each element is a string (directory name) or nil (try default directory).\n\
3354 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3355 otherwise to default specified by file `epaths.h' when Emacs was built.");
3357 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3358 "Non-nil iff inside of `load'.");
3360 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3361 "An alist of expressions to be evalled when particular files are loaded.\n\
3362 Each element looks like (FILENAME FORMS...).\n\
3363 When `load' is run and the file-name argument is FILENAME,\n\
3364 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3365 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3366 with no directory specified, since that is how `load' is normally called.\n\
3367 An error in FORMS does not undo the load,\n\
3368 but does prevent execution of the rest of the FORMS.");
3369 Vafter_load_alist
= Qnil
;
3371 DEFVAR_LISP ("load-history", &Vload_history
,
3372 "Alist mapping source file names to symbols and features.\n\
3373 Each alist element is a list that starts with a file name,\n\
3374 except for one element (optional) that starts with nil and describes\n\
3375 definitions evaluated from buffers not visiting files.\n\
3376 The remaining elements of each list are symbols defined as functions\n\
3377 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3378 Vload_history
= Qnil
;
3380 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3381 "Full name of file being loaded by `load'.");
3382 Vload_file_name
= Qnil
;
3384 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3385 "File name, including directory, of user's initialization file.");
3386 Vuser_init_file
= Qnil
;
3388 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3389 "Used for internal purposes by `load'.");
3390 Vcurrent_load_list
= Qnil
;
3392 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3393 "Function used by `load' and `eval-region' for reading expressions.\n\
3394 The default is nil, which means use the function `read'.");
3395 Vload_read_function
= Qnil
;
3397 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3398 "Function called in `load' for loading an Emacs lisp source file.\n\
3399 This function is for doing code conversion before reading the source file.\n\
3400 If nil, loading is done without any code conversion.\n\
3401 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3402 FULLNAME is the full name of FILE.\n\
3403 See `load' for the meaning of the remaining arguments.");
3404 Vload_source_file_function
= Qnil
;
3406 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3407 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3408 This is useful when the file being loaded is a temporary copy.");
3409 load_force_doc_strings
= 0;
3411 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3412 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3413 This is normally used in `load-with-code-conversion'\n\
3414 for loading non-compiled files.");
3415 load_convert_to_unibyte
= 0;
3417 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3418 "Directory in which Emacs sources were found when Emacs was built.\n\
3419 You cannot count on them to still be there!");
3421 = Fexpand_file_name (build_string ("../"),
3422 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3424 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3425 "List of files that were preloaded (when dumping Emacs).");
3426 Vpreloaded_file_list
= Qnil
;
3428 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars
,
3429 "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
3430 Vbyte_boolean_vars
= Qnil
;
3432 /* Vsource_directory was initialized in init_lread. */
3434 load_descriptor_list
= Qnil
;
3435 staticpro (&load_descriptor_list
);
3437 Qcurrent_load_list
= intern ("current-load-list");
3438 staticpro (&Qcurrent_load_list
);
3440 Qstandard_input
= intern ("standard-input");
3441 staticpro (&Qstandard_input
);
3443 Qread_char
= intern ("read-char");
3444 staticpro (&Qread_char
);
3446 Qget_file_char
= intern ("get-file-char");
3447 staticpro (&Qget_file_char
);
3449 Qbackquote
= intern ("`");
3450 staticpro (&Qbackquote
);
3451 Qcomma
= intern (",");
3452 staticpro (&Qcomma
);
3453 Qcomma_at
= intern (",@");
3454 staticpro (&Qcomma_at
);
3455 Qcomma_dot
= intern (",.");
3456 staticpro (&Qcomma_dot
);
3458 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3459 staticpro (&Qinhibit_file_name_operation
);
3461 Qascii_character
= intern ("ascii-character");
3462 staticpro (&Qascii_character
);
3464 Qfunction
= intern ("function");
3465 staticpro (&Qfunction
);
3467 Qload
= intern ("load");
3470 Qload_file_name
= intern ("load-file-name");
3471 staticpro (&Qload_file_name
);
3473 staticpro (&dump_path
);
3475 staticpro (&read_objects
);
3476 read_objects
= Qnil
;
3477 staticpro (&seen_list
);