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 unsigned char workbuf
[4];
223 unsigned char *str
= workbuf
;
226 /* Fetch the character code from the buffer. */
227 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
228 BUF_INC_POS (inbuffer
, pt_byte
);
229 c
= STRING_CHAR (p
, pt_byte
- orig_pt_byte
);
231 /* Find the byte-sequence representation of that character. */
232 if (SINGLE_BYTE_CHAR_P (c
))
233 length
= 1, workbuf
[0] = c
;
235 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
237 /* If the bytes for this character in the buffer
238 are not identical with what the character code implies,
239 read the bytes one by one from the buffer. */
240 if (length
!= pt_byte
- orig_pt_byte
241 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
243 readchar_backlog
= pt_byte
- orig_pt_byte
;
244 c
= BUF_FETCH_BYTE (inbuffer
, orig_pt_byte
);
250 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
253 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
257 if (MARKERP (readcharfun
))
259 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
261 int bytepos
= marker_byte_position (readcharfun
);
262 int orig_bytepos
= bytepos
;
264 if (readchar_backlog
> 0)
265 /* We get the address of the byte just passed,
266 which is the last byte of the character.
267 The other bytes in this character are consecutive with it,
268 because the gap can't be in the middle of a character. */
269 return *(BUF_BYTE_ADDRESS (inbuffer
, XMARKER (readcharfun
)->bytepos
- 1)
270 - --readchar_backlog
);
272 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
275 readchar_backlog
= -1;
277 if (! NILP (inbuffer
->enable_multibyte_characters
))
279 unsigned char workbuf
[4];
280 unsigned char *str
= workbuf
;
283 /* Fetch the character code from the buffer. */
284 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
285 BUF_INC_POS (inbuffer
, bytepos
);
286 c
= STRING_CHAR (p
, bytepos
- orig_bytepos
);
288 /* Find the byte-sequence representation of that character. */
289 if (SINGLE_BYTE_CHAR_P (c
))
290 length
= 1, workbuf
[0] = c
;
292 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
294 /* If the bytes for this character in the buffer
295 are not identical with what the character code implies,
296 read the bytes one by one from the buffer. */
297 if (length
!= bytepos
- orig_bytepos
298 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
300 readchar_backlog
= bytepos
- orig_bytepos
;
301 c
= BUF_FETCH_BYTE (inbuffer
, orig_bytepos
);
307 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
311 XMARKER (readcharfun
)->bytepos
= bytepos
;
312 XMARKER (readcharfun
)->charpos
++;
317 if (EQ (readcharfun
, Qlambda
))
318 return read_bytecode_char (0);
320 if (EQ (readcharfun
, Qget_file_char
))
324 /* Interrupted reads have been observed while reading over the network */
325 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
334 if (STRINGP (readcharfun
))
336 if (read_from_string_index
>= read_from_string_limit
)
338 else if (STRING_MULTIBYTE (readcharfun
))
339 FETCH_STRING_CHAR_ADVANCE (c
, readcharfun
,
340 read_from_string_index
,
341 read_from_string_index_byte
);
343 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
348 tem
= call0 (readcharfun
);
355 /* Unread the character C in the way appropriate for the stream READCHARFUN.
356 If the stream is a user function, call it with the char as argument. */
359 unreadchar (readcharfun
, c
)
360 Lisp_Object readcharfun
;
364 /* Don't back up the pointer if we're unreading the end-of-input mark,
365 since readchar didn't advance it when we read it. */
367 else if (BUFFERP (readcharfun
))
369 struct buffer
*b
= XBUFFER (readcharfun
);
370 int bytepos
= BUF_PT_BYTE (b
);
372 if (readchar_backlog
>= 0)
377 if (! NILP (b
->enable_multibyte_characters
))
378 BUF_DEC_POS (b
, bytepos
);
382 BUF_PT_BYTE (b
) = bytepos
;
385 else if (MARKERP (readcharfun
))
387 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
388 int bytepos
= XMARKER (readcharfun
)->bytepos
;
390 if (readchar_backlog
>= 0)
394 XMARKER (readcharfun
)->charpos
--;
395 if (! NILP (b
->enable_multibyte_characters
))
396 BUF_DEC_POS (b
, bytepos
);
400 XMARKER (readcharfun
)->bytepos
= bytepos
;
403 else if (STRINGP (readcharfun
))
405 read_from_string_index
--;
406 read_from_string_index_byte
407 = string_char_to_byte (readcharfun
, read_from_string_index
);
409 else if (EQ (readcharfun
, Qlambda
))
410 read_bytecode_char (1);
411 else if (EQ (readcharfun
, Qget_file_char
))
412 ungetc (c
, instream
);
414 call1 (readcharfun
, make_number (c
));
417 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
418 static int read_multibyte ();
419 static Lisp_Object
substitute_object_recurse ();
420 static void substitute_object_in_subtree (), substitute_in_interval ();
423 /* Get a character from the tty. */
425 extern Lisp_Object
read_char ();
427 /* Read input events until we get one that's acceptable for our purposes.
429 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
430 until we get a character we like, and then stuffed into
433 If ASCII_REQUIRED is non-zero, we check function key events to see
434 if the unmodified version of the symbol has a Qascii_character
435 property, and use that character, if present.
437 If ERROR_NONASCII is non-zero, we signal an error if the input we
438 get isn't an ASCII character with modifiers. If it's zero but
439 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
442 If INPUT_METHOD is nonzero, we invoke the current input method
443 if the character warrants that. */
446 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
448 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
451 return make_number (getchar ());
453 register Lisp_Object val
, delayed_switch_frame
;
455 delayed_switch_frame
= Qnil
;
457 /* Read until we get an acceptable event. */
459 val
= read_char (0, 0, 0,
460 (input_method
? Qnil
: Qt
),
466 /* switch-frame events are put off until after the next ASCII
467 character. This is better than signaling an error just because
468 the last characters were typed to a separate minibuffer frame,
469 for example. Eventually, some code which can deal with
470 switch-frame events will read it and process it. */
472 && EVENT_HAS_PARAMETERS (val
)
473 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
475 delayed_switch_frame
= val
;
481 /* Convert certain symbols to their ASCII equivalents. */
484 Lisp_Object tem
, tem1
;
485 tem
= Fget (val
, Qevent_symbol_element_mask
);
488 tem1
= Fget (Fcar (tem
), Qascii_character
);
489 /* Merge this symbol's modifier bits
490 with the ASCII equivalent of its basic code. */
492 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
496 /* If we don't have a character now, deal with it appropriately. */
501 Vunread_command_events
= Fcons (val
, Qnil
);
502 error ("Non-character input-event");
509 if (! NILP (delayed_switch_frame
))
510 unread_switch_frame
= delayed_switch_frame
;
516 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 2, 0,
517 "Read a character from the command input (keyboard or macro).\n\
518 It is returned as a number.\n\
519 If the user generates an event which is not a character (i.e. a mouse\n\
520 click or function key event), `read-char' signals an error. As an\n\
521 exception, switch-frame events are put off until non-ASCII events can\n\
523 If you want to read non-character events, or ignore them, call\n\
524 `read-event' or `read-char-exclusive' instead.\n\
526 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
527 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
528 input method is turned on in the current buffer, that input method\n\
529 is used for reading a character.")
530 (prompt
, inherit_input_method
)
531 Lisp_Object prompt
, inherit_input_method
;
534 message_with_string ("%s", prompt
, 0);
535 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
));
538 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 2, 0,
539 "Read an event object from the input stream.\n\
540 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
541 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
542 input method is turned on in the current buffer, that input method\n\
543 is used for reading a character.")
544 (prompt
, inherit_input_method
)
545 Lisp_Object prompt
, inherit_input_method
;
548 message_with_string ("%s", prompt
, 0);
549 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
));
552 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 2, 0,
553 "Read a character from the command input (keyboard or macro).\n\
554 It is returned as a number. Non-character events are ignored.\n\
556 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
557 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
558 input method is turned on in the current buffer, that input method\n\
559 is used for reading a character.")
560 (prompt
, inherit_input_method
)
561 Lisp_Object prompt
, inherit_input_method
;
564 message_with_string ("%s", prompt
, 0);
565 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
));
568 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
569 "Don't use this yourself.")
572 register Lisp_Object val
;
573 XSETINT (val
, getc (instream
));
577 static void readevalloop ();
578 static Lisp_Object
load_unwind ();
579 static Lisp_Object
load_descriptor_unwind ();
581 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
582 "Execute a file of Lisp code named FILE.\n\
583 First try FILE with `.elc' appended, then try with `.el',\n\
584 then try FILE unmodified.\n\
585 This function searches the directories in `load-path'.\n\
586 If optional second arg NOERROR is non-nil,\n\
587 report no error if FILE doesn't exist.\n\
588 Print messages at start and end of loading unless\n\
589 optional third arg NOMESSAGE is non-nil.\n\
590 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
591 suffixes `.elc' or `.el' to the specified name FILE.\n\
592 If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
593 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
594 it ends in one of those suffixes or includes a directory name.\n\
595 Return t if file exists.")
596 (file
, noerror
, nomessage
, nosuffix
, must_suffix
)
597 Lisp_Object file
, noerror
, nomessage
, nosuffix
, must_suffix
;
599 register FILE *stream
;
600 register int fd
= -1;
601 register Lisp_Object lispstream
;
602 int count
= specpdl_ptr
- specpdl
;
606 /* 1 means we printed the ".el is newer" message. */
608 /* 1 means we are loading a compiled file. */
616 CHECK_STRING (file
, 0);
618 /* If file name is magic, call the handler. */
619 handler
= Ffind_file_name_handler (file
, Qload
);
621 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
623 /* Do this after the handler to avoid
624 the need to gcpro noerror, nomessage and nosuffix.
625 (Below here, we care only whether they are nil or not.) */
626 file
= Fsubstitute_in_file_name (file
);
628 /* Avoid weird lossage with null string as arg,
629 since it would try to load a directory as a Lisp file */
630 if (XSTRING (file
)->size
> 0)
632 int size
= STRING_BYTES (XSTRING (file
));
636 if (! NILP (must_suffix
))
638 /* Don't insist on adding a suffix if FILE already ends with one. */
640 && !strcmp (XSTRING (file
)->data
+ size
- 3, ".el"))
643 && !strcmp (XSTRING (file
)->data
+ size
- 4, ".elc"))
645 /* Don't insist on adding a suffix
646 if the argument includes a directory name. */
647 else if (! NILP (Ffile_name_directory (file
)))
651 fd
= openp (Vload_path
, file
,
652 (!NILP (nosuffix
) ? ""
653 : ! NILP (must_suffix
) ? ".elc:.el"
663 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
664 Fcons (file
, Qnil
)));
669 if (EQ (Qt
, Vuser_init_file
))
670 Vuser_init_file
= found
;
672 /* If FD is 0, that means openp found a magic file. */
675 if (NILP (Fequal (found
, file
)))
676 /* If FOUND is a different file name from FILE,
677 find its handler even if we have already inhibited
678 the `load' operation on FILE. */
679 handler
= Ffind_file_name_handler (found
, Qt
);
681 handler
= Ffind_file_name_handler (found
, Qload
);
682 if (! NILP (handler
))
683 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
686 /* Load .elc files directly, but not when they are
687 remote and have no handler! */
688 if (!bcmp (&(XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 4]),
700 stat ((char *)XSTRING (found
)->data
, &s1
);
701 XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 1] = 0;
702 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
703 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
705 /* Make the progress messages mention that source is newer. */
708 /* If we won't print another message, mention this anyway. */
709 if (! NILP (nomessage
))
710 message_with_string ("Source file `%s' newer than byte-compiled file",
713 XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 1] = 'c';
717 /* We are loading a source file (*.el). */
718 if (!NILP (Vload_source_file_function
))
722 return call4 (Vload_source_file_function
, found
, file
,
723 NILP (noerror
) ? Qnil
: Qt
,
724 NILP (nomessage
) ? Qnil
: Qt
);
730 stream
= fopen ((char *) XSTRING (found
)->data
, fmode
);
731 #else /* not WINDOWSNT */
732 stream
= fdopen (fd
, fmode
);
733 #endif /* not WINDOWSNT */
737 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
740 if (! NILP (Vpurify_flag
))
741 Vpreloaded_file_list
= Fcons (file
, Vpreloaded_file_list
);
743 if (NILP (nomessage
))
746 message_with_string ("Loading %s (source)...", file
, 1);
748 message_with_string ("Loading %s (compiled; note, source file is newer)...",
750 else /* The typical case; compiled file newer than source file. */
751 message_with_string ("Loading %s...", file
, 1);
755 lispstream
= Fcons (Qnil
, Qnil
);
756 XSETFASTINT (XCAR (lispstream
), (EMACS_UINT
)stream
>> 16);
757 XSETFASTINT (XCDR (lispstream
), (EMACS_UINT
)stream
& 0xffff);
758 record_unwind_protect (load_unwind
, lispstream
);
759 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
760 specbind (Qload_file_name
, found
);
761 specbind (Qinhibit_file_name_operation
, Qnil
);
763 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
765 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0, Qnil
, Qnil
);
766 unbind_to (count
, Qnil
);
768 /* Run any load-hooks for this file. */
769 temp
= Fassoc (file
, Vafter_load_alist
);
771 Fprogn (Fcdr (temp
));
774 if (saved_doc_string
)
775 free (saved_doc_string
);
776 saved_doc_string
= 0;
777 saved_doc_string_size
= 0;
779 if (prev_saved_doc_string
)
780 free (prev_saved_doc_string
);
781 prev_saved_doc_string
= 0;
782 prev_saved_doc_string_size
= 0;
784 if (!noninteractive
&& NILP (nomessage
))
787 message_with_string ("Loading %s (source)...done", file
, 1);
789 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
791 else /* The typical case; compiled file newer than source file. */
792 message_with_string ("Loading %s...done", file
, 1);
798 load_unwind (stream
) /* used as unwind-protect function in load */
801 fclose ((FILE *) (XFASTINT (XCAR (stream
)) << 16
802 | XFASTINT (XCDR (stream
))));
803 if (--load_in_progress
< 0) load_in_progress
= 0;
808 load_descriptor_unwind (oldlist
)
811 load_descriptor_list
= oldlist
;
815 /* Close all descriptors in use for Floads.
816 This is used when starting a subprocess. */
823 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCDR (tail
))
824 emacs_close (XFASTINT (XCAR (tail
)));
829 complete_filename_p (pathname
)
830 Lisp_Object pathname
;
832 register unsigned char *s
= XSTRING (pathname
)->data
;
833 return (IS_DIRECTORY_SEP (s
[0])
834 || (XSTRING (pathname
)->size
> 2
835 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
845 /* Search for a file whose name is STR, looking in directories
846 in the Lisp list PATH, and trying suffixes from SUFFIX.
847 SUFFIX is a string containing possible suffixes separated by colons.
848 On success, returns a file descriptor. On failure, returns -1.
850 EXEC_ONLY nonzero means don't open the files,
851 just look for one that is executable. In this case,
852 returns 1 on success.
854 If STOREPTR is nonzero, it points to a slot where the name of
855 the file actually found should be stored as a Lisp string.
856 nil is stored there on failure.
858 If the file we find is remote, return 0
859 but store the found remote file name in *STOREPTR.
860 We do not check for remote files if EXEC_ONLY is nonzero. */
863 openp (path
, str
, suffix
, storeptr
, exec_only
)
864 Lisp_Object path
, str
;
866 Lisp_Object
*storeptr
;
872 register char *fn
= buf
;
875 Lisp_Object filename
;
883 if (complete_filename_p (str
))
886 for (; !NILP (path
); path
= Fcdr (path
))
890 filename
= Fexpand_file_name (str
, Fcar (path
));
891 if (!complete_filename_p (filename
))
892 /* If there are non-absolute elts in PATH (eg ".") */
893 /* Of course, this could conceivably lose if luser sets
894 default-directory to be something non-absolute... */
896 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
897 if (!complete_filename_p (filename
))
898 /* Give up on this path element! */
902 /* Calculate maximum size of any filename made from
903 this path element/specified file name and any possible suffix. */
904 want_size
= strlen (suffix
) + STRING_BYTES (XSTRING (filename
)) + 1;
905 if (fn_size
< want_size
)
906 fn
= (char *) alloca (fn_size
= 100 + want_size
);
910 /* Loop over suffixes. */
913 char *esuffix
= (char *) index (nsuffix
, ':');
914 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
917 /* Concatenate path element/specified name with the suffix.
918 If the directory starts with /:, remove that. */
919 if (XSTRING (filename
)->size
> 2
920 && XSTRING (filename
)->data
[0] == '/'
921 && XSTRING (filename
)->data
[1] == ':')
923 strncpy (fn
, XSTRING (filename
)->data
+ 2,
924 STRING_BYTES (XSTRING (filename
)) - 2);
925 fn
[STRING_BYTES (XSTRING (filename
)) - 2] = 0;
929 strncpy (fn
, XSTRING (filename
)->data
,
930 STRING_BYTES (XSTRING (filename
)));
931 fn
[STRING_BYTES (XSTRING (filename
))] = 0;
934 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
935 strncat (fn
, nsuffix
, lsuffix
);
937 /* Check that the file exists and is not a directory. */
941 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
942 if (! NILP (handler
) && ! exec_only
)
947 string
= build_string (fn
);
948 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
949 : Ffile_readable_p (string
));
951 && ! NILP (Ffile_directory_p (build_string (fn
))))
956 /* We succeeded; return this descriptor and filename. */
958 *storeptr
= build_string (fn
);
965 int exists
= (stat (fn
, &st
) >= 0
966 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
969 /* Check that we can access or open it. */
971 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
973 fd
= emacs_open (fn
, O_RDONLY
, 0);
977 /* We succeeded; return this descriptor and filename. */
979 *storeptr
= build_string (fn
);
986 /* Advance to next suffix. */
989 nsuffix
+= lsuffix
+ 1;
1000 /* Merge the list we've accumulated of globals from the current input source
1001 into the load_history variable. The details depend on whether
1002 the source has an associated file name or not. */
1005 build_load_history (stream
, source
)
1009 register Lisp_Object tail
, prev
, newelt
;
1010 register Lisp_Object tem
, tem2
;
1011 register int foundit
, loading
;
1013 loading
= stream
|| !NARROWED
;
1015 tail
= Vload_history
;
1018 while (!NILP (tail
))
1022 /* Find the feature's previous assoc list... */
1023 if (!NILP (Fequal (source
, Fcar (tem
))))
1027 /* If we're loading, remove it. */
1031 Vload_history
= Fcdr (tail
);
1033 Fsetcdr (prev
, Fcdr (tail
));
1036 /* Otherwise, cons on new symbols that are not already members. */
1039 tem2
= Vcurrent_load_list
;
1041 while (CONSP (tem2
))
1043 newelt
= Fcar (tem2
);
1045 if (NILP (Fmemq (newelt
, tem
)))
1046 Fsetcar (tail
, Fcons (Fcar (tem
),
1047 Fcons (newelt
, Fcdr (tem
))));
1060 /* If we're loading, cons the new assoc onto the front of load-history,
1061 the most-recently-loaded position. Also do this if we didn't find
1062 an existing member for the current source. */
1063 if (loading
|| !foundit
)
1064 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1069 unreadpure () /* Used as unwind-protect function in readevalloop */
1076 readevalloop_1 (old
)
1079 load_convert_to_unibyte
= ! NILP (old
);
1083 /* UNIBYTE specifies how to set load_convert_to_unibyte
1084 for this invocation.
1085 READFUN, if non-nil, is used instead of `read'. */
1088 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
, unibyte
, readfun
)
1089 Lisp_Object readcharfun
;
1091 Lisp_Object sourcename
;
1092 Lisp_Object (*evalfun
) ();
1094 Lisp_Object unibyte
, readfun
;
1097 register Lisp_Object val
;
1098 int count
= specpdl_ptr
- specpdl
;
1099 struct gcpro gcpro1
;
1100 struct buffer
*b
= 0;
1102 if (BUFFERP (readcharfun
))
1103 b
= XBUFFER (readcharfun
);
1104 else if (MARKERP (readcharfun
))
1105 b
= XMARKER (readcharfun
)->buffer
;
1107 specbind (Qstandard_input
, readcharfun
);
1108 specbind (Qcurrent_load_list
, Qnil
);
1109 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1110 load_convert_to_unibyte
= !NILP (unibyte
);
1112 readchar_backlog
= -1;
1114 GCPRO1 (sourcename
);
1116 LOADHIST_ATTACH (sourcename
);
1120 if (b
!= 0 && NILP (b
->name
))
1121 error ("Reading from killed buffer");
1127 while ((c
= READCHAR
) != '\n' && c
!= -1);
1132 /* Ignore whitespace here, so we can detect eof. */
1133 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
1136 if (!NILP (Vpurify_flag
) && c
== '(')
1138 int count1
= specpdl_ptr
- specpdl
;
1139 record_unwind_protect (unreadpure
, Qnil
);
1140 val
= read_list (-1, readcharfun
);
1141 unbind_to (count1
, Qnil
);
1146 read_objects
= Qnil
;
1147 if (! NILP (readfun
))
1148 val
= call1 (readfun
, readcharfun
);
1149 else if (! NILP (Vload_read_function
))
1150 val
= call1 (Vload_read_function
, readcharfun
);
1152 val
= read0 (readcharfun
);
1155 val
= (*evalfun
) (val
);
1158 Vvalues
= Fcons (val
, Vvalues
);
1159 if (EQ (Vstandard_output
, Qt
))
1166 build_load_history (stream
, sourcename
);
1169 unbind_to (count
, Qnil
);
1174 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1175 "Execute the current buffer as Lisp code.\n\
1176 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1177 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1178 PRINTFLAG controls printing of output:\n\
1179 nil means discard it; anything else is stream for print.\n\
1181 If the optional third argument FILENAME is non-nil,\n\
1182 it specifies the file name to use for `load-history'.\n\
1183 The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
1184 for this invocation.\n\
1186 The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
1187 `print' and related functions should work normally even if PRINTFLAG is nil.\n\
1189 This function preserves the position of point.")
1190 (buffer
, printflag
, filename
, unibyte
, do_allow_print
)
1191 Lisp_Object buffer
, printflag
, filename
, unibyte
, do_allow_print
;
1193 int count
= specpdl_ptr
- specpdl
;
1194 Lisp_Object tem
, buf
;
1197 buf
= Fcurrent_buffer ();
1199 buf
= Fget_buffer (buffer
);
1201 error ("No such buffer");
1203 if (NILP (printflag
) && NILP (do_allow_print
))
1208 if (NILP (filename
))
1209 filename
= XBUFFER (buf
)->filename
;
1211 specbind (Qstandard_output
, tem
);
1212 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1213 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1214 readevalloop (buf
, 0, filename
, Feval
, !NILP (printflag
), unibyte
, Qnil
);
1215 unbind_to (count
, Qnil
);
1221 XDEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
1222 "Execute the current buffer as Lisp code.\n\
1223 Programs can pass argument PRINTFLAG which controls printing of output:\n\
1224 nil means discard it; anything else is stream for print.\n\
1226 If there is no error, point does not move. If there is an error,\n\
1227 point remains at the end of the last character read from the buffer.")
1229 Lisp_Object printflag
;
1231 int count
= specpdl_ptr
- specpdl
;
1232 Lisp_Object tem
, cbuf
;
1234 cbuf
= Fcurrent_buffer ()
1236 if (NILP (printflag
))
1240 specbind (Qstandard_output
, tem
);
1241 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1243 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1244 !NILP (printflag
), Qnil
, Qnil
);
1245 return unbind_to (count
, Qnil
);
1249 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1250 "Execute the region as Lisp code.\n\
1251 When called from programs, expects two arguments,\n\
1252 giving starting and ending indices in the current buffer\n\
1253 of the text to be executed.\n\
1254 Programs can pass third argument PRINTFLAG which controls output:\n\
1255 nil means discard it; anything else is stream for printing it.\n\
1256 Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1257 instead of `read' to read each expression. It gets one argument\n\
1258 which is the input stream for reading characters.\n\
1260 This function does not move point.")
1261 (start
, end
, printflag
, read_function
)
1262 Lisp_Object start
, end
, printflag
, read_function
;
1264 int count
= specpdl_ptr
- specpdl
;
1265 Lisp_Object tem
, cbuf
;
1267 cbuf
= Fcurrent_buffer ();
1269 if (NILP (printflag
))
1273 specbind (Qstandard_output
, tem
);
1275 if (NILP (printflag
))
1276 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1277 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1279 /* This both uses start and checks its type. */
1281 Fnarrow_to_region (make_number (BEGV
), end
);
1282 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1283 !NILP (printflag
), Qnil
, read_function
);
1285 return unbind_to (count
, Qnil
);
1288 #endif /* standalone */
1290 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1291 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1292 If STREAM is nil, use the value of `standard-input' (which see).\n\
1293 STREAM or the value of `standard-input' may be:\n\
1294 a buffer (read from point and advance it)\n\
1295 a marker (read from where it points and advance it)\n\
1296 a function (call it with no arguments for each character,\n\
1297 call it with a char as argument to push a char back)\n\
1298 a string (takes text from string, starting at the beginning)\n\
1299 t (read text line using minibuffer and use it).")
1303 extern Lisp_Object
Fread_minibuffer ();
1306 stream
= Vstandard_input
;
1307 if (EQ (stream
, Qt
))
1308 stream
= Qread_char
;
1310 readchar_backlog
= -1;
1311 new_backquote_flag
= 0;
1312 read_objects
= Qnil
;
1315 if (EQ (stream
, Qread_char
))
1316 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1319 if (STRINGP (stream
))
1320 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1322 return read0 (stream
);
1325 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1326 "Read one Lisp expression which is represented as text by STRING.\n\
1327 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1328 START and END optionally delimit a substring of STRING from which to read;\n\
1329 they default to 0 and (length STRING) respectively.")
1330 (string
, start
, end
)
1331 Lisp_Object string
, start
, end
;
1333 int startval
, endval
;
1336 CHECK_STRING (string
,0);
1339 endval
= XSTRING (string
)->size
;
1342 CHECK_NUMBER (end
, 2);
1343 endval
= XINT (end
);
1344 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1345 args_out_of_range (string
, end
);
1352 CHECK_NUMBER (start
, 1);
1353 startval
= XINT (start
);
1354 if (startval
< 0 || startval
> endval
)
1355 args_out_of_range (string
, start
);
1358 read_from_string_index
= startval
;
1359 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1360 read_from_string_limit
= endval
;
1362 new_backquote_flag
= 0;
1363 read_objects
= Qnil
;
1365 tem
= read0 (string
);
1366 return Fcons (tem
, make_number (read_from_string_index
));
1369 /* Use this for recursive reads, in contexts where internal tokens
1374 Lisp_Object readcharfun
;
1376 register Lisp_Object val
;
1379 val
= read1 (readcharfun
, &c
, 0);
1381 Fsignal (Qinvalid_read_syntax
, Fcons (Fmake_string (make_number (1),
1388 static int read_buffer_size
;
1389 static char *read_buffer
;
1391 /* Read multibyte form and return it as a character. C is a first
1392 byte of multibyte form, and rest of them are read from
1396 read_multibyte (c
, readcharfun
)
1398 Lisp_Object readcharfun
;
1400 /* We need the actual character code of this multibyte
1402 unsigned char str
[MAX_LENGTH_OF_MULTI_BYTE_FORM
];
1406 while ((c
= READCHAR
) >= 0xA0
1407 && len
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1410 return STRING_CHAR (str
, len
);
1413 /* Read a \-escape sequence, assuming we already read the `\'. */
1416 read_escape (readcharfun
, stringp
)
1417 Lisp_Object readcharfun
;
1420 register int c
= READCHAR
;
1424 error ("End of file");
1454 error ("Invalid escape character syntax");
1457 c
= read_escape (readcharfun
, 0);
1458 return c
| meta_modifier
;
1463 error ("Invalid escape character syntax");
1466 c
= read_escape (readcharfun
, 0);
1467 return c
| shift_modifier
;
1472 error ("Invalid escape character syntax");
1475 c
= read_escape (readcharfun
, 0);
1476 return c
| hyper_modifier
;
1481 error ("Invalid escape character syntax");
1484 c
= read_escape (readcharfun
, 0);
1485 return c
| alt_modifier
;
1490 error ("Invalid escape character syntax");
1493 c
= read_escape (readcharfun
, 0);
1494 return c
| super_modifier
;
1499 error ("Invalid escape character syntax");
1503 c
= read_escape (readcharfun
, 0);
1504 if ((c
& ~CHAR_MODIFIER_MASK
) == '?')
1505 return 0177 | (c
& CHAR_MODIFIER_MASK
);
1506 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1507 return c
| ctrl_modifier
;
1508 /* ASCII control chars are made from letters (both cases),
1509 as well as the non-letters within 0100...0137. */
1510 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1511 return (c
& (037 | ~0177));
1512 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1513 return (c
& (037 | ~0177));
1515 return c
| ctrl_modifier
;
1525 /* An octal escape, as in ANSI C. */
1527 register int i
= c
- '0';
1528 register int count
= 0;
1531 if ((c
= READCHAR
) >= '0' && c
<= '7')
1546 /* A hex escape, as in ANSI C. */
1552 if (c
>= '0' && c
<= '9')
1557 else if ((c
>= 'a' && c
<= 'f')
1558 || (c
>= 'A' && c
<= 'F'))
1561 if (c
>= 'a' && c
<= 'f')
1576 if (BASE_LEADING_CODE_P (c
))
1577 c
= read_multibyte (c
, readcharfun
);
1582 /* If the next token is ')' or ']' or '.', we store that character
1583 in *PCH and the return value is not interesting. Else, we store
1584 zero in *PCH and we read and return one lisp object.
1586 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1589 read1 (readcharfun
, pch
, first_in_list
)
1590 register Lisp_Object readcharfun
;
1595 int uninterned_symbol
= 0;
1602 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1607 return read_list (0, readcharfun
);
1610 return read_vector (readcharfun
, 0);
1627 tmp
= read_vector (readcharfun
, 0);
1628 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1629 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1630 error ("Invalid size char-table");
1631 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1632 XCHAR_TABLE (tmp
)->top
= Qt
;
1641 tmp
= read_vector (readcharfun
, 0);
1642 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1643 error ("Invalid size char-table");
1644 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1645 XCHAR_TABLE (tmp
)->top
= Qnil
;
1648 Fsignal (Qinvalid_read_syntax
,
1649 Fcons (make_string ("#^^", 3), Qnil
));
1651 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1656 length
= read1 (readcharfun
, pch
, first_in_list
);
1660 Lisp_Object tmp
, val
;
1661 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1665 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1666 if (size_in_chars
!= XSTRING (tmp
)->size
1667 /* We used to print 1 char too many
1668 when the number of bits was a multiple of 8.
1669 Accept such input in case it came from an old version. */
1670 && ! (XFASTINT (length
)
1671 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1672 Fsignal (Qinvalid_read_syntax
,
1673 Fcons (make_string ("#&...", 5), Qnil
));
1675 val
= Fmake_bool_vector (length
, Qnil
);
1676 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1678 /* Clear the extraneous bits in the last byte. */
1679 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1680 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1681 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1684 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1689 /* Accept compiled functions at read-time so that we don't have to
1690 build them using function calls. */
1692 tmp
= read_vector (readcharfun
, 1);
1693 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1694 XVECTOR (tmp
)->contents
);
1696 #ifdef USE_TEXT_PROPERTIES
1700 struct gcpro gcpro1
;
1703 /* Read the string itself. */
1704 tmp
= read1 (readcharfun
, &ch
, 0);
1705 if (ch
!= 0 || !STRINGP (tmp
))
1706 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1708 /* Read the intervals and their properties. */
1711 Lisp_Object beg
, end
, plist
;
1713 beg
= read1 (readcharfun
, &ch
, 0);
1717 end
= read1 (readcharfun
, &ch
, 0);
1719 plist
= read1 (readcharfun
, &ch
, 0);
1721 Fsignal (Qinvalid_read_syntax
,
1722 Fcons (build_string ("invalid string property list"),
1724 Fset_text_properties (beg
, end
, plist
, tmp
);
1730 /* #@NUMBER is used to skip NUMBER following characters.
1731 That's used in .elc files to skip over doc strings
1732 and function definitions. */
1737 /* Read a decimal integer. */
1738 while ((c
= READCHAR
) >= 0
1739 && c
>= '0' && c
<= '9')
1747 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1749 /* If we are supposed to force doc strings into core right now,
1750 record the last string that we skipped,
1751 and record where in the file it comes from. */
1753 /* But first exchange saved_doc_string
1754 with prev_saved_doc_string, so we save two strings. */
1756 char *temp
= saved_doc_string
;
1757 int temp_size
= saved_doc_string_size
;
1758 file_offset temp_pos
= saved_doc_string_position
;
1759 int temp_len
= saved_doc_string_length
;
1761 saved_doc_string
= prev_saved_doc_string
;
1762 saved_doc_string_size
= prev_saved_doc_string_size
;
1763 saved_doc_string_position
= prev_saved_doc_string_position
;
1764 saved_doc_string_length
= prev_saved_doc_string_length
;
1766 prev_saved_doc_string
= temp
;
1767 prev_saved_doc_string_size
= temp_size
;
1768 prev_saved_doc_string_position
= temp_pos
;
1769 prev_saved_doc_string_length
= temp_len
;
1772 if (saved_doc_string_size
== 0)
1774 saved_doc_string_size
= nskip
+ 100;
1775 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1777 if (nskip
> saved_doc_string_size
)
1779 saved_doc_string_size
= nskip
+ 100;
1780 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1781 saved_doc_string_size
);
1784 saved_doc_string_position
= file_tell (instream
);
1786 /* Copy that many characters into saved_doc_string. */
1787 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1788 saved_doc_string
[i
] = c
= READCHAR
;
1790 saved_doc_string_length
= i
;
1794 /* Skip that many characters. */
1795 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1802 return Vload_file_name
;
1804 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1805 /* #:foo is the uninterned symbol named foo. */
1808 uninterned_symbol
= 1;
1812 /* Reader forms that can reuse previously read objects. */
1813 if (c
>= '0' && c
<= '9')
1818 /* Read a non-negative integer. */
1819 while (c
>= '0' && c
<= '9')
1825 /* #n=object returns object, but associates it with n for #n#. */
1828 /* Make a placeholder for #n# to use temporarily */
1829 Lisp_Object placeholder
;
1832 placeholder
= Fcons(Qnil
, Qnil
);
1833 cell
= Fcons (make_number (n
), placeholder
);
1834 read_objects
= Fcons (cell
, read_objects
);
1836 /* Read the object itself. */
1837 tem
= read0 (readcharfun
);
1839 /* Now put it everywhere the placeholder was... */
1840 substitute_object_in_subtree (tem
, placeholder
);
1842 /* ...and #n# will use the real value from now on. */
1843 Fsetcdr (cell
, tem
);
1847 /* #n# returns a previously read object. */
1850 tem
= Fassq (make_number (n
), read_objects
);
1853 /* Fall through to error message. */
1855 /* Fall through to error message. */
1859 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1862 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1867 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1877 new_backquote_flag
= 1;
1878 value
= read0 (readcharfun
);
1879 new_backquote_flag
= 0;
1881 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1885 if (new_backquote_flag
)
1887 Lisp_Object comma_type
= Qnil
;
1892 comma_type
= Qcomma_at
;
1894 comma_type
= Qcomma_dot
;
1897 if (ch
>= 0) UNREAD (ch
);
1898 comma_type
= Qcomma
;
1901 new_backquote_flag
= 0;
1902 value
= read0 (readcharfun
);
1903 new_backquote_flag
= 1;
1904 return Fcons (comma_type
, Fcons (value
, Qnil
));
1912 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1915 c
= read_escape (readcharfun
, 0);
1916 else if (BASE_LEADING_CODE_P (c
))
1917 c
= read_multibyte (c
, readcharfun
);
1919 return make_number (c
);
1924 register char *p
= read_buffer
;
1925 register char *end
= read_buffer
+ read_buffer_size
;
1927 /* Nonzero if we saw an escape sequence specifying
1928 a multibyte character. */
1929 int force_multibyte
= 0;
1930 /* Nonzero if we saw an escape sequence specifying
1931 a single-byte character. */
1932 int force_singlebyte
= 0;
1936 while ((c
= READCHAR
) >= 0
1939 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1941 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1942 p
+= new - read_buffer
;
1943 read_buffer
+= new - read_buffer
;
1944 end
= read_buffer
+ read_buffer_size
;
1949 c
= read_escape (readcharfun
, 1);
1951 /* C is -1 if \ newline has just been seen */
1954 if (p
== read_buffer
)
1959 /* If an escape specifies a non-ASCII single-byte character,
1960 this must be a unibyte string. */
1961 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
))
1962 && ! ASCII_BYTE_P ((c
& ~CHAR_MODIFIER_MASK
)))
1963 force_singlebyte
= 1;
1966 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1968 unsigned char workbuf
[4];
1969 unsigned char *str
= workbuf
;
1972 /* Any modifiers for a multibyte character are invalid. */
1973 if (c
& CHAR_MODIFIER_MASK
)
1974 error ("Invalid modifier in string");
1975 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
1977 force_multibyte
= 1;
1979 bcopy (str
, p
, length
);
1984 /* Allow `\C- ' and `\C-?'. */
1985 if (c
== (CHAR_CTL
| ' '))
1987 else if (c
== (CHAR_CTL
| '?'))
1992 /* Shift modifier is valid only with [A-Za-z]. */
1993 if ((c
& 0377) >= 'A' && (c
& 0377) <= 'Z')
1995 else if ((c
& 0377) >= 'a' && (c
& 0377) <= 'z')
1996 c
= (c
& ~CHAR_SHIFT
) - ('a' - 'A');
2000 /* Move the meta bit to the right place for a string. */
2001 c
= (c
& ~CHAR_META
) | 0x80;
2003 error ("Invalid modifier in string");
2008 return Fsignal (Qend_of_file
, Qnil
);
2010 /* If purifying, and string starts with \ newline,
2011 return zero instead. This is for doc strings
2012 that we are really going to find in etc/DOC.nn.nn */
2013 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2014 return make_number (0);
2016 if (force_multibyte
)
2017 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2018 else if (force_singlebyte
)
2019 nchars
= p
- read_buffer
;
2020 else if (load_convert_to_unibyte
)
2023 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2024 if (p
- read_buffer
!= nchars
)
2026 string
= make_multibyte_string (read_buffer
, nchars
,
2028 return Fstring_make_unibyte (string
);
2031 else if (EQ (readcharfun
, Qget_file_char
)
2032 || EQ (readcharfun
, Qlambda
))
2033 /* Nowadays, reading directly from a file
2034 is used only for compiled Emacs Lisp files,
2035 and those always use the Emacs internal encoding.
2036 Meanwhile, Qlambda is used for reading dynamic byte code
2037 (compiled with byte-compile-dynamic = t). */
2038 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2040 /* In all other cases, if we read these bytes as
2041 separate characters, treat them as separate characters now. */
2042 nchars
= p
- read_buffer
;
2045 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2047 || (p
- read_buffer
!= nchars
)));
2048 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2050 || (p
- read_buffer
!= nchars
)));
2055 #ifdef LISP_FLOAT_TYPE
2056 /* If a period is followed by a number, then we should read it
2057 as a floating point number. Otherwise, it denotes a dotted
2059 int next_char
= READCHAR
;
2062 if (! (next_char
>= '0' && next_char
<= '9'))
2069 /* Otherwise, we fall through! Note that the atom-reading loop
2070 below will now loop at least once, assuring that we will not
2071 try to UNREAD two characters in a row. */
2075 if (c
<= 040) goto retry
;
2077 register char *p
= read_buffer
;
2081 register char *end
= read_buffer
+ read_buffer_size
;
2084 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2085 || c
== '(' || c
== ')'
2086 #ifndef LISP_FLOAT_TYPE
2087 /* If we have floating-point support, then we need
2088 to allow <digits><dot><digits>. */
2090 #endif /* not LISP_FLOAT_TYPE */
2091 || c
== '[' || c
== ']' || c
== '#'
2094 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
2096 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2097 p
+= new - read_buffer
;
2098 read_buffer
+= new - read_buffer
;
2099 end
= read_buffer
+ read_buffer_size
;
2107 if (! SINGLE_BYTE_CHAR_P (c
))
2109 unsigned char workbuf
[4];
2110 unsigned char *str
= workbuf
;
2113 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
2115 bcopy (str
, p
, length
);
2126 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2127 p
+= new - read_buffer
;
2128 read_buffer
+= new - read_buffer
;
2129 /* end = read_buffer + read_buffer_size; */
2136 if (!quoted
&& !uninterned_symbol
)
2139 register Lisp_Object val
;
2141 if (*p1
== '+' || *p1
== '-') p1
++;
2142 /* Is it an integer? */
2145 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2146 #ifdef LISP_FLOAT_TYPE
2147 /* Integers can have trailing decimal points. */
2148 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2151 /* It is an integer. */
2153 #ifdef LISP_FLOAT_TYPE
2157 if (sizeof (int) == sizeof (EMACS_INT
))
2158 XSETINT (val
, atoi (read_buffer
));
2159 else if (sizeof (long) == sizeof (EMACS_INT
))
2160 XSETINT (val
, atol (read_buffer
));
2166 #ifdef LISP_FLOAT_TYPE
2167 if (isfloat_string (read_buffer
))
2169 /* Compute NaN and infinities using 0.0 in a variable,
2170 to cope with compilers that think they are smarter
2176 /* Negate the value ourselves. This treats 0, NaNs,
2177 and infinity properly on IEEE floating point hosts,
2178 and works around a common bug where atof ("-0.0")
2180 int negative
= read_buffer
[0] == '-';
2182 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2183 returns 1, is if the input ends in e+INF or e+NaN. */
2190 value
= zero
/ zero
;
2193 value
= atof (read_buffer
+ negative
);
2197 return make_float (negative
? - value
: value
);
2202 if (uninterned_symbol
)
2203 return make_symbol (read_buffer
);
2205 return intern (read_buffer
);
2211 /* List of nodes we've seen during substitute_object_in_subtree. */
2212 static Lisp_Object seen_list
;
2215 substitute_object_in_subtree (object
, placeholder
)
2217 Lisp_Object placeholder
;
2219 Lisp_Object check_object
;
2221 /* We haven't seen any objects when we start. */
2224 /* Make all the substitutions. */
2226 = substitute_object_recurse (object
, placeholder
, object
);
2228 /* Clear seen_list because we're done with it. */
2231 /* The returned object here is expected to always eq the
2233 if (!EQ (check_object
, object
))
2234 error ("Unexpected mutation error in reader");
2237 /* Feval doesn't get called from here, so no gc protection is needed. */
2238 #define SUBSTITUTE(get_val, set_val) \
2240 Lisp_Object old_value = get_val; \
2241 Lisp_Object true_value \
2242 = substitute_object_recurse (object, placeholder,\
2245 if (!EQ (old_value, true_value)) \
2252 substitute_object_recurse (object
, placeholder
, subtree
)
2254 Lisp_Object placeholder
;
2255 Lisp_Object subtree
;
2257 /* If we find the placeholder, return the target object. */
2258 if (EQ (placeholder
, subtree
))
2261 /* If we've been to this node before, don't explore it again. */
2262 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2265 /* If this node can be the entry point to a cycle, remember that
2266 we've seen it. It can only be such an entry point if it was made
2267 by #n=, which means that we can find it as a value in
2269 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2270 seen_list
= Fcons (subtree
, seen_list
);
2272 /* Recurse according to subtree's type.
2273 Every branch must return a Lisp_Object. */
2274 switch (XTYPE (subtree
))
2276 case Lisp_Vectorlike
:
2279 int length
= Flength(subtree
);
2280 for (i
= 0; i
< length
; i
++)
2282 Lisp_Object idx
= make_number (i
);
2283 SUBSTITUTE (Faref (subtree
, idx
),
2284 Faset (subtree
, idx
, true_value
));
2291 SUBSTITUTE (Fcar_safe (subtree
),
2292 Fsetcar (subtree
, true_value
));
2293 SUBSTITUTE (Fcdr_safe (subtree
),
2294 Fsetcdr (subtree
, true_value
));
2298 #ifdef USE_TEXT_PROPERTIES
2301 /* Check for text properties in each interval.
2302 substitute_in_interval contains part of the logic. */
2304 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2305 Lisp_Object arg
= Fcons (object
, placeholder
);
2307 traverse_intervals (root_interval
, 1, 0,
2308 &substitute_in_interval
, arg
);
2312 #endif /* defined USE_TEXT_PROPERTIES */
2314 /* Other types don't recurse any further. */
2320 /* Helper function for substitute_object_recurse. */
2322 substitute_in_interval (interval
, arg
)
2326 Lisp_Object object
= Fcar (arg
);
2327 Lisp_Object placeholder
= Fcdr (arg
);
2329 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2333 #ifdef LISP_FLOAT_TYPE
2350 if (*cp
== '+' || *cp
== '-')
2353 if (*cp
>= '0' && *cp
<= '9')
2356 while (*cp
>= '0' && *cp
<= '9')
2364 if (*cp
>= '0' && *cp
<= '9')
2367 while (*cp
>= '0' && *cp
<= '9')
2370 if (*cp
== 'e' || *cp
== 'E')
2374 if (*cp
== '+' || *cp
== '-')
2378 if (*cp
>= '0' && *cp
<= '9')
2381 while (*cp
>= '0' && *cp
<= '9')
2384 else if (cp
== start
)
2386 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2391 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2397 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2398 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2399 || state
== (DOT_CHAR
|TRAIL_INT
)
2400 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2401 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2402 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2404 #endif /* LISP_FLOAT_TYPE */
2407 read_vector (readcharfun
, bytecodeflag
)
2408 Lisp_Object readcharfun
;
2413 register Lisp_Object
*ptr
;
2414 register Lisp_Object tem
, item
, vector
;
2415 register struct Lisp_Cons
*otem
;
2418 tem
= read_list (1, readcharfun
);
2419 len
= Flength (tem
);
2420 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2422 size
= XVECTOR (vector
)->size
;
2423 ptr
= XVECTOR (vector
)->contents
;
2424 for (i
= 0; i
< size
; i
++)
2427 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2428 bytecode object, the docstring containing the bytecode and
2429 constants values must be treated as unibyte and passed to
2430 Fread, to get the actual bytecode string and constants vector. */
2431 if (bytecodeflag
&& load_force_doc_strings
)
2433 if (i
== COMPILED_BYTECODE
)
2435 if (!STRINGP (item
))
2436 error ("invalid byte code");
2438 /* Delay handling the bytecode slot until we know whether
2439 it is lazily-loaded (we can tell by whether the
2440 constants slot is nil). */
2441 ptr
[COMPILED_CONSTANTS
] = item
;
2444 else if (i
== COMPILED_CONSTANTS
)
2446 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2450 /* Coerce string to unibyte (like string-as-unibyte,
2451 but without generating extra garbage and
2452 guaranteeing no change in the contents). */
2453 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2454 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2456 item
= Fread (bytestr
);
2458 error ("invalid byte code");
2460 otem
= XCONS (item
);
2461 bytestr
= XCAR (item
);
2466 /* Now handle the bytecode slot. */
2467 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2470 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2478 /* FLAG = 1 means check for ] to terminate rather than ) and .
2479 FLAG = -1 means check for starting with defun
2480 and make structure pure. */
2483 read_list (flag
, readcharfun
)
2485 register Lisp_Object readcharfun
;
2487 /* -1 means check next element for defun,
2488 0 means don't check,
2489 1 means already checked and found defun. */
2490 int defunflag
= flag
< 0 ? -1 : 0;
2491 Lisp_Object val
, tail
;
2492 register Lisp_Object elt
, tem
;
2493 struct gcpro gcpro1
, gcpro2
;
2494 /* 0 is the normal case.
2495 1 means this list is a doc reference; replace it with the number 0.
2496 2 means this list is a doc reference; replace it with the doc string. */
2497 int doc_reference
= 0;
2499 /* Initialize this to 1 if we are reading a list. */
2500 int first_in_list
= flag
<= 0;
2509 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2514 /* While building, if the list starts with #$, treat it specially. */
2515 if (EQ (elt
, Vload_file_name
)
2517 && !NILP (Vpurify_flag
))
2519 if (NILP (Vdoc_file_name
))
2520 /* We have not yet called Snarf-documentation, so assume
2521 this file is described in the DOC-MM.NN file
2522 and Snarf-documentation will fill in the right value later.
2523 For now, replace the whole list with 0. */
2526 /* We have already called Snarf-documentation, so make a relative
2527 file name for this file, so it can be found properly
2528 in the installed Lisp directory.
2529 We don't use Fexpand_file_name because that would make
2530 the directory absolute now. */
2531 elt
= concat2 (build_string ("../lisp/"),
2532 Ffile_name_nondirectory (elt
));
2534 else if (EQ (elt
, Vload_file_name
)
2536 && load_force_doc_strings
)
2545 Fsignal (Qinvalid_read_syntax
,
2546 Fcons (make_string (") or . in a vector", 18), Qnil
));
2554 XCDR (tail
) = read0 (readcharfun
);
2556 val
= read0 (readcharfun
);
2557 read1 (readcharfun
, &ch
, 0);
2561 if (doc_reference
== 1)
2562 return make_number (0);
2563 if (doc_reference
== 2)
2565 /* Get a doc string from the file we are loading.
2566 If it's in saved_doc_string, get it from there. */
2567 int pos
= XINT (XCDR (val
));
2568 /* Position is negative for user variables. */
2569 if (pos
< 0) pos
= -pos
;
2570 if (pos
>= saved_doc_string_position
2571 && pos
< (saved_doc_string_position
2572 + saved_doc_string_length
))
2574 int start
= pos
- saved_doc_string_position
;
2577 /* Process quoting with ^A,
2578 and find the end of the string,
2579 which is marked with ^_ (037). */
2580 for (from
= start
, to
= start
;
2581 saved_doc_string
[from
] != 037;)
2583 int c
= saved_doc_string
[from
++];
2586 c
= saved_doc_string
[from
++];
2588 saved_doc_string
[to
++] = c
;
2590 saved_doc_string
[to
++] = 0;
2592 saved_doc_string
[to
++] = 037;
2595 saved_doc_string
[to
++] = c
;
2598 return make_string (saved_doc_string
+ start
,
2601 /* Look in prev_saved_doc_string the same way. */
2602 else if (pos
>= prev_saved_doc_string_position
2603 && pos
< (prev_saved_doc_string_position
2604 + prev_saved_doc_string_length
))
2606 int start
= pos
- prev_saved_doc_string_position
;
2609 /* Process quoting with ^A,
2610 and find the end of the string,
2611 which is marked with ^_ (037). */
2612 for (from
= start
, to
= start
;
2613 prev_saved_doc_string
[from
] != 037;)
2615 int c
= prev_saved_doc_string
[from
++];
2618 c
= prev_saved_doc_string
[from
++];
2620 prev_saved_doc_string
[to
++] = c
;
2622 prev_saved_doc_string
[to
++] = 0;
2624 prev_saved_doc_string
[to
++] = 037;
2627 prev_saved_doc_string
[to
++] = c
;
2630 return make_string (prev_saved_doc_string
+ start
,
2634 return get_doc_string (val
, 0, 0);
2639 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2641 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2643 tem
= (read_pure
&& flag
<= 0
2644 ? pure_cons (elt
, Qnil
)
2645 : Fcons (elt
, Qnil
));
2652 defunflag
= EQ (elt
, Qdefun
);
2653 else if (defunflag
> 0)
2658 Lisp_Object Vobarray
;
2659 Lisp_Object initial_obarray
;
2661 /* oblookup stores the bucket number here, for the sake of Funintern. */
2663 int oblookup_last_bucket_number
;
2665 static int hash_string ();
2666 Lisp_Object
oblookup ();
2668 /* Get an error if OBARRAY is not an obarray.
2669 If it is one, return it. */
2672 check_obarray (obarray
)
2673 Lisp_Object obarray
;
2675 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2677 /* If Vobarray is now invalid, force it to be valid. */
2678 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2680 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2685 /* Intern the C string STR: return a symbol with that name,
2686 interned in the current obarray. */
2693 int len
= strlen (str
);
2694 Lisp_Object obarray
;
2697 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2698 obarray
= check_obarray (obarray
);
2699 tem
= oblookup (obarray
, str
, len
, len
);
2702 return Fintern (make_string (str
, len
), obarray
);
2705 /* Create an uninterned symbol with name STR. */
2711 int len
= strlen (str
);
2713 return Fmake_symbol ((!NILP (Vpurify_flag
)
2714 ? make_pure_string (str
, len
, len
, 0)
2715 : make_string (str
, len
)));
2718 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2719 "Return the canonical symbol whose name is STRING.\n\
2720 If there is none, one is created by this function and returned.\n\
2721 A second optional argument specifies the obarray to use;\n\
2722 it defaults to the value of `obarray'.")
2724 Lisp_Object string
, obarray
;
2726 register Lisp_Object tem
, sym
, *ptr
;
2728 if (NILP (obarray
)) obarray
= Vobarray
;
2729 obarray
= check_obarray (obarray
);
2731 CHECK_STRING (string
, 0);
2733 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2734 XSTRING (string
)->size
,
2735 STRING_BYTES (XSTRING (string
)));
2736 if (!INTEGERP (tem
))
2739 if (!NILP (Vpurify_flag
))
2740 string
= Fpurecopy (string
);
2741 sym
= Fmake_symbol (string
);
2742 XSYMBOL (sym
)->obarray
= obarray
;
2744 if ((XSTRING (string
)->data
[0] == ':')
2745 && EQ (obarray
, initial_obarray
))
2746 XSYMBOL (sym
)->value
= sym
;
2748 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2750 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2752 XSYMBOL (sym
)->next
= 0;
2757 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2758 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
2759 A second optional argument specifies the obarray to use;\n\
2760 it defaults to the value of `obarray'.")
2762 Lisp_Object string
, obarray
;
2764 register Lisp_Object tem
;
2766 if (NILP (obarray
)) obarray
= Vobarray
;
2767 obarray
= check_obarray (obarray
);
2769 CHECK_STRING (string
, 0);
2771 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2772 XSTRING (string
)->size
,
2773 STRING_BYTES (XSTRING (string
)));
2774 if (!INTEGERP (tem
))
2779 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2780 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2781 The value is t if a symbol was found and deleted, nil otherwise.\n\
2782 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2783 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2784 OBARRAY defaults to the value of the variable `obarray'.")
2786 Lisp_Object name
, obarray
;
2788 register Lisp_Object string
, tem
;
2791 if (NILP (obarray
)) obarray
= Vobarray
;
2792 obarray
= check_obarray (obarray
);
2795 XSETSTRING (string
, XSYMBOL (name
)->name
);
2798 CHECK_STRING (name
, 0);
2802 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2803 XSTRING (string
)->size
,
2804 STRING_BYTES (XSTRING (string
)));
2807 /* If arg was a symbol, don't delete anything but that symbol itself. */
2808 if (SYMBOLP (name
) && !EQ (name
, tem
))
2811 XSYMBOL (tem
)->obarray
= Qnil
;
2813 hash
= oblookup_last_bucket_number
;
2815 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2817 if (XSYMBOL (tem
)->next
)
2818 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2820 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2824 Lisp_Object tail
, following
;
2826 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2827 XSYMBOL (tail
)->next
;
2830 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2831 if (EQ (following
, tem
))
2833 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2842 /* Return the symbol in OBARRAY whose names matches the string
2843 of SIZE characters (SIZE_BYTE bytes) at PTR.
2844 If there is no such symbol in OBARRAY, return nil.
2846 Also store the bucket number in oblookup_last_bucket_number. */
2849 oblookup (obarray
, ptr
, size
, size_byte
)
2850 Lisp_Object obarray
;
2852 int size
, size_byte
;
2856 register Lisp_Object tail
;
2857 Lisp_Object bucket
, tem
;
2859 if (!VECTORP (obarray
)
2860 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2862 obarray
= check_obarray (obarray
);
2863 obsize
= XVECTOR (obarray
)->size
;
2865 /* This is sometimes needed in the middle of GC. */
2866 obsize
&= ~ARRAY_MARK_FLAG
;
2867 /* Combining next two lines breaks VMS C 2.3. */
2868 hash
= hash_string (ptr
, size_byte
);
2870 bucket
= XVECTOR (obarray
)->contents
[hash
];
2871 oblookup_last_bucket_number
= hash
;
2872 if (XFASTINT (bucket
) == 0)
2874 else if (!SYMBOLP (bucket
))
2875 error ("Bad data in guts of obarray"); /* Like CADR error message */
2877 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2879 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2880 && XSYMBOL (tail
)->name
->size
== size
2881 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2883 else if (XSYMBOL (tail
)->next
== 0)
2886 XSETINT (tem
, hash
);
2891 hash_string (ptr
, len
)
2895 register unsigned char *p
= ptr
;
2896 register unsigned char *end
= p
+ len
;
2897 register unsigned char c
;
2898 register int hash
= 0;
2903 if (c
>= 0140) c
-= 40;
2904 hash
= ((hash
<<3) + (hash
>>28) + c
);
2906 return hash
& 07777777777;
2910 map_obarray (obarray
, fn
, arg
)
2911 Lisp_Object obarray
;
2912 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2916 register Lisp_Object tail
;
2917 CHECK_VECTOR (obarray
, 1);
2918 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2920 tail
= XVECTOR (obarray
)->contents
[i
];
2925 if (XSYMBOL (tail
)->next
== 0)
2927 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2933 mapatoms_1 (sym
, function
)
2934 Lisp_Object sym
, function
;
2936 call1 (function
, sym
);
2939 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2940 "Call FUNCTION on every symbol in OBARRAY.\n\
2941 OBARRAY defaults to the value of `obarray'.")
2943 Lisp_Object function
, obarray
;
2945 if (NILP (obarray
)) obarray
= Vobarray
;
2946 obarray
= check_obarray (obarray
);
2948 map_obarray (obarray
, mapatoms_1
, function
);
2952 #define OBARRAY_SIZE 1511
2957 Lisp_Object oblength
;
2961 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2963 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2964 Vobarray
= Fmake_vector (oblength
, make_number (0));
2965 initial_obarray
= Vobarray
;
2966 staticpro (&initial_obarray
);
2967 /* Intern nil in the obarray */
2968 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2969 /* These locals are to kludge around a pyramid compiler bug. */
2970 hash
= hash_string ("nil", 3);
2971 /* Separate statement here to avoid VAXC bug. */
2972 hash
%= OBARRAY_SIZE
;
2973 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2976 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2977 XSYMBOL (Qnil
)->function
= Qunbound
;
2978 XSYMBOL (Qunbound
)->value
= Qunbound
;
2979 XSYMBOL (Qunbound
)->function
= Qunbound
;
2982 XSYMBOL (Qnil
)->value
= Qnil
;
2983 XSYMBOL (Qnil
)->plist
= Qnil
;
2984 XSYMBOL (Qt
)->value
= Qt
;
2986 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2989 Qvariable_documentation
= intern ("variable-documentation");
2990 staticpro (&Qvariable_documentation
);
2992 read_buffer_size
= 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM
;
2993 read_buffer
= (char *) malloc (read_buffer_size
);
2998 struct Lisp_Subr
*sname
;
3001 sym
= intern (sname
->symbol_name
);
3002 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3005 #ifdef NOTDEF /* use fset in subr.el now */
3007 defalias (sname
, string
)
3008 struct Lisp_Subr
*sname
;
3012 sym
= intern (string
);
3013 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3017 /* Define an "integer variable"; a symbol whose value is forwarded
3018 to a C variable of type int. Sample call: */
3019 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3021 defvar_int (namestring
, address
)
3025 Lisp_Object sym
, val
;
3026 sym
= intern (namestring
);
3027 val
= allocate_misc ();
3028 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
3029 XINTFWD (val
)->intvar
= address
;
3030 XSYMBOL (sym
)->value
= val
;
3033 /* Similar but define a variable whose value is T if address contains 1,
3034 NIL if address contains 0 */
3036 defvar_bool (namestring
, address
)
3040 Lisp_Object sym
, val
;
3041 sym
= intern (namestring
);
3042 val
= allocate_misc ();
3043 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
3044 XBOOLFWD (val
)->boolvar
= address
;
3045 XSYMBOL (sym
)->value
= val
;
3046 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
3049 /* Similar but define a variable whose value is the Lisp Object stored
3050 at address. Two versions: with and without gc-marking of the C
3051 variable. The nopro version is used when that variable will be
3052 gc-marked for some other reason, since marking the same slot twice
3053 can cause trouble with strings. */
3055 defvar_lisp_nopro (namestring
, address
)
3057 Lisp_Object
*address
;
3059 Lisp_Object sym
, val
;
3060 sym
= intern (namestring
);
3061 val
= allocate_misc ();
3062 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3063 XOBJFWD (val
)->objvar
= address
;
3064 XSYMBOL (sym
)->value
= val
;
3068 defvar_lisp (namestring
, address
)
3070 Lisp_Object
*address
;
3072 defvar_lisp_nopro (namestring
, address
);
3073 staticpro (address
);
3078 /* Similar but define a variable whose value is the Lisp Object stored in
3079 the current buffer. address is the address of the slot in the buffer
3080 that is current now. */
3083 defvar_per_buffer (namestring
, address
, type
, doc
)
3085 Lisp_Object
*address
;
3089 Lisp_Object sym
, val
;
3091 extern struct buffer buffer_local_symbols
;
3093 sym
= intern (namestring
);
3094 val
= allocate_misc ();
3095 offset
= (char *)address
- (char *)current_buffer
;
3097 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3098 XBUFFER_OBJFWD (val
)->offset
= offset
;
3099 XSYMBOL (sym
)->value
= val
;
3100 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
3101 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
3102 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
3103 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3104 slot of buffer_local_flags */
3108 #endif /* standalone */
3110 /* Similar but define a variable whose value is the Lisp Object stored
3111 at a particular offset in the current kboard object. */
3114 defvar_kboard (namestring
, offset
)
3118 Lisp_Object sym
, val
;
3119 sym
= intern (namestring
);
3120 val
= allocate_misc ();
3121 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3122 XKBOARD_OBJFWD (val
)->offset
= offset
;
3123 XSYMBOL (sym
)->value
= val
;
3126 /* Record the value of load-path used at the start of dumping
3127 so we can see if the site changed it later during dumping. */
3128 static Lisp_Object dump_path
;
3134 int turn_off_warning
= 0;
3136 /* Compute the default load-path. */
3138 normal
= PATH_LOADSEARCH
;
3139 Vload_path
= decode_env_path (0, normal
);
3141 if (NILP (Vpurify_flag
))
3142 normal
= PATH_LOADSEARCH
;
3144 normal
= PATH_DUMPLOADSEARCH
;
3146 /* In a dumped Emacs, we normally have to reset the value of
3147 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3148 uses ../lisp, instead of the path of the installed elisp
3149 libraries. However, if it appears that Vload_path was changed
3150 from the default before dumping, don't override that value. */
3153 if (! NILP (Fequal (dump_path
, Vload_path
)))
3155 Vload_path
= decode_env_path (0, normal
);
3156 if (!NILP (Vinstallation_directory
))
3158 /* Add to the path the lisp subdir of the
3159 installation dir, if it exists. */
3160 Lisp_Object tem
, tem1
;
3161 tem
= Fexpand_file_name (build_string ("lisp"),
3162 Vinstallation_directory
);
3163 tem1
= Ffile_exists_p (tem
);
3166 if (NILP (Fmember (tem
, Vload_path
)))
3168 turn_off_warning
= 1;
3169 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3173 /* That dir doesn't exist, so add the build-time
3174 Lisp dirs instead. */
3175 Vload_path
= nconc2 (Vload_path
, dump_path
);
3177 /* Add leim under the installation dir, if it exists. */
3178 tem
= Fexpand_file_name (build_string ("leim"),
3179 Vinstallation_directory
);
3180 tem1
= Ffile_exists_p (tem
);
3183 if (NILP (Fmember (tem
, Vload_path
)))
3184 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3187 /* Add site-list under the installation dir, if it exists. */
3188 tem
= Fexpand_file_name (build_string ("site-lisp"),
3189 Vinstallation_directory
);
3190 tem1
= Ffile_exists_p (tem
);
3193 if (NILP (Fmember (tem
, Vload_path
)))
3194 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3197 /* If Emacs was not built in the source directory,
3198 and it is run from where it was built, add to load-path
3199 the lisp, leim and site-lisp dirs under that directory. */
3201 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3205 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3206 Vinstallation_directory
);
3207 tem1
= Ffile_exists_p (tem
);
3209 /* Don't be fooled if they moved the entire source tree
3210 AFTER dumping Emacs. If the build directory is indeed
3211 different from the source dir, src/Makefile.in and
3212 src/Makefile will not be found together. */
3213 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3214 Vinstallation_directory
);
3215 tem2
= Ffile_exists_p (tem
);
3216 if (!NILP (tem1
) && NILP (tem2
))
3218 tem
= Fexpand_file_name (build_string ("lisp"),
3221 if (NILP (Fmember (tem
, Vload_path
)))
3222 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3224 tem
= Fexpand_file_name (build_string ("leim"),
3227 if (NILP (Fmember (tem
, Vload_path
)))
3228 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3230 tem
= Fexpand_file_name (build_string ("site-lisp"),
3233 if (NILP (Fmember (tem
, Vload_path
)))
3234 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3242 /* NORMAL refers to the lisp dir in the source directory. */
3243 /* We used to add ../lisp at the front here, but
3244 that caused trouble because it was copied from dump_path
3245 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3246 It should be unnecessary. */
3247 Vload_path
= decode_env_path (0, normal
);
3248 dump_path
= Vload_path
;
3253 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3254 almost never correct, thereby causing a warning to be printed out that
3255 confuses users. Since PATH_LOADSEARCH is always overridden by the
3256 EMACSLOADPATH environment variable below, disable the warning on NT. */
3258 /* Warn if dirs in the *standard* path don't exist. */
3259 if (!turn_off_warning
)
3261 Lisp_Object path_tail
;
3263 for (path_tail
= Vload_path
;
3265 path_tail
= XCDR (path_tail
))
3267 Lisp_Object dirfile
;
3268 dirfile
= Fcar (path_tail
);
3269 if (STRINGP (dirfile
))
3271 dirfile
= Fdirectory_file_name (dirfile
);
3272 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3273 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3278 #endif /* WINDOWSNT */
3280 /* If the EMACSLOADPATH environment variable is set, use its value.
3281 This doesn't apply if we're dumping. */
3283 if (NILP (Vpurify_flag
)
3284 && egetenv ("EMACSLOADPATH"))
3286 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3290 load_in_progress
= 0;
3291 Vload_file_name
= Qnil
;
3293 load_descriptor_list
= Qnil
;
3295 Vstandard_input
= Qt
;
3298 /* Print a warning, using format string FORMAT, that directory DIRNAME
3299 does not exist. Print it on stderr and put it in *Message*. */
3302 dir_warning (format
, dirname
)
3304 Lisp_Object dirname
;
3307 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3309 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3310 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3311 /* Don't log the warning before we've initialized!! */
3313 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3320 defsubr (&Sread_from_string
);
3322 defsubr (&Sintern_soft
);
3323 defsubr (&Sunintern
);
3325 defsubr (&Seval_buffer
);
3326 defsubr (&Seval_region
);
3327 defsubr (&Sread_char
);
3328 defsubr (&Sread_char_exclusive
);
3329 defsubr (&Sread_event
);
3330 defsubr (&Sget_file_char
);
3331 defsubr (&Smapatoms
);
3333 DEFVAR_LISP ("obarray", &Vobarray
,
3334 "Symbol table for use by `intern' and `read'.\n\
3335 It is a vector whose length ought to be prime for best results.\n\
3336 The vector's contents don't make sense if examined from Lisp programs;\n\
3337 to find all the symbols in an obarray, use `mapatoms'.");
3339 DEFVAR_LISP ("values", &Vvalues
,
3340 "List of values of all expressions which were read, evaluated and printed.\n\
3341 Order is reverse chronological.");
3343 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3344 "Stream for read to get input from.\n\
3345 See documentation of `read' for possible values.");
3346 Vstandard_input
= Qt
;
3348 DEFVAR_LISP ("load-path", &Vload_path
,
3349 "*List of directories to search for files to load.\n\
3350 Each element is a string (directory name) or nil (try default directory).\n\
3351 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3352 otherwise to default specified by file `epaths.h' when Emacs was built.");
3354 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3355 "Non-nil iff inside of `load'.");
3357 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3358 "An alist of expressions to be evalled when particular files are loaded.\n\
3359 Each element looks like (FILENAME FORMS...).\n\
3360 When `load' is run and the file-name argument is FILENAME,\n\
3361 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3362 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3363 with no directory specified, since that is how `load' is normally called.\n\
3364 An error in FORMS does not undo the load,\n\
3365 but does prevent execution of the rest of the FORMS.");
3366 Vafter_load_alist
= Qnil
;
3368 DEFVAR_LISP ("load-history", &Vload_history
,
3369 "Alist mapping source file names to symbols and features.\n\
3370 Each alist element is a list that starts with a file name,\n\
3371 except for one element (optional) that starts with nil and describes\n\
3372 definitions evaluated from buffers not visiting files.\n\
3373 The remaining elements of each list are symbols defined as functions\n\
3374 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3375 Vload_history
= Qnil
;
3377 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3378 "Full name of file being loaded by `load'.");
3379 Vload_file_name
= Qnil
;
3381 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3382 "File name, including directory, of user's initialization file.");
3383 Vuser_init_file
= Qnil
;
3385 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3386 "Used for internal purposes by `load'.");
3387 Vcurrent_load_list
= Qnil
;
3389 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3390 "Function used by `load' and `eval-region' for reading expressions.\n\
3391 The default is nil, which means use the function `read'.");
3392 Vload_read_function
= Qnil
;
3394 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3395 "Function called in `load' for loading an Emacs lisp source file.\n\
3396 This function is for doing code conversion before reading the source file.\n\
3397 If nil, loading is done without any code conversion.\n\
3398 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3399 FULLNAME is the full name of FILE.\n\
3400 See `load' for the meaning of the remaining arguments.");
3401 Vload_source_file_function
= Qnil
;
3403 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3404 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3405 This is useful when the file being loaded is a temporary copy.");
3406 load_force_doc_strings
= 0;
3408 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3409 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3410 This is normally used in `load-with-code-conversion'\n\
3411 for loading non-compiled files.");
3412 load_convert_to_unibyte
= 0;
3414 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3415 "Directory in which Emacs sources were found when Emacs was built.\n\
3416 You cannot count on them to still be there!");
3418 = Fexpand_file_name (build_string ("../"),
3419 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3421 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3422 "List of files that were preloaded (when dumping Emacs).");
3423 Vpreloaded_file_list
= Qnil
;
3425 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars
,
3426 "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
3427 Vbyte_boolean_vars
= Qnil
;
3429 /* Vsource_directory was initialized in init_lread. */
3431 load_descriptor_list
= Qnil
;
3432 staticpro (&load_descriptor_list
);
3434 Qcurrent_load_list
= intern ("current-load-list");
3435 staticpro (&Qcurrent_load_list
);
3437 Qstandard_input
= intern ("standard-input");
3438 staticpro (&Qstandard_input
);
3440 Qread_char
= intern ("read-char");
3441 staticpro (&Qread_char
);
3443 Qget_file_char
= intern ("get-file-char");
3444 staticpro (&Qget_file_char
);
3446 Qbackquote
= intern ("`");
3447 staticpro (&Qbackquote
);
3448 Qcomma
= intern (",");
3449 staticpro (&Qcomma
);
3450 Qcomma_at
= intern (",@");
3451 staticpro (&Qcomma_at
);
3452 Qcomma_dot
= intern (",.");
3453 staticpro (&Qcomma_dot
);
3455 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3456 staticpro (&Qinhibit_file_name_operation
);
3458 Qascii_character
= intern ("ascii-character");
3459 staticpro (&Qascii_character
);
3461 Qfunction
= intern ("function");
3462 staticpro (&Qfunction
);
3464 Qload
= intern ("load");
3467 Qload_file_name
= intern ("load-file-name");
3468 staticpro (&Qload_file_name
);
3470 staticpro (&dump_path
);
3472 staticpro (&read_objects
);
3473 read_objects
= Qnil
;
3474 staticpro (&seen_list
);