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
);
1699 struct gcpro gcpro1
;
1702 /* Read the string itself. */
1703 tmp
= read1 (readcharfun
, &ch
, 0);
1704 if (ch
!= 0 || !STRINGP (tmp
))
1705 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1707 /* Read the intervals and their properties. */
1710 Lisp_Object beg
, end
, plist
;
1712 beg
= read1 (readcharfun
, &ch
, 0);
1716 end
= read1 (readcharfun
, &ch
, 0);
1718 plist
= read1 (readcharfun
, &ch
, 0);
1720 Fsignal (Qinvalid_read_syntax
,
1721 Fcons (build_string ("invalid string property list"),
1723 Fset_text_properties (beg
, end
, plist
, tmp
);
1729 /* #@NUMBER is used to skip NUMBER following characters.
1730 That's used in .elc files to skip over doc strings
1731 and function definitions. */
1736 /* Read a decimal integer. */
1737 while ((c
= READCHAR
) >= 0
1738 && c
>= '0' && c
<= '9')
1746 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1748 /* If we are supposed to force doc strings into core right now,
1749 record the last string that we skipped,
1750 and record where in the file it comes from. */
1752 /* But first exchange saved_doc_string
1753 with prev_saved_doc_string, so we save two strings. */
1755 char *temp
= saved_doc_string
;
1756 int temp_size
= saved_doc_string_size
;
1757 file_offset temp_pos
= saved_doc_string_position
;
1758 int temp_len
= saved_doc_string_length
;
1760 saved_doc_string
= prev_saved_doc_string
;
1761 saved_doc_string_size
= prev_saved_doc_string_size
;
1762 saved_doc_string_position
= prev_saved_doc_string_position
;
1763 saved_doc_string_length
= prev_saved_doc_string_length
;
1765 prev_saved_doc_string
= temp
;
1766 prev_saved_doc_string_size
= temp_size
;
1767 prev_saved_doc_string_position
= temp_pos
;
1768 prev_saved_doc_string_length
= temp_len
;
1771 if (saved_doc_string_size
== 0)
1773 saved_doc_string_size
= nskip
+ 100;
1774 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1776 if (nskip
> saved_doc_string_size
)
1778 saved_doc_string_size
= nskip
+ 100;
1779 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1780 saved_doc_string_size
);
1783 saved_doc_string_position
= file_tell (instream
);
1785 /* Copy that many characters into saved_doc_string. */
1786 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1787 saved_doc_string
[i
] = c
= READCHAR
;
1789 saved_doc_string_length
= i
;
1793 /* Skip that many characters. */
1794 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1801 return Vload_file_name
;
1803 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1804 /* #:foo is the uninterned symbol named foo. */
1807 uninterned_symbol
= 1;
1811 /* Reader forms that can reuse previously read objects. */
1812 if (c
>= '0' && c
<= '9')
1817 /* Read a non-negative integer. */
1818 while (c
>= '0' && c
<= '9')
1824 /* #n=object returns object, but associates it with n for #n#. */
1827 /* Make a placeholder for #n# to use temporarily */
1828 Lisp_Object placeholder
;
1831 placeholder
= Fcons(Qnil
, Qnil
);
1832 cell
= Fcons (make_number (n
), placeholder
);
1833 read_objects
= Fcons (cell
, read_objects
);
1835 /* Read the object itself. */
1836 tem
= read0 (readcharfun
);
1838 /* Now put it everywhere the placeholder was... */
1839 substitute_object_in_subtree (tem
, placeholder
);
1841 /* ...and #n# will use the real value from now on. */
1842 Fsetcdr (cell
, tem
);
1846 /* #n# returns a previously read object. */
1849 tem
= Fassq (make_number (n
), read_objects
);
1852 /* Fall through to error message. */
1854 /* Fall through to error message. */
1858 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1861 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1866 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1876 new_backquote_flag
= 1;
1877 value
= read0 (readcharfun
);
1878 new_backquote_flag
= 0;
1880 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1884 if (new_backquote_flag
)
1886 Lisp_Object comma_type
= Qnil
;
1891 comma_type
= Qcomma_at
;
1893 comma_type
= Qcomma_dot
;
1896 if (ch
>= 0) UNREAD (ch
);
1897 comma_type
= Qcomma
;
1900 new_backquote_flag
= 0;
1901 value
= read0 (readcharfun
);
1902 new_backquote_flag
= 1;
1903 return Fcons (comma_type
, Fcons (value
, Qnil
));
1911 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1914 c
= read_escape (readcharfun
, 0);
1915 else if (BASE_LEADING_CODE_P (c
))
1916 c
= read_multibyte (c
, readcharfun
);
1918 return make_number (c
);
1923 register char *p
= read_buffer
;
1924 register char *end
= read_buffer
+ read_buffer_size
;
1926 /* Nonzero if we saw an escape sequence specifying
1927 a multibyte character. */
1928 int force_multibyte
= 0;
1929 /* Nonzero if we saw an escape sequence specifying
1930 a single-byte character. */
1931 int force_singlebyte
= 0;
1935 while ((c
= READCHAR
) >= 0
1938 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1940 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1941 p
+= new - read_buffer
;
1942 read_buffer
+= new - read_buffer
;
1943 end
= read_buffer
+ read_buffer_size
;
1948 c
= read_escape (readcharfun
, 1);
1950 /* C is -1 if \ newline has just been seen */
1953 if (p
== read_buffer
)
1958 /* If an escape specifies a non-ASCII single-byte character,
1959 this must be a unibyte string. */
1960 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
))
1961 && ! ASCII_BYTE_P ((c
& ~CHAR_MODIFIER_MASK
)))
1962 force_singlebyte
= 1;
1965 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1967 unsigned char workbuf
[4];
1968 unsigned char *str
= workbuf
;
1971 /* Any modifiers for a multibyte character are invalid. */
1972 if (c
& CHAR_MODIFIER_MASK
)
1973 error ("Invalid modifier in string");
1974 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
1976 force_multibyte
= 1;
1978 bcopy (str
, p
, length
);
1983 /* Allow `\C- ' and `\C-?'. */
1984 if (c
== (CHAR_CTL
| ' '))
1986 else if (c
== (CHAR_CTL
| '?'))
1991 /* Shift modifier is valid only with [A-Za-z]. */
1992 if ((c
& 0377) >= 'A' && (c
& 0377) <= 'Z')
1994 else if ((c
& 0377) >= 'a' && (c
& 0377) <= 'z')
1995 c
= (c
& ~CHAR_SHIFT
) - ('a' - 'A');
1999 /* Move the meta bit to the right place for a string. */
2000 c
= (c
& ~CHAR_META
) | 0x80;
2002 error ("Invalid modifier in string");
2007 return Fsignal (Qend_of_file
, Qnil
);
2009 /* If purifying, and string starts with \ newline,
2010 return zero instead. This is for doc strings
2011 that we are really going to find in etc/DOC.nn.nn */
2012 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2013 return make_number (0);
2015 if (force_multibyte
)
2016 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2017 else if (force_singlebyte
)
2018 nchars
= p
- read_buffer
;
2019 else if (load_convert_to_unibyte
)
2022 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2023 if (p
- read_buffer
!= nchars
)
2025 string
= make_multibyte_string (read_buffer
, nchars
,
2027 return Fstring_make_unibyte (string
);
2030 else if (EQ (readcharfun
, Qget_file_char
)
2031 || EQ (readcharfun
, Qlambda
))
2032 /* Nowadays, reading directly from a file
2033 is used only for compiled Emacs Lisp files,
2034 and those always use the Emacs internal encoding.
2035 Meanwhile, Qlambda is used for reading dynamic byte code
2036 (compiled with byte-compile-dynamic = t). */
2037 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2039 /* In all other cases, if we read these bytes as
2040 separate characters, treat them as separate characters now. */
2041 nchars
= p
- read_buffer
;
2044 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2046 || (p
- read_buffer
!= nchars
)));
2047 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2049 || (p
- read_buffer
!= nchars
)));
2054 #ifdef LISP_FLOAT_TYPE
2055 /* If a period is followed by a number, then we should read it
2056 as a floating point number. Otherwise, it denotes a dotted
2058 int next_char
= READCHAR
;
2061 if (! (next_char
>= '0' && next_char
<= '9'))
2068 /* Otherwise, we fall through! Note that the atom-reading loop
2069 below will now loop at least once, assuring that we will not
2070 try to UNREAD two characters in a row. */
2074 if (c
<= 040) goto retry
;
2076 register char *p
= read_buffer
;
2080 register char *end
= read_buffer
+ read_buffer_size
;
2083 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2084 || c
== '(' || c
== ')'
2085 #ifndef LISP_FLOAT_TYPE
2086 /* If we have floating-point support, then we need
2087 to allow <digits><dot><digits>. */
2089 #endif /* not LISP_FLOAT_TYPE */
2090 || c
== '[' || c
== ']' || c
== '#'
2093 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
2095 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2096 p
+= new - read_buffer
;
2097 read_buffer
+= new - read_buffer
;
2098 end
= read_buffer
+ read_buffer_size
;
2106 if (! SINGLE_BYTE_CHAR_P (c
))
2108 unsigned char workbuf
[4];
2109 unsigned char *str
= workbuf
;
2112 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
2114 bcopy (str
, p
, length
);
2125 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2126 p
+= new - read_buffer
;
2127 read_buffer
+= new - read_buffer
;
2128 /* end = read_buffer + read_buffer_size; */
2135 if (!quoted
&& !uninterned_symbol
)
2138 register Lisp_Object val
;
2140 if (*p1
== '+' || *p1
== '-') p1
++;
2141 /* Is it an integer? */
2144 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2145 #ifdef LISP_FLOAT_TYPE
2146 /* Integers can have trailing decimal points. */
2147 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2150 /* It is an integer. */
2152 #ifdef LISP_FLOAT_TYPE
2156 if (sizeof (int) == sizeof (EMACS_INT
))
2157 XSETINT (val
, atoi (read_buffer
));
2158 else if (sizeof (long) == sizeof (EMACS_INT
))
2159 XSETINT (val
, atol (read_buffer
));
2165 #ifdef LISP_FLOAT_TYPE
2166 if (isfloat_string (read_buffer
))
2168 /* Compute NaN and infinities using 0.0 in a variable,
2169 to cope with compilers that think they are smarter
2175 /* Negate the value ourselves. This treats 0, NaNs,
2176 and infinity properly on IEEE floating point hosts,
2177 and works around a common bug where atof ("-0.0")
2179 int negative
= read_buffer
[0] == '-';
2181 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2182 returns 1, is if the input ends in e+INF or e+NaN. */
2189 value
= zero
/ zero
;
2192 value
= atof (read_buffer
+ negative
);
2196 return make_float (negative
? - value
: value
);
2201 if (uninterned_symbol
)
2202 return make_symbol (read_buffer
);
2204 return intern (read_buffer
);
2210 /* List of nodes we've seen during substitute_object_in_subtree. */
2211 static Lisp_Object seen_list
;
2214 substitute_object_in_subtree (object
, placeholder
)
2216 Lisp_Object placeholder
;
2218 Lisp_Object check_object
;
2220 /* We haven't seen any objects when we start. */
2223 /* Make all the substitutions. */
2225 = substitute_object_recurse (object
, placeholder
, object
);
2227 /* Clear seen_list because we're done with it. */
2230 /* The returned object here is expected to always eq the
2232 if (!EQ (check_object
, object
))
2233 error ("Unexpected mutation error in reader");
2236 /* Feval doesn't get called from here, so no gc protection is needed. */
2237 #define SUBSTITUTE(get_val, set_val) \
2239 Lisp_Object old_value = get_val; \
2240 Lisp_Object true_value \
2241 = substitute_object_recurse (object, placeholder,\
2244 if (!EQ (old_value, true_value)) \
2251 substitute_object_recurse (object
, placeholder
, subtree
)
2253 Lisp_Object placeholder
;
2254 Lisp_Object subtree
;
2256 /* If we find the placeholder, return the target object. */
2257 if (EQ (placeholder
, subtree
))
2260 /* If we've been to this node before, don't explore it again. */
2261 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2264 /* If this node can be the entry point to a cycle, remember that
2265 we've seen it. It can only be such an entry point if it was made
2266 by #n=, which means that we can find it as a value in
2268 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2269 seen_list
= Fcons (subtree
, seen_list
);
2271 /* Recurse according to subtree's type.
2272 Every branch must return a Lisp_Object. */
2273 switch (XTYPE (subtree
))
2275 case Lisp_Vectorlike
:
2278 int length
= Flength(subtree
);
2279 for (i
= 0; i
< length
; i
++)
2281 Lisp_Object idx
= make_number (i
);
2282 SUBSTITUTE (Faref (subtree
, idx
),
2283 Faset (subtree
, idx
, true_value
));
2290 SUBSTITUTE (Fcar_safe (subtree
),
2291 Fsetcar (subtree
, true_value
));
2292 SUBSTITUTE (Fcdr_safe (subtree
),
2293 Fsetcdr (subtree
, true_value
));
2299 /* Check for text properties in each interval.
2300 substitute_in_interval contains part of the logic. */
2302 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2303 Lisp_Object arg
= Fcons (object
, placeholder
);
2305 traverse_intervals (root_interval
, 1, 0,
2306 &substitute_in_interval
, arg
);
2311 /* Other types don't recurse any further. */
2317 /* Helper function for substitute_object_recurse. */
2319 substitute_in_interval (interval
, arg
)
2323 Lisp_Object object
= Fcar (arg
);
2324 Lisp_Object placeholder
= Fcdr (arg
);
2326 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2330 #ifdef LISP_FLOAT_TYPE
2347 if (*cp
== '+' || *cp
== '-')
2350 if (*cp
>= '0' && *cp
<= '9')
2353 while (*cp
>= '0' && *cp
<= '9')
2361 if (*cp
>= '0' && *cp
<= '9')
2364 while (*cp
>= '0' && *cp
<= '9')
2367 if (*cp
== 'e' || *cp
== 'E')
2371 if (*cp
== '+' || *cp
== '-')
2375 if (*cp
>= '0' && *cp
<= '9')
2378 while (*cp
>= '0' && *cp
<= '9')
2381 else if (cp
== start
)
2383 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2388 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2394 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2395 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2396 || state
== (DOT_CHAR
|TRAIL_INT
)
2397 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2398 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2399 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2401 #endif /* LISP_FLOAT_TYPE */
2404 read_vector (readcharfun
, bytecodeflag
)
2405 Lisp_Object readcharfun
;
2410 register Lisp_Object
*ptr
;
2411 register Lisp_Object tem
, item
, vector
;
2412 register struct Lisp_Cons
*otem
;
2415 tem
= read_list (1, readcharfun
);
2416 len
= Flength (tem
);
2417 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2419 size
= XVECTOR (vector
)->size
;
2420 ptr
= XVECTOR (vector
)->contents
;
2421 for (i
= 0; i
< size
; i
++)
2424 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2425 bytecode object, the docstring containing the bytecode and
2426 constants values must be treated as unibyte and passed to
2427 Fread, to get the actual bytecode string and constants vector. */
2428 if (bytecodeflag
&& load_force_doc_strings
)
2430 if (i
== COMPILED_BYTECODE
)
2432 if (!STRINGP (item
))
2433 error ("invalid byte code");
2435 /* Delay handling the bytecode slot until we know whether
2436 it is lazily-loaded (we can tell by whether the
2437 constants slot is nil). */
2438 ptr
[COMPILED_CONSTANTS
] = item
;
2441 else if (i
== COMPILED_CONSTANTS
)
2443 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2447 /* Coerce string to unibyte (like string-as-unibyte,
2448 but without generating extra garbage and
2449 guaranteeing no change in the contents). */
2450 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2451 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2453 item
= Fread (bytestr
);
2455 error ("invalid byte code");
2457 otem
= XCONS (item
);
2458 bytestr
= XCAR (item
);
2463 /* Now handle the bytecode slot. */
2464 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2467 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2475 /* FLAG = 1 means check for ] to terminate rather than ) and .
2476 FLAG = -1 means check for starting with defun
2477 and make structure pure. */
2480 read_list (flag
, readcharfun
)
2482 register Lisp_Object readcharfun
;
2484 /* -1 means check next element for defun,
2485 0 means don't check,
2486 1 means already checked and found defun. */
2487 int defunflag
= flag
< 0 ? -1 : 0;
2488 Lisp_Object val
, tail
;
2489 register Lisp_Object elt
, tem
;
2490 struct gcpro gcpro1
, gcpro2
;
2491 /* 0 is the normal case.
2492 1 means this list is a doc reference; replace it with the number 0.
2493 2 means this list is a doc reference; replace it with the doc string. */
2494 int doc_reference
= 0;
2496 /* Initialize this to 1 if we are reading a list. */
2497 int first_in_list
= flag
<= 0;
2506 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2511 /* While building, if the list starts with #$, treat it specially. */
2512 if (EQ (elt
, Vload_file_name
)
2514 && !NILP (Vpurify_flag
))
2516 if (NILP (Vdoc_file_name
))
2517 /* We have not yet called Snarf-documentation, so assume
2518 this file is described in the DOC-MM.NN file
2519 and Snarf-documentation will fill in the right value later.
2520 For now, replace the whole list with 0. */
2523 /* We have already called Snarf-documentation, so make a relative
2524 file name for this file, so it can be found properly
2525 in the installed Lisp directory.
2526 We don't use Fexpand_file_name because that would make
2527 the directory absolute now. */
2528 elt
= concat2 (build_string ("../lisp/"),
2529 Ffile_name_nondirectory (elt
));
2531 else if (EQ (elt
, Vload_file_name
)
2533 && load_force_doc_strings
)
2542 Fsignal (Qinvalid_read_syntax
,
2543 Fcons (make_string (") or . in a vector", 18), Qnil
));
2551 XCDR (tail
) = read0 (readcharfun
);
2553 val
= read0 (readcharfun
);
2554 read1 (readcharfun
, &ch
, 0);
2558 if (doc_reference
== 1)
2559 return make_number (0);
2560 if (doc_reference
== 2)
2562 /* Get a doc string from the file we are loading.
2563 If it's in saved_doc_string, get it from there. */
2564 int pos
= XINT (XCDR (val
));
2565 /* Position is negative for user variables. */
2566 if (pos
< 0) pos
= -pos
;
2567 if (pos
>= saved_doc_string_position
2568 && pos
< (saved_doc_string_position
2569 + saved_doc_string_length
))
2571 int start
= pos
- saved_doc_string_position
;
2574 /* Process quoting with ^A,
2575 and find the end of the string,
2576 which is marked with ^_ (037). */
2577 for (from
= start
, to
= start
;
2578 saved_doc_string
[from
] != 037;)
2580 int c
= saved_doc_string
[from
++];
2583 c
= saved_doc_string
[from
++];
2585 saved_doc_string
[to
++] = c
;
2587 saved_doc_string
[to
++] = 0;
2589 saved_doc_string
[to
++] = 037;
2592 saved_doc_string
[to
++] = c
;
2595 return make_string (saved_doc_string
+ start
,
2598 /* Look in prev_saved_doc_string the same way. */
2599 else if (pos
>= prev_saved_doc_string_position
2600 && pos
< (prev_saved_doc_string_position
2601 + prev_saved_doc_string_length
))
2603 int start
= pos
- prev_saved_doc_string_position
;
2606 /* Process quoting with ^A,
2607 and find the end of the string,
2608 which is marked with ^_ (037). */
2609 for (from
= start
, to
= start
;
2610 prev_saved_doc_string
[from
] != 037;)
2612 int c
= prev_saved_doc_string
[from
++];
2615 c
= prev_saved_doc_string
[from
++];
2617 prev_saved_doc_string
[to
++] = c
;
2619 prev_saved_doc_string
[to
++] = 0;
2621 prev_saved_doc_string
[to
++] = 037;
2624 prev_saved_doc_string
[to
++] = c
;
2627 return make_string (prev_saved_doc_string
+ start
,
2631 return get_doc_string (val
, 0, 0);
2636 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2638 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2640 tem
= (read_pure
&& flag
<= 0
2641 ? pure_cons (elt
, Qnil
)
2642 : Fcons (elt
, Qnil
));
2649 defunflag
= EQ (elt
, Qdefun
);
2650 else if (defunflag
> 0)
2655 Lisp_Object Vobarray
;
2656 Lisp_Object initial_obarray
;
2658 /* oblookup stores the bucket number here, for the sake of Funintern. */
2660 int oblookup_last_bucket_number
;
2662 static int hash_string ();
2663 Lisp_Object
oblookup ();
2665 /* Get an error if OBARRAY is not an obarray.
2666 If it is one, return it. */
2669 check_obarray (obarray
)
2670 Lisp_Object obarray
;
2672 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2674 /* If Vobarray is now invalid, force it to be valid. */
2675 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2677 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2682 /* Intern the C string STR: return a symbol with that name,
2683 interned in the current obarray. */
2690 int len
= strlen (str
);
2691 Lisp_Object obarray
;
2694 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2695 obarray
= check_obarray (obarray
);
2696 tem
= oblookup (obarray
, str
, len
, len
);
2699 return Fintern (make_string (str
, len
), obarray
);
2702 /* Create an uninterned symbol with name STR. */
2708 int len
= strlen (str
);
2710 return Fmake_symbol ((!NILP (Vpurify_flag
)
2711 ? make_pure_string (str
, len
, len
, 0)
2712 : make_string (str
, len
)));
2715 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2716 "Return the canonical symbol whose name is STRING.\n\
2717 If there is none, one is created by this function and returned.\n\
2718 A second optional argument specifies the obarray to use;\n\
2719 it defaults to the value of `obarray'.")
2721 Lisp_Object string
, obarray
;
2723 register Lisp_Object tem
, sym
, *ptr
;
2725 if (NILP (obarray
)) obarray
= Vobarray
;
2726 obarray
= check_obarray (obarray
);
2728 CHECK_STRING (string
, 0);
2730 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2731 XSTRING (string
)->size
,
2732 STRING_BYTES (XSTRING (string
)));
2733 if (!INTEGERP (tem
))
2736 if (!NILP (Vpurify_flag
))
2737 string
= Fpurecopy (string
);
2738 sym
= Fmake_symbol (string
);
2739 XSYMBOL (sym
)->obarray
= obarray
;
2741 if ((XSTRING (string
)->data
[0] == ':')
2742 && EQ (obarray
, initial_obarray
))
2743 XSYMBOL (sym
)->value
= sym
;
2745 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2747 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2749 XSYMBOL (sym
)->next
= 0;
2754 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2755 "Return the canonical symbol named NAME, or nil if none exists.\n\
2756 NAME may be a string or a symbol. If it is a symbol, that exact\n\
2757 symbol is searched for.\n\
2758 A second optional argument specifies the obarray to use;\n\
2759 it defaults to the value of `obarray'.")
2761 Lisp_Object name
, obarray
;
2763 register Lisp_Object tem
;
2764 struct Lisp_String
*string
;
2766 if (NILP (obarray
)) obarray
= Vobarray
;
2767 obarray
= check_obarray (obarray
);
2769 if (!SYMBOLP (name
))
2771 CHECK_STRING (name
, 0);
2772 string
= XSTRING (name
);
2775 string
= XSYMBOL (name
)->name
;
2777 tem
= oblookup (obarray
, string
->data
, string
->size
, STRING_BYTES (string
));
2778 if (INTEGERP (tem
) || (SYMBOLP (name
) && !EQ (name
, tem
)))
2784 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2785 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2786 The value is t if a symbol was found and deleted, nil otherwise.\n\
2787 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2788 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2789 OBARRAY defaults to the value of the variable `obarray'.")
2791 Lisp_Object name
, obarray
;
2793 register Lisp_Object string
, tem
;
2796 if (NILP (obarray
)) obarray
= Vobarray
;
2797 obarray
= check_obarray (obarray
);
2800 XSETSTRING (string
, XSYMBOL (name
)->name
);
2803 CHECK_STRING (name
, 0);
2807 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2808 XSTRING (string
)->size
,
2809 STRING_BYTES (XSTRING (string
)));
2812 /* If arg was a symbol, don't delete anything but that symbol itself. */
2813 if (SYMBOLP (name
) && !EQ (name
, tem
))
2816 XSYMBOL (tem
)->obarray
= Qnil
;
2818 hash
= oblookup_last_bucket_number
;
2820 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2822 if (XSYMBOL (tem
)->next
)
2823 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2825 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2829 Lisp_Object tail
, following
;
2831 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2832 XSYMBOL (tail
)->next
;
2835 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2836 if (EQ (following
, tem
))
2838 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2847 /* Return the symbol in OBARRAY whose names matches the string
2848 of SIZE characters (SIZE_BYTE bytes) at PTR.
2849 If there is no such symbol in OBARRAY, return nil.
2851 Also store the bucket number in oblookup_last_bucket_number. */
2854 oblookup (obarray
, ptr
, size
, size_byte
)
2855 Lisp_Object obarray
;
2857 int size
, size_byte
;
2861 register Lisp_Object tail
;
2862 Lisp_Object bucket
, tem
;
2864 if (!VECTORP (obarray
)
2865 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2867 obarray
= check_obarray (obarray
);
2868 obsize
= XVECTOR (obarray
)->size
;
2870 /* This is sometimes needed in the middle of GC. */
2871 obsize
&= ~ARRAY_MARK_FLAG
;
2872 /* Combining next two lines breaks VMS C 2.3. */
2873 hash
= hash_string (ptr
, size_byte
);
2875 bucket
= XVECTOR (obarray
)->contents
[hash
];
2876 oblookup_last_bucket_number
= hash
;
2877 if (XFASTINT (bucket
) == 0)
2879 else if (!SYMBOLP (bucket
))
2880 error ("Bad data in guts of obarray"); /* Like CADR error message */
2882 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2884 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2885 && XSYMBOL (tail
)->name
->size
== size
2886 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2888 else if (XSYMBOL (tail
)->next
== 0)
2891 XSETINT (tem
, hash
);
2896 hash_string (ptr
, len
)
2900 register unsigned char *p
= ptr
;
2901 register unsigned char *end
= p
+ len
;
2902 register unsigned char c
;
2903 register int hash
= 0;
2908 if (c
>= 0140) c
-= 40;
2909 hash
= ((hash
<<3) + (hash
>>28) + c
);
2911 return hash
& 07777777777;
2915 map_obarray (obarray
, fn
, arg
)
2916 Lisp_Object obarray
;
2917 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2921 register Lisp_Object tail
;
2922 CHECK_VECTOR (obarray
, 1);
2923 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2925 tail
= XVECTOR (obarray
)->contents
[i
];
2930 if (XSYMBOL (tail
)->next
== 0)
2932 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2938 mapatoms_1 (sym
, function
)
2939 Lisp_Object sym
, function
;
2941 call1 (function
, sym
);
2944 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2945 "Call FUNCTION on every symbol in OBARRAY.\n\
2946 OBARRAY defaults to the value of `obarray'.")
2948 Lisp_Object function
, obarray
;
2950 if (NILP (obarray
)) obarray
= Vobarray
;
2951 obarray
= check_obarray (obarray
);
2953 map_obarray (obarray
, mapatoms_1
, function
);
2957 #define OBARRAY_SIZE 1511
2962 Lisp_Object oblength
;
2966 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2968 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2969 Vobarray
= Fmake_vector (oblength
, make_number (0));
2970 initial_obarray
= Vobarray
;
2971 staticpro (&initial_obarray
);
2972 /* Intern nil in the obarray */
2973 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2974 /* These locals are to kludge around a pyramid compiler bug. */
2975 hash
= hash_string ("nil", 3);
2976 /* Separate statement here to avoid VAXC bug. */
2977 hash
%= OBARRAY_SIZE
;
2978 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2981 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2982 XSYMBOL (Qnil
)->function
= Qunbound
;
2983 XSYMBOL (Qunbound
)->value
= Qunbound
;
2984 XSYMBOL (Qunbound
)->function
= Qunbound
;
2987 XSYMBOL (Qnil
)->value
= Qnil
;
2988 XSYMBOL (Qnil
)->plist
= Qnil
;
2989 XSYMBOL (Qt
)->value
= Qt
;
2991 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2994 Qvariable_documentation
= intern ("variable-documentation");
2995 staticpro (&Qvariable_documentation
);
2997 read_buffer_size
= 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM
;
2998 read_buffer
= (char *) malloc (read_buffer_size
);
3003 struct Lisp_Subr
*sname
;
3006 sym
= intern (sname
->symbol_name
);
3007 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3010 #ifdef NOTDEF /* use fset in subr.el now */
3012 defalias (sname
, string
)
3013 struct Lisp_Subr
*sname
;
3017 sym
= intern (string
);
3018 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3022 /* Define an "integer variable"; a symbol whose value is forwarded
3023 to a C variable of type int. Sample call: */
3024 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3026 defvar_int (namestring
, address
)
3030 Lisp_Object sym
, val
;
3031 sym
= intern (namestring
);
3032 val
= allocate_misc ();
3033 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
3034 XINTFWD (val
)->intvar
= address
;
3035 XSYMBOL (sym
)->value
= val
;
3038 /* Similar but define a variable whose value is T if address contains 1,
3039 NIL if address contains 0 */
3041 defvar_bool (namestring
, address
)
3045 Lisp_Object sym
, val
;
3046 sym
= intern (namestring
);
3047 val
= allocate_misc ();
3048 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
3049 XBOOLFWD (val
)->boolvar
= address
;
3050 XSYMBOL (sym
)->value
= val
;
3051 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
3054 /* Similar but define a variable whose value is the Lisp Object stored
3055 at address. Two versions: with and without gc-marking of the C
3056 variable. The nopro version is used when that variable will be
3057 gc-marked for some other reason, since marking the same slot twice
3058 can cause trouble with strings. */
3060 defvar_lisp_nopro (namestring
, address
)
3062 Lisp_Object
*address
;
3064 Lisp_Object sym
, val
;
3065 sym
= intern (namestring
);
3066 val
= allocate_misc ();
3067 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3068 XOBJFWD (val
)->objvar
= address
;
3069 XSYMBOL (sym
)->value
= val
;
3073 defvar_lisp (namestring
, address
)
3075 Lisp_Object
*address
;
3077 defvar_lisp_nopro (namestring
, address
);
3078 staticpro (address
);
3083 /* Similar but define a variable whose value is the Lisp Object stored in
3084 the current buffer. address is the address of the slot in the buffer
3085 that is current now. */
3088 defvar_per_buffer (namestring
, address
, type
, doc
)
3090 Lisp_Object
*address
;
3094 Lisp_Object sym
, val
;
3096 extern struct buffer buffer_local_symbols
;
3098 sym
= intern (namestring
);
3099 val
= allocate_misc ();
3100 offset
= (char *)address
- (char *)current_buffer
;
3102 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3103 XBUFFER_OBJFWD (val
)->offset
= offset
;
3104 XSYMBOL (sym
)->value
= val
;
3105 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
3106 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
3107 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
3108 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3109 slot of buffer_local_flags */
3113 #endif /* standalone */
3115 /* Similar but define a variable whose value is the Lisp Object stored
3116 at a particular offset in the current kboard object. */
3119 defvar_kboard (namestring
, offset
)
3123 Lisp_Object sym
, val
;
3124 sym
= intern (namestring
);
3125 val
= allocate_misc ();
3126 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3127 XKBOARD_OBJFWD (val
)->offset
= offset
;
3128 XSYMBOL (sym
)->value
= val
;
3131 /* Record the value of load-path used at the start of dumping
3132 so we can see if the site changed it later during dumping. */
3133 static Lisp_Object dump_path
;
3139 int turn_off_warning
= 0;
3141 /* Compute the default load-path. */
3143 normal
= PATH_LOADSEARCH
;
3144 Vload_path
= decode_env_path (0, normal
);
3146 if (NILP (Vpurify_flag
))
3147 normal
= PATH_LOADSEARCH
;
3149 normal
= PATH_DUMPLOADSEARCH
;
3151 /* In a dumped Emacs, we normally have to reset the value of
3152 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3153 uses ../lisp, instead of the path of the installed elisp
3154 libraries. However, if it appears that Vload_path was changed
3155 from the default before dumping, don't override that value. */
3158 if (! NILP (Fequal (dump_path
, Vload_path
)))
3160 Vload_path
= decode_env_path (0, normal
);
3161 if (!NILP (Vinstallation_directory
))
3163 /* Add to the path the lisp subdir of the
3164 installation dir, if it exists. */
3165 Lisp_Object tem
, tem1
;
3166 tem
= Fexpand_file_name (build_string ("lisp"),
3167 Vinstallation_directory
);
3168 tem1
= Ffile_exists_p (tem
);
3171 if (NILP (Fmember (tem
, Vload_path
)))
3173 turn_off_warning
= 1;
3174 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3178 /* That dir doesn't exist, so add the build-time
3179 Lisp dirs instead. */
3180 Vload_path
= nconc2 (Vload_path
, dump_path
);
3182 /* Add leim under the installation dir, if it exists. */
3183 tem
= Fexpand_file_name (build_string ("leim"),
3184 Vinstallation_directory
);
3185 tem1
= Ffile_exists_p (tem
);
3188 if (NILP (Fmember (tem
, Vload_path
)))
3189 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3192 /* Add site-list under the installation dir, if it exists. */
3193 tem
= Fexpand_file_name (build_string ("site-lisp"),
3194 Vinstallation_directory
);
3195 tem1
= Ffile_exists_p (tem
);
3198 if (NILP (Fmember (tem
, Vload_path
)))
3199 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3202 /* If Emacs was not built in the source directory,
3203 and it is run from where it was built, add to load-path
3204 the lisp, leim and site-lisp dirs under that directory. */
3206 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3210 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3211 Vinstallation_directory
);
3212 tem1
= Ffile_exists_p (tem
);
3214 /* Don't be fooled if they moved the entire source tree
3215 AFTER dumping Emacs. If the build directory is indeed
3216 different from the source dir, src/Makefile.in and
3217 src/Makefile will not be found together. */
3218 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3219 Vinstallation_directory
);
3220 tem2
= Ffile_exists_p (tem
);
3221 if (!NILP (tem1
) && NILP (tem2
))
3223 tem
= Fexpand_file_name (build_string ("lisp"),
3226 if (NILP (Fmember (tem
, Vload_path
)))
3227 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3229 tem
= Fexpand_file_name (build_string ("leim"),
3232 if (NILP (Fmember (tem
, Vload_path
)))
3233 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3235 tem
= Fexpand_file_name (build_string ("site-lisp"),
3238 if (NILP (Fmember (tem
, Vload_path
)))
3239 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3247 /* NORMAL refers to the lisp dir in the source directory. */
3248 /* We used to add ../lisp at the front here, but
3249 that caused trouble because it was copied from dump_path
3250 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3251 It should be unnecessary. */
3252 Vload_path
= decode_env_path (0, normal
);
3253 dump_path
= Vload_path
;
3258 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3259 almost never correct, thereby causing a warning to be printed out that
3260 confuses users. Since PATH_LOADSEARCH is always overridden by the
3261 EMACSLOADPATH environment variable below, disable the warning on NT. */
3263 /* Warn if dirs in the *standard* path don't exist. */
3264 if (!turn_off_warning
)
3266 Lisp_Object path_tail
;
3268 for (path_tail
= Vload_path
;
3270 path_tail
= XCDR (path_tail
))
3272 Lisp_Object dirfile
;
3273 dirfile
= Fcar (path_tail
);
3274 if (STRINGP (dirfile
))
3276 dirfile
= Fdirectory_file_name (dirfile
);
3277 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3278 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3283 #endif /* WINDOWSNT */
3285 /* If the EMACSLOADPATH environment variable is set, use its value.
3286 This doesn't apply if we're dumping. */
3288 if (NILP (Vpurify_flag
)
3289 && egetenv ("EMACSLOADPATH"))
3291 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3295 load_in_progress
= 0;
3296 Vload_file_name
= Qnil
;
3298 load_descriptor_list
= Qnil
;
3300 Vstandard_input
= Qt
;
3303 /* Print a warning, using format string FORMAT, that directory DIRNAME
3304 does not exist. Print it on stderr and put it in *Message*. */
3307 dir_warning (format
, dirname
)
3309 Lisp_Object dirname
;
3312 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3314 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3315 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3316 /* Don't log the warning before we've initialized!! */
3318 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3325 defsubr (&Sread_from_string
);
3327 defsubr (&Sintern_soft
);
3328 defsubr (&Sunintern
);
3330 defsubr (&Seval_buffer
);
3331 defsubr (&Seval_region
);
3332 defsubr (&Sread_char
);
3333 defsubr (&Sread_char_exclusive
);
3334 defsubr (&Sread_event
);
3335 defsubr (&Sget_file_char
);
3336 defsubr (&Smapatoms
);
3338 DEFVAR_LISP ("obarray", &Vobarray
,
3339 "Symbol table for use by `intern' and `read'.\n\
3340 It is a vector whose length ought to be prime for best results.\n\
3341 The vector's contents don't make sense if examined from Lisp programs;\n\
3342 to find all the symbols in an obarray, use `mapatoms'.");
3344 DEFVAR_LISP ("values", &Vvalues
,
3345 "List of values of all expressions which were read, evaluated and printed.\n\
3346 Order is reverse chronological.");
3348 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3349 "Stream for read to get input from.\n\
3350 See documentation of `read' for possible values.");
3351 Vstandard_input
= Qt
;
3353 DEFVAR_LISP ("load-path", &Vload_path
,
3354 "*List of directories to search for files to load.\n\
3355 Each element is a string (directory name) or nil (try default directory).\n\
3356 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3357 otherwise to default specified by file `epaths.h' when Emacs was built.");
3359 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3360 "Non-nil iff inside of `load'.");
3362 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3363 "An alist of expressions to be evalled when particular files are loaded.\n\
3364 Each element looks like (FILENAME FORMS...).\n\
3365 When `load' is run and the file-name argument is FILENAME,\n\
3366 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3367 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3368 with no directory specified, since that is how `load' is normally called.\n\
3369 An error in FORMS does not undo the load,\n\
3370 but does prevent execution of the rest of the FORMS.");
3371 Vafter_load_alist
= Qnil
;
3373 DEFVAR_LISP ("load-history", &Vload_history
,
3374 "Alist mapping source file names to symbols and features.\n\
3375 Each alist element is a list that starts with a file name,\n\
3376 except for one element (optional) that starts with nil and describes\n\
3377 definitions evaluated from buffers not visiting files.\n\
3378 The remaining elements of each list are symbols defined as functions\n\
3379 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3380 Vload_history
= Qnil
;
3382 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3383 "Full name of file being loaded by `load'.");
3384 Vload_file_name
= Qnil
;
3386 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3387 "File name, including directory, of user's initialization file.");
3388 Vuser_init_file
= Qnil
;
3390 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3391 "Used for internal purposes by `load'.");
3392 Vcurrent_load_list
= Qnil
;
3394 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3395 "Function used by `load' and `eval-region' for reading expressions.\n\
3396 The default is nil, which means use the function `read'.");
3397 Vload_read_function
= Qnil
;
3399 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3400 "Function called in `load' for loading an Emacs lisp source file.\n\
3401 This function is for doing code conversion before reading the source file.\n\
3402 If nil, loading is done without any code conversion.\n\
3403 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3404 FULLNAME is the full name of FILE.\n\
3405 See `load' for the meaning of the remaining arguments.");
3406 Vload_source_file_function
= Qnil
;
3408 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3409 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3410 This is useful when the file being loaded is a temporary copy.");
3411 load_force_doc_strings
= 0;
3413 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3414 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3415 This is normally used in `load-with-code-conversion'\n\
3416 for loading non-compiled files.");
3417 load_convert_to_unibyte
= 0;
3419 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3420 "Directory in which Emacs sources were found when Emacs was built.\n\
3421 You cannot count on them to still be there!");
3423 = Fexpand_file_name (build_string ("../"),
3424 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3426 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3427 "List of files that were preloaded (when dumping Emacs).");
3428 Vpreloaded_file_list
= Qnil
;
3430 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars
,
3431 "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
3432 Vbyte_boolean_vars
= Qnil
;
3434 /* Vsource_directory was initialized in init_lread. */
3436 load_descriptor_list
= Qnil
;
3437 staticpro (&load_descriptor_list
);
3439 Qcurrent_load_list
= intern ("current-load-list");
3440 staticpro (&Qcurrent_load_list
);
3442 Qstandard_input
= intern ("standard-input");
3443 staticpro (&Qstandard_input
);
3445 Qread_char
= intern ("read-char");
3446 staticpro (&Qread_char
);
3448 Qget_file_char
= intern ("get-file-char");
3449 staticpro (&Qget_file_char
);
3451 Qbackquote
= intern ("`");
3452 staticpro (&Qbackquote
);
3453 Qcomma
= intern (",");
3454 staticpro (&Qcomma
);
3455 Qcomma_at
= intern (",@");
3456 staticpro (&Qcomma_at
);
3457 Qcomma_dot
= intern (",.");
3458 staticpro (&Qcomma_dot
);
3460 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3461 staticpro (&Qinhibit_file_name_operation
);
3463 Qascii_character
= intern ("ascii-character");
3464 staticpro (&Qascii_character
);
3466 Qfunction
= intern ("function");
3467 staticpro (&Qfunction
);
3469 Qload
= intern ("load");
3472 Qload_file_name
= intern ("load-file-name");
3473 staticpro (&Qload_file_name
);
3475 staticpro (&dump_path
);
3477 staticpro (&read_objects
);
3478 read_objects
= Qnil
;
3479 staticpro (&seen_list
);