1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include <sys/types.h>
37 #include "termhooks.h"
41 #include <sys/inode.h>
46 #include <unistd.h> /* to get X_OK */
59 #ifdef LISP_FLOAT_TYPE
65 #endif /* LISP_FLOAT_TYPE */
69 #endif /* HAVE_SETLOCALE */
77 Lisp_Object Qread_char
, Qget_file_char
, Qstandard_input
, Qcurrent_load_list
;
78 Lisp_Object Qvariable_documentation
, Vvalues
, Vstandard_input
, Vafter_load_alist
;
79 Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
80 Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
81 Lisp_Object Qinhibit_file_name_operation
;
83 extern Lisp_Object Qevent_symbol_element_mask
;
84 extern Lisp_Object Qfile_exists_p
;
86 /* non-zero if inside `load' */
89 /* Directory in which the sources were found. */
90 Lisp_Object Vsource_directory
;
92 /* Search path for files to be loaded. */
93 Lisp_Object Vload_path
;
95 /* File name of user's init file. */
96 Lisp_Object Vuser_init_file
;
98 /* This is the user-visible association list that maps features to
99 lists of defs in their load files. */
100 Lisp_Object Vload_history
;
102 /* This is used to build the load history. */
103 Lisp_Object Vcurrent_load_list
;
105 /* List of files that were preloaded. */
106 Lisp_Object Vpreloaded_file_list
;
108 /* Name of file actually being read by `load'. */
109 Lisp_Object Vload_file_name
;
111 /* Function to use for reading, in `load' and friends. */
112 Lisp_Object Vload_read_function
;
114 /* The association list of objects read with the #n=object form.
115 Each member of the list has the form (n . object), and is used to
116 look up the object for the corresponding #n# construct.
117 It must be set to nil before all top-level calls to read0. */
118 Lisp_Object read_objects
;
120 /* Nonzero means load should forcibly load all dynamic doc strings. */
121 static int load_force_doc_strings
;
123 /* Nonzero means read should convert strings to unibyte. */
124 static int load_convert_to_unibyte
;
126 /* Function to use for loading an Emacs lisp source file (not
127 compiled) instead of readevalloop. */
128 Lisp_Object Vload_source_file_function
;
130 /* List of descriptors now open for Fload. */
131 static Lisp_Object load_descriptor_list
;
133 /* File for get_file_char to read from. Use by load. */
134 static FILE *instream
;
136 /* When nonzero, read conses in pure space */
137 static int read_pure
;
139 /* For use within read-from-string (this reader is non-reentrant!!) */
140 static int read_from_string_index
;
141 static int read_from_string_index_byte
;
142 static int read_from_string_limit
;
144 /* Number of bytes left to read in the buffer character
145 that `readchar' has already advanced over. */
146 static int readchar_backlog
;
148 /* This contains the last string skipped with #@. */
149 static char *saved_doc_string
;
150 /* Length of buffer allocated in saved_doc_string. */
151 static int saved_doc_string_size
;
152 /* Length of actual data in saved_doc_string. */
153 static int saved_doc_string_length
;
154 /* This is the file position that string came from. */
155 static int saved_doc_string_position
;
157 /* This contains the previous string skipped with #@.
158 We copy it from saved_doc_string when a new string
159 is put in saved_doc_string. */
160 static char *prev_saved_doc_string
;
161 /* Length of buffer allocated in prev_saved_doc_string. */
162 static int prev_saved_doc_string_size
;
163 /* Length of actual data in prev_saved_doc_string. */
164 static int prev_saved_doc_string_length
;
165 /* This is the file position that string came from. */
166 static int prev_saved_doc_string_position
;
168 /* Nonzero means inside a new-style backquote
169 with no surrounding parentheses.
170 Fread initializes this to zero, so we need not specbind it
171 or worry about what happens to it when there is an error. */
172 static int new_backquote_flag
;
174 /* Handle unreading and rereading of characters.
175 Write READCHAR to read a character,
176 UNREAD(c) to unread c to be read again.
178 These macros actually read/unread a byte code, multibyte characters
179 are not handled here. The caller should manage them if necessary.
182 #define READCHAR readchar (readcharfun)
183 #define UNREAD(c) unreadchar (readcharfun, c)
186 readchar (readcharfun
)
187 Lisp_Object readcharfun
;
190 register int c
, mpos
;
192 if (BUFFERP (readcharfun
))
194 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
196 int pt_byte
= BUF_PT_BYTE (inbuffer
);
197 int orig_pt_byte
= pt_byte
;
199 if (readchar_backlog
> 0)
200 /* We get the address of the byte just passed,
201 which is the last byte of the character.
202 The other bytes in this character are consecutive with it,
203 because the gap can't be in the middle of a character. */
204 return *(BUF_BYTE_ADDRESS (inbuffer
, BUF_PT_BYTE (inbuffer
) - 1)
205 - --readchar_backlog
);
207 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
210 readchar_backlog
= -1;
212 if (! NILP (inbuffer
->enable_multibyte_characters
))
214 unsigned char workbuf
[4];
215 unsigned char *str
= workbuf
;
218 /* Fetch the character code from the buffer. */
219 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
220 BUF_INC_POS (inbuffer
, pt_byte
);
221 c
= STRING_CHAR (p
, pt_byte
- orig_pt_byte
);
223 /* Find the byte-sequence representation of that character. */
224 if (SINGLE_BYTE_CHAR_P (c
))
225 length
= 1, workbuf
[0] = c
;
227 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
229 /* If the bytes for this character in the buffer
230 are not identical with what the character code implies,
231 read the bytes one by one from the buffer. */
232 if (length
!= pt_byte
- orig_pt_byte
233 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
235 readchar_backlog
= pt_byte
- orig_pt_byte
;
236 c
= BUF_FETCH_BYTE (inbuffer
, orig_pt_byte
);
242 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
245 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
249 if (MARKERP (readcharfun
))
251 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
253 int bytepos
= marker_byte_position (readcharfun
);
254 int orig_bytepos
= bytepos
;
256 if (readchar_backlog
> 0)
257 /* We get the address of the byte just passed,
258 which is the last byte of the character.
259 The other bytes in this character are consecutive with it,
260 because the gap can't be in the middle of a character. */
261 return *(BUF_BYTE_ADDRESS (inbuffer
, XMARKER (readcharfun
)->bytepos
- 1)
262 - --readchar_backlog
);
264 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
267 readchar_backlog
= -1;
269 if (! NILP (inbuffer
->enable_multibyte_characters
))
271 unsigned char workbuf
[4];
272 unsigned char *str
= workbuf
;
275 /* Fetch the character code from the buffer. */
276 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
277 BUF_INC_POS (inbuffer
, bytepos
);
278 c
= STRING_CHAR (p
, bytepos
- orig_bytepos
);
280 /* Find the byte-sequence representation of that character. */
281 if (SINGLE_BYTE_CHAR_P (c
))
282 length
= 1, workbuf
[0] = c
;
284 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
286 /* If the bytes for this character in the buffer
287 are not identical with what the character code implies,
288 read the bytes one by one from the buffer. */
289 if (length
!= bytepos
- orig_bytepos
290 || (length
== 1 ? *str
!= *p
: bcmp (str
, p
, length
)))
292 readchar_backlog
= bytepos
- orig_bytepos
;
293 c
= BUF_FETCH_BYTE (inbuffer
, orig_bytepos
);
299 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
303 XMARKER (readcharfun
)->bytepos
= bytepos
;
304 XMARKER (readcharfun
)->charpos
++;
309 if (EQ (readcharfun
, Qlambda
))
310 return read_bytecode_char (0);
312 if (EQ (readcharfun
, Qget_file_char
))
316 /* Interrupted reads have been observed while reading over the network */
317 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
326 if (STRINGP (readcharfun
))
328 if (read_from_string_index
>= read_from_string_limit
)
330 else if (STRING_MULTIBYTE (readcharfun
))
331 FETCH_STRING_CHAR_ADVANCE (c
, readcharfun
,
332 read_from_string_index
,
333 read_from_string_index_byte
);
335 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
340 tem
= call0 (readcharfun
);
347 /* Unread the character C in the way appropriate for the stream READCHARFUN.
348 If the stream is a user function, call it with the char as argument. */
351 unreadchar (readcharfun
, c
)
352 Lisp_Object readcharfun
;
356 /* Don't back up the pointer if we're unreading the end-of-input mark,
357 since readchar didn't advance it when we read it. */
359 else if (BUFFERP (readcharfun
))
361 struct buffer
*b
= XBUFFER (readcharfun
);
362 int bytepos
= BUF_PT_BYTE (b
);
364 if (readchar_backlog
>= 0)
369 if (! NILP (b
->enable_multibyte_characters
))
370 BUF_DEC_POS (b
, bytepos
);
374 BUF_PT_BYTE (b
) = bytepos
;
377 else if (MARKERP (readcharfun
))
379 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
380 int bytepos
= XMARKER (readcharfun
)->bytepos
;
382 if (readchar_backlog
>= 0)
386 XMARKER (readcharfun
)->charpos
--;
387 if (! NILP (b
->enable_multibyte_characters
))
388 BUF_DEC_POS (b
, bytepos
);
392 XMARKER (readcharfun
)->bytepos
= bytepos
;
395 else if (STRINGP (readcharfun
))
397 read_from_string_index
--;
398 read_from_string_index_byte
399 = string_char_to_byte (readcharfun
, read_from_string_index
);
401 else if (EQ (readcharfun
, Qlambda
))
402 read_bytecode_char (1);
403 else if (EQ (readcharfun
, Qget_file_char
))
404 ungetc (c
, instream
);
406 call1 (readcharfun
, make_number (c
));
409 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
410 static int read_multibyte ();
411 static Lisp_Object
substitute_object_recurse ();
412 static void substitute_object_in_subtree (), substitute_in_interval ();
415 /* Get a character from the tty. */
417 extern Lisp_Object
read_char ();
419 /* Read input events until we get one that's acceptable for our purposes.
421 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
422 until we get a character we like, and then stuffed into
425 If ASCII_REQUIRED is non-zero, we check function key events to see
426 if the unmodified version of the symbol has a Qascii_character
427 property, and use that character, if present.
429 If ERROR_NONASCII is non-zero, we signal an error if the input we
430 get isn't an ASCII character with modifiers. If it's zero but
431 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
434 If INPUT_METHOD is nonzero, we invoke the current input method
435 if the character warrants that. */
438 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
440 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
443 return make_number (getchar ());
445 register Lisp_Object val
, delayed_switch_frame
;
447 delayed_switch_frame
= Qnil
;
449 /* Read until we get an acceptable event. */
451 val
= read_char (0, 0, 0,
452 (input_method
? Qnil
: Qt
),
458 /* switch-frame events are put off until after the next ASCII
459 character. This is better than signaling an error just because
460 the last characters were typed to a separate minibuffer frame,
461 for example. Eventually, some code which can deal with
462 switch-frame events will read it and process it. */
464 && EVENT_HAS_PARAMETERS (val
)
465 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
467 delayed_switch_frame
= val
;
473 /* Convert certain symbols to their ASCII equivalents. */
476 Lisp_Object tem
, tem1
, tem2
;
477 tem
= Fget (val
, Qevent_symbol_element_mask
);
480 tem1
= Fget (Fcar (tem
), Qascii_character
);
481 /* Merge this symbol's modifier bits
482 with the ASCII equivalent of its basic code. */
484 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
488 /* If we don't have a character now, deal with it appropriately. */
493 Vunread_command_events
= Fcons (val
, Qnil
);
494 error ("Non-character input-event");
501 if (! NILP (delayed_switch_frame
))
502 unread_switch_frame
= delayed_switch_frame
;
508 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 2, 0,
509 "Read a character from the command input (keyboard or macro).\n\
510 It is returned as a number.\n\
511 If the user generates an event which is not a character (i.e. a mouse\n\
512 click or function key event), `read-char' signals an error. As an\n\
513 exception, switch-frame events are put off until non-ASCII events can\n\
515 If you want to read non-character events, or ignore them, call\n\
516 `read-event' or `read-char-exclusive' instead.\n\
518 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
519 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
520 input method is turned on in the current buffer, that input method\n\
521 is used for reading a character.")
522 (prompt
, inherit_input_method
)
523 Lisp_Object prompt
, inherit_input_method
;
526 message_with_string ("%s", prompt
, 0);
527 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
));
530 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 2, 0,
531 "Read an event object from the input stream.\n\
532 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
533 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
534 input method is turned on in the current buffer, that input method\n\
535 is used for reading a character.")
536 (prompt
, inherit_input_method
)
537 Lisp_Object prompt
, inherit_input_method
;
540 message_with_string ("%s", prompt
, 0);
541 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
));
544 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 2, 0,
545 "Read a character from the command input (keyboard or macro).\n\
546 It is returned as a number. Non-character events are ignored.\n\
548 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
549 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
550 input method is turned on in the current buffer, that input method\n\
551 is used for reading a character.")
552 (prompt
, inherit_input_method
)
553 Lisp_Object prompt
, inherit_input_method
;
556 message_with_string ("%s", prompt
, 0);
557 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
));
560 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
561 "Don't use this yourself.")
564 register Lisp_Object val
;
565 XSETINT (val
, getc (instream
));
569 static void readevalloop ();
570 static Lisp_Object
load_unwind ();
571 static Lisp_Object
load_descriptor_unwind ();
573 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
574 "Execute a file of Lisp code named FILE.\n\
575 First try FILE with `.elc' appended, then try with `.el',\n\
576 then try FILE unmodified.\n\
577 This function searches the directories in `load-path'.\n\
578 If optional second arg NOERROR is non-nil,\n\
579 report no error if FILE doesn't exist.\n\
580 Print messages at start and end of loading unless\n\
581 optional third arg NOMESSAGE is non-nil.\n\
582 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
583 suffixes `.elc' or `.el' to the specified name FILE.\n\
584 If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
585 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
586 it ends in one of those suffixes or includes a directory name.\n\
587 Return t if file exists.")
588 (file
, noerror
, nomessage
, nosuffix
, must_suffix
)
589 Lisp_Object file
, noerror
, nomessage
, nosuffix
, must_suffix
;
591 register FILE *stream
;
592 register int fd
= -1;
593 register Lisp_Object lispstream
;
594 int count
= specpdl_ptr
- specpdl
;
598 /* 1 means we printed the ".el is newer" message. */
600 /* 1 means we are loading a compiled file. */
608 CHECK_STRING (file
, 0);
610 /* If file name is magic, call the handler. */
611 handler
= Ffind_file_name_handler (file
, Qload
);
613 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
615 /* Do this after the handler to avoid
616 the need to gcpro noerror, nomessage and nosuffix.
617 (Below here, we care only whether they are nil or not.) */
618 file
= Fsubstitute_in_file_name (file
);
620 /* Avoid weird lossage with null string as arg,
621 since it would try to load a directory as a Lisp file */
622 if (XSTRING (file
)->size
> 0)
624 int size
= XSTRING (file
)->size
;
628 if (! NILP (must_suffix
))
630 /* Don't insist on adding a suffix if FILE already ends with one. */
632 && !strcmp (XSTRING (file
)->data
+ size
- 3, ".el"))
635 && !strcmp (XSTRING (file
)->data
+ size
- 4, ".elc"))
637 /* Don't insist on adding a suffix
638 if the argument includes a directory name. */
639 else if (! NILP (Ffile_name_directory (file
)))
643 fd
= openp (Vload_path
, file
,
644 (!NILP (nosuffix
) ? ""
645 : ! NILP (must_suffix
) ? ".elc:.el"
655 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
656 Fcons (file
, Qnil
)));
661 if (EQ (Qt
, Vuser_init_file
))
662 Vuser_init_file
= found
;
664 /* If FD is 0, that means openp found a magic file. */
667 if (NILP (Fequal (found
, file
)))
668 /* If FOUND is a different file name from FILE,
669 find its handler even if we have already inhibited
670 the `load' operation on FILE. */
671 handler
= Ffind_file_name_handler (found
, Qt
);
673 handler
= Ffind_file_name_handler (found
, Qload
);
674 if (! NILP (handler
))
675 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
678 /* Load .elc files directly, but not when they are
679 remote and have no handler! */
680 if (!bcmp (&(XSTRING (found
)->data
[XSTRING (found
)->size
- 4]),
692 stat ((char *)XSTRING (found
)->data
, &s1
);
693 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 0;
694 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
695 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
697 /* Make the progress messages mention that source is newer. */
700 /* If we won't print another message, mention this anyway. */
701 if (! NILP (nomessage
))
702 message_with_string ("Source file `%s' newer than byte-compiled file",
705 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 'c';
709 /* We are loading a source file (*.el). */
710 if (!NILP (Vload_source_file_function
))
714 return call4 (Vload_source_file_function
, found
, file
,
715 NILP (noerror
) ? Qnil
: Qt
,
716 NILP (nomessage
) ? Qnil
: Qt
);
722 stream
= fopen ((char *) XSTRING (found
)->data
, fmode
);
723 #else /* not WINDOWSNT */
724 stream
= fdopen (fd
, fmode
);
725 #endif /* not WINDOWSNT */
729 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
732 if (! NILP (Vpurify_flag
))
733 Vpreloaded_file_list
= Fcons (file
, Vpreloaded_file_list
);
735 if (NILP (nomessage
))
738 message_with_string ("Loading %s (source)...", file
, 1);
740 message_with_string ("Loading %s (compiled; note, source file is newer)...",
742 else /* The typical case; compiled file newer than source file. */
743 message_with_string ("Loading %s...", file
, 1);
747 lispstream
= Fcons (Qnil
, Qnil
);
748 XSETFASTINT (XCONS (lispstream
)->car
, (EMACS_UINT
)stream
>> 16);
749 XSETFASTINT (XCONS (lispstream
)->cdr
, (EMACS_UINT
)stream
& 0xffff);
750 record_unwind_protect (load_unwind
, lispstream
);
751 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
752 specbind (Qload_file_name
, found
);
753 specbind (Qinhibit_file_name_operation
, Qnil
);
755 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
757 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0, Qnil
, Qnil
);
758 unbind_to (count
, Qnil
);
760 /* Run any load-hooks for this file. */
761 temp
= Fassoc (file
, Vafter_load_alist
);
763 Fprogn (Fcdr (temp
));
766 if (saved_doc_string
)
767 free (saved_doc_string
);
768 saved_doc_string
= 0;
769 saved_doc_string_size
= 0;
771 if (prev_saved_doc_string
)
772 free (prev_saved_doc_string
);
773 prev_saved_doc_string
= 0;
774 prev_saved_doc_string_size
= 0;
776 if (!noninteractive
&& NILP (nomessage
))
779 message_with_string ("Loading %s (source)...done", file
, 1);
781 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
783 else /* The typical case; compiled file newer than source file. */
784 message_with_string ("Loading %s...done", file
, 1);
790 load_unwind (stream
) /* used as unwind-protect function in load */
793 fclose ((FILE *) (XFASTINT (XCONS (stream
)->car
) << 16
794 | XFASTINT (XCONS (stream
)->cdr
)));
795 if (--load_in_progress
< 0) load_in_progress
= 0;
800 load_descriptor_unwind (oldlist
)
803 load_descriptor_list
= oldlist
;
807 /* Close all descriptors in use for Floads.
808 This is used when starting a subprocess. */
815 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
816 close (XFASTINT (XCONS (tail
)->car
));
821 complete_filename_p (pathname
)
822 Lisp_Object pathname
;
824 register unsigned char *s
= XSTRING (pathname
)->data
;
825 return (IS_DIRECTORY_SEP (s
[0])
826 || (XSTRING (pathname
)->size
> 2
827 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
837 /* Search for a file whose name is STR, looking in directories
838 in the Lisp list PATH, and trying suffixes from SUFFIX.
839 SUFFIX is a string containing possible suffixes separated by colons.
840 On success, returns a file descriptor. On failure, returns -1.
842 EXEC_ONLY nonzero means don't open the files,
843 just look for one that is executable. In this case,
844 returns 1 on success.
846 If STOREPTR is nonzero, it points to a slot where the name of
847 the file actually found should be stored as a Lisp string.
848 nil is stored there on failure.
850 If the file we find is remote, return 0
851 but store the found remote file name in *STOREPTR.
852 We do not check for remote files if EXEC_ONLY is nonzero. */
855 openp (path
, str
, suffix
, storeptr
, exec_only
)
856 Lisp_Object path
, str
;
858 Lisp_Object
*storeptr
;
864 register char *fn
= buf
;
867 Lisp_Object filename
;
875 if (complete_filename_p (str
))
878 for (; !NILP (path
); path
= Fcdr (path
))
882 filename
= Fexpand_file_name (str
, Fcar (path
));
883 if (!complete_filename_p (filename
))
884 /* If there are non-absolute elts in PATH (eg ".") */
885 /* Of course, this could conceivably lose if luser sets
886 default-directory to be something non-absolute... */
888 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
889 if (!complete_filename_p (filename
))
890 /* Give up on this path element! */
894 /* Calculate maximum size of any filename made from
895 this path element/specified file name and any possible suffix. */
896 want_size
= strlen (suffix
) + XSTRING (filename
)->size
+ 1;
897 if (fn_size
< want_size
)
898 fn
= (char *) alloca (fn_size
= 100 + want_size
);
902 /* Loop over suffixes. */
905 char *esuffix
= (char *) index (nsuffix
, ':');
906 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
909 /* Concatenate path element/specified name with the suffix.
910 If the directory starts with /:, remove that. */
911 if (XSTRING (filename
)->size
> 2
912 && XSTRING (filename
)->data
[0] == '/'
913 && XSTRING (filename
)->data
[1] == ':')
915 strncpy (fn
, XSTRING (filename
)->data
+ 2,
916 XSTRING (filename
)->size
- 2);
917 fn
[XSTRING (filename
)->size
- 2] = 0;
921 strncpy (fn
, XSTRING (filename
)->data
, XSTRING (filename
)->size
);
922 fn
[XSTRING (filename
)->size
] = 0;
925 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
926 strncat (fn
, nsuffix
, lsuffix
);
928 /* Check that the file exists and is not a directory. */
932 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
933 if (! NILP (handler
) && ! exec_only
)
938 string
= build_string (fn
);
939 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
940 : Ffile_readable_p (string
));
942 && ! NILP (Ffile_directory_p (build_string (fn
))))
947 /* We succeeded; return this descriptor and filename. */
949 *storeptr
= build_string (fn
);
956 int exists
= (stat (fn
, &st
) >= 0
957 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
960 /* Check that we can access or open it. */
962 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
964 fd
= open (fn
, O_RDONLY
, 0);
968 /* We succeeded; return this descriptor and filename. */
970 *storeptr
= build_string (fn
);
977 /* Advance to next suffix. */
980 nsuffix
+= lsuffix
+ 1;
991 /* Merge the list we've accumulated of globals from the current input source
992 into the load_history variable. The details depend on whether
993 the source has an associated file name or not. */
996 build_load_history (stream
, source
)
1000 register Lisp_Object tail
, prev
, newelt
;
1001 register Lisp_Object tem
, tem2
;
1002 register int foundit
, loading
;
1004 loading
= stream
|| !NARROWED
;
1006 tail
= Vload_history
;
1009 while (!NILP (tail
))
1013 /* Find the feature's previous assoc list... */
1014 if (!NILP (Fequal (source
, Fcar (tem
))))
1018 /* If we're loading, remove it. */
1022 Vload_history
= Fcdr (tail
);
1024 Fsetcdr (prev
, Fcdr (tail
));
1027 /* Otherwise, cons on new symbols that are not already members. */
1030 tem2
= Vcurrent_load_list
;
1032 while (CONSP (tem2
))
1034 newelt
= Fcar (tem2
);
1036 if (NILP (Fmemq (newelt
, tem
)))
1037 Fsetcar (tail
, Fcons (Fcar (tem
),
1038 Fcons (newelt
, Fcdr (tem
))));
1051 /* If we're loading, cons the new assoc onto the front of load-history,
1052 the most-recently-loaded position. Also do this if we didn't find
1053 an existing member for the current source. */
1054 if (loading
|| !foundit
)
1055 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1060 unreadpure () /* Used as unwind-protect function in readevalloop */
1067 readevalloop_1 (old
)
1070 load_convert_to_unibyte
= ! NILP (old
);
1074 /* UNIBYTE specifies how to set load_convert_to_unibyte
1075 for this invocation.
1076 READFUN, if non-nil, is used instead of `read'. */
1079 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
, unibyte
, readfun
)
1080 Lisp_Object readcharfun
;
1082 Lisp_Object sourcename
;
1083 Lisp_Object (*evalfun
) ();
1085 Lisp_Object unibyte
, readfun
;
1088 register Lisp_Object val
;
1089 int count
= specpdl_ptr
- specpdl
;
1090 struct gcpro gcpro1
;
1091 struct buffer
*b
= 0;
1093 if (BUFFERP (readcharfun
))
1094 b
= XBUFFER (readcharfun
);
1095 else if (MARKERP (readcharfun
))
1096 b
= XMARKER (readcharfun
)->buffer
;
1098 specbind (Qstandard_input
, readcharfun
);
1099 specbind (Qcurrent_load_list
, Qnil
);
1100 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1101 load_convert_to_unibyte
= !NILP (unibyte
);
1103 readchar_backlog
= -1;
1105 GCPRO1 (sourcename
);
1107 LOADHIST_ATTACH (sourcename
);
1111 if (b
!= 0 && NILP (b
->name
))
1112 error ("Reading from killed buffer");
1118 while ((c
= READCHAR
) != '\n' && c
!= -1);
1123 /* Ignore whitespace here, so we can detect eof. */
1124 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
1127 if (!NILP (Vpurify_flag
) && c
== '(')
1129 int count1
= specpdl_ptr
- specpdl
;
1130 record_unwind_protect (unreadpure
, Qnil
);
1131 val
= read_list (-1, readcharfun
);
1132 unbind_to (count1
, Qnil
);
1137 read_objects
= Qnil
;
1138 if (! NILP (readfun
))
1139 val
= call1 (readfun
, readcharfun
);
1140 else if (! NILP (Vload_read_function
))
1141 val
= call1 (Vload_read_function
, readcharfun
);
1143 val
= read0 (readcharfun
);
1146 val
= (*evalfun
) (val
);
1149 Vvalues
= Fcons (val
, Vvalues
);
1150 if (EQ (Vstandard_output
, Qt
))
1157 build_load_history (stream
, sourcename
);
1160 unbind_to (count
, Qnil
);
1165 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1166 "Execute the current buffer as Lisp code.\n\
1167 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1168 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1169 PRINTFLAG controls printing of output:\n\
1170 nil means discard it; anything else is stream for print.\n\
1172 If the optional third argument FILENAME is non-nil,\n\
1173 it specifies the file name to use for `load-history'.\n\
1174 The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
1175 for this invocation.\n\
1177 The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
1178 `print' and related functions should work normally even if PRINTFLAG is nil.\n\
1180 This function preserves the position of point.")
1181 (buffer
, printflag
, filename
, unibyte
, do_allow_print
)
1182 Lisp_Object buffer
, printflag
, filename
, unibyte
, do_allow_print
;
1184 int count
= specpdl_ptr
- specpdl
;
1185 Lisp_Object tem
, buf
;
1188 buf
= Fcurrent_buffer ();
1190 buf
= Fget_buffer (buffer
);
1192 error ("No such buffer");
1194 if (NILP (printflag
) && NILP (do_allow_print
))
1199 if (NILP (filename
))
1200 filename
= XBUFFER (buf
)->filename
;
1202 specbind (Qstandard_output
, tem
);
1203 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1204 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1205 readevalloop (buf
, 0, filename
, Feval
, !NILP (printflag
), unibyte
, Qnil
);
1206 unbind_to (count
, Qnil
);
1212 XDEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
1213 "Execute the current buffer as Lisp code.\n\
1214 Programs can pass argument PRINTFLAG which controls printing of output:\n\
1215 nil means discard it; anything else is stream for print.\n\
1217 If there is no error, point does not move. If there is an error,\n\
1218 point remains at the end of the last character read from the buffer.")
1220 Lisp_Object printflag
;
1222 int count
= specpdl_ptr
- specpdl
;
1223 Lisp_Object tem
, cbuf
;
1225 cbuf
= Fcurrent_buffer ()
1227 if (NILP (printflag
))
1231 specbind (Qstandard_output
, tem
);
1232 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1234 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1235 !NILP (printflag
), Qnil
, Qnil
);
1236 return unbind_to (count
, Qnil
);
1240 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1241 "Execute the region as Lisp code.\n\
1242 When called from programs, expects two arguments,\n\
1243 giving starting and ending indices in the current buffer\n\
1244 of the text to be executed.\n\
1245 Programs can pass third argument PRINTFLAG which controls output:\n\
1246 nil means discard it; anything else is stream for printing it.\n\
1247 Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1248 instead of `read' to read each expression. It gets one argument\n\
1249 which is the input stream for reading characters.\n\
1251 This function does not move point.")
1252 (start
, end
, printflag
, read_function
)
1253 Lisp_Object start
, end
, printflag
, read_function
;
1255 int count
= specpdl_ptr
- specpdl
;
1256 Lisp_Object tem
, cbuf
;
1258 cbuf
= Fcurrent_buffer ();
1260 if (NILP (printflag
))
1264 specbind (Qstandard_output
, tem
);
1266 if (NILP (printflag
))
1267 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1268 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1270 /* This both uses start and checks its type. */
1272 Fnarrow_to_region (make_number (BEGV
), end
);
1273 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1274 !NILP (printflag
), Qnil
, read_function
);
1276 return unbind_to (count
, Qnil
);
1279 #endif /* standalone */
1281 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1282 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1283 If STREAM is nil, use the value of `standard-input' (which see).\n\
1284 STREAM or the value of `standard-input' may be:\n\
1285 a buffer (read from point and advance it)\n\
1286 a marker (read from where it points and advance it)\n\
1287 a function (call it with no arguments for each character,\n\
1288 call it with a char as argument to push a char back)\n\
1289 a string (takes text from string, starting at the beginning)\n\
1290 t (read text line using minibuffer and use it).")
1294 extern Lisp_Object
Fread_minibuffer ();
1297 stream
= Vstandard_input
;
1298 if (EQ (stream
, Qt
))
1299 stream
= Qread_char
;
1301 readchar_backlog
= -1;
1302 new_backquote_flag
= 0;
1303 read_objects
= Qnil
;
1306 if (EQ (stream
, Qread_char
))
1307 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1310 if (STRINGP (stream
))
1311 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1313 return read0 (stream
);
1316 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1317 "Read one Lisp expression which is represented as text by STRING.\n\
1318 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1319 START and END optionally delimit a substring of STRING from which to read;\n\
1320 they default to 0 and (length STRING) respectively.")
1321 (string
, start
, end
)
1322 Lisp_Object string
, start
, end
;
1324 int startval
, endval
;
1327 CHECK_STRING (string
,0);
1330 endval
= XSTRING (string
)->size
;
1333 CHECK_NUMBER (end
, 2);
1334 endval
= XINT (end
);
1335 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1336 args_out_of_range (string
, end
);
1343 CHECK_NUMBER (start
, 1);
1344 startval
= XINT (start
);
1345 if (startval
< 0 || startval
> endval
)
1346 args_out_of_range (string
, start
);
1349 read_from_string_index
= startval
;
1350 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1351 read_from_string_limit
= endval
;
1353 new_backquote_flag
= 0;
1354 read_objects
= Qnil
;
1356 tem
= read0 (string
);
1357 return Fcons (tem
, make_number (read_from_string_index
));
1360 /* Use this for recursive reads, in contexts where internal tokens
1365 Lisp_Object readcharfun
;
1367 register Lisp_Object val
;
1370 val
= read1 (readcharfun
, &c
, 0);
1372 Fsignal (Qinvalid_read_syntax
, Fcons (Fmake_string (make_number (1),
1379 static int read_buffer_size
;
1380 static char *read_buffer
;
1382 /* Read multibyte form and return it as a character. C is a first
1383 byte of multibyte form, and rest of them are read from
1387 read_multibyte (c
, readcharfun
)
1389 Lisp_Object readcharfun
;
1391 /* We need the actual character code of this multibyte
1393 unsigned char str
[MAX_LENGTH_OF_MULTI_BYTE_FORM
];
1397 while ((c
= READCHAR
) >= 0xA0
1398 && len
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1401 return STRING_CHAR (str
, len
);
1404 /* Read a \-escape sequence, assuming we already read the `\'. */
1407 read_escape (readcharfun
, stringp
)
1408 Lisp_Object readcharfun
;
1411 register int c
= READCHAR
;
1415 error ("End of file");
1445 error ("Invalid escape character syntax");
1448 c
= read_escape (readcharfun
, 0);
1449 return c
| meta_modifier
;
1454 error ("Invalid escape character syntax");
1457 c
= read_escape (readcharfun
, 0);
1458 return c
| shift_modifier
;
1463 error ("Invalid escape character syntax");
1466 c
= read_escape (readcharfun
, 0);
1467 return c
| hyper_modifier
;
1472 error ("Invalid escape character syntax");
1475 c
= read_escape (readcharfun
, 0);
1476 return c
| alt_modifier
;
1481 error ("Invalid escape character syntax");
1484 c
= read_escape (readcharfun
, 0);
1485 return c
| super_modifier
;
1490 error ("Invalid escape character syntax");
1494 c
= read_escape (readcharfun
, 0);
1495 if ((c
& 0177) == '?')
1497 /* ASCII control chars are made from letters (both cases),
1498 as well as the non-letters within 0100...0137. */
1499 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1500 return (c
& (037 | ~0177));
1501 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1502 return (c
& (037 | ~0177));
1504 return c
| ctrl_modifier
;
1514 /* An octal escape, as in ANSI C. */
1516 register int i
= c
- '0';
1517 register int count
= 0;
1520 if ((c
= READCHAR
) >= '0' && c
<= '7')
1535 /* A hex escape, as in ANSI C. */
1541 if (c
>= '0' && c
<= '9')
1546 else if ((c
>= 'a' && c
<= 'f')
1547 || (c
>= 'A' && c
<= 'F'))
1550 if (c
>= 'a' && c
<= 'f')
1565 if (BASE_LEADING_CODE_P (c
))
1566 c
= read_multibyte (c
, readcharfun
);
1571 /* If the next token is ')' or ']' or '.', we store that character
1572 in *PCH and the return value is not interesting. Else, we store
1573 zero in *PCH and we read and return one lisp object.
1575 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1578 read1 (readcharfun
, pch
, first_in_list
)
1579 register Lisp_Object readcharfun
;
1584 int uninterned_symbol
= 0;
1591 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1596 return read_list (0, readcharfun
);
1599 return read_vector (readcharfun
, 0);
1616 tmp
= read_vector (readcharfun
, 0);
1617 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1618 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1619 error ("Invalid size char-table");
1620 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1621 XCHAR_TABLE (tmp
)->top
= Qt
;
1630 tmp
= read_vector (readcharfun
, 0);
1631 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1632 error ("Invalid size char-table");
1633 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1634 XCHAR_TABLE (tmp
)->top
= Qnil
;
1637 Fsignal (Qinvalid_read_syntax
,
1638 Fcons (make_string ("#^^", 3), Qnil
));
1640 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1645 length
= read1 (readcharfun
, pch
, first_in_list
);
1649 Lisp_Object tmp
, val
;
1650 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1654 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1655 if (size_in_chars
!= XSTRING (tmp
)->size
1656 /* We used to print 1 char too many
1657 when the number of bits was a multiple of 8.
1658 Accept such input in case it came from an old version. */
1659 && ! (XFASTINT (length
)
1660 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1661 Fsignal (Qinvalid_read_syntax
,
1662 Fcons (make_string ("#&...", 5), Qnil
));
1664 val
= Fmake_bool_vector (length
, Qnil
);
1665 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1667 /* Clear the extraneous bits in the last byte. */
1668 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1669 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1670 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1673 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1678 /* Accept compiled functions at read-time so that we don't have to
1679 build them using function calls. */
1681 tmp
= read_vector (readcharfun
, 1);
1682 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1683 XVECTOR (tmp
)->contents
);
1685 #ifdef USE_TEXT_PROPERTIES
1689 struct gcpro gcpro1
;
1692 /* Read the string itself. */
1693 tmp
= read1 (readcharfun
, &ch
, 0);
1694 if (ch
!= 0 || !STRINGP (tmp
))
1695 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1697 /* Read the intervals and their properties. */
1700 Lisp_Object beg
, end
, plist
;
1702 beg
= read1 (readcharfun
, &ch
, 0);
1706 end
= read1 (readcharfun
, &ch
, 0);
1708 plist
= read1 (readcharfun
, &ch
, 0);
1710 Fsignal (Qinvalid_read_syntax
,
1711 Fcons (build_string ("invalid string property list"),
1713 Fset_text_properties (beg
, end
, plist
, tmp
);
1719 /* #@NUMBER is used to skip NUMBER following characters.
1720 That's used in .elc files to skip over doc strings
1721 and function definitions. */
1726 /* Read a decimal integer. */
1727 while ((c
= READCHAR
) >= 0
1728 && c
>= '0' && c
<= '9')
1736 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1738 /* If we are supposed to force doc strings into core right now,
1739 record the last string that we skipped,
1740 and record where in the file it comes from. */
1742 /* But first exchange saved_doc_string
1743 with prev_saved_doc_string, so we save two strings. */
1745 char *temp
= saved_doc_string
;
1746 int temp_size
= saved_doc_string_size
;
1747 int temp_pos
= saved_doc_string_position
;
1748 int temp_len
= saved_doc_string_length
;
1750 saved_doc_string
= prev_saved_doc_string
;
1751 saved_doc_string_size
= prev_saved_doc_string_size
;
1752 saved_doc_string_position
= prev_saved_doc_string_position
;
1753 saved_doc_string_length
= prev_saved_doc_string_length
;
1755 prev_saved_doc_string
= temp
;
1756 prev_saved_doc_string_size
= temp_size
;
1757 prev_saved_doc_string_position
= temp_pos
;
1758 prev_saved_doc_string_length
= temp_len
;
1761 if (saved_doc_string_size
== 0)
1763 saved_doc_string_size
= nskip
+ 100;
1764 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1766 if (nskip
> saved_doc_string_size
)
1768 saved_doc_string_size
= nskip
+ 100;
1769 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1770 saved_doc_string_size
);
1773 saved_doc_string_position
= ftell (instream
);
1775 /* Copy that many characters into saved_doc_string. */
1776 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1777 saved_doc_string
[i
] = c
= READCHAR
;
1779 saved_doc_string_length
= i
;
1783 /* Skip that many characters. */
1784 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1791 return Vload_file_name
;
1793 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1794 /* #:foo is the uninterned symbol named foo. */
1797 uninterned_symbol
= 1;
1801 /* Reader forms that can reuse previously read objects. */
1802 if (c
>= '0' && c
<= '9')
1807 /* Read a non-negative integer. */
1808 while (c
>= '0' && c
<= '9')
1814 /* #n=object returns object, but associates it with n for #n#. */
1817 /* Make a placeholder for #n# to use temporarily */
1818 Lisp_Object placeholder
;
1821 placeholder
= Fcons(Qnil
, Qnil
);
1822 cell
= Fcons (make_number (n
), placeholder
);
1823 read_objects
= Fcons (cell
, read_objects
);
1825 /* Read the object itself. */
1826 tem
= read0 (readcharfun
);
1828 /* Now put it everywhere the placeholder was... */
1829 substitute_object_in_subtree (tem
, placeholder
);
1831 /* ...and #n# will use the real value from now on. */
1832 Fsetcdr (cell
, tem
);
1836 /* #n# returns a previously read object. */
1839 tem
= Fassq (make_number (n
), read_objects
);
1842 /* Fall through to error message. */
1844 /* Fall through to error message. */
1848 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1851 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1856 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1866 new_backquote_flag
= 1;
1867 value
= read0 (readcharfun
);
1868 new_backquote_flag
= 0;
1870 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1874 if (new_backquote_flag
)
1876 Lisp_Object comma_type
= Qnil
;
1881 comma_type
= Qcomma_at
;
1883 comma_type
= Qcomma_dot
;
1886 if (ch
>= 0) UNREAD (ch
);
1887 comma_type
= Qcomma
;
1890 new_backquote_flag
= 0;
1891 value
= read0 (readcharfun
);
1892 new_backquote_flag
= 1;
1893 return Fcons (comma_type
, Fcons (value
, Qnil
));
1900 register Lisp_Object val
;
1903 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1906 c
= read_escape (readcharfun
, 0);
1907 else if (BASE_LEADING_CODE_P (c
))
1908 c
= read_multibyte (c
, readcharfun
);
1910 return make_number (c
);
1915 register char *p
= read_buffer
;
1916 register char *end
= read_buffer
+ read_buffer_size
;
1918 /* Nonzero if we saw an escape sequence specifying
1919 a multibyte character. */
1920 int force_multibyte
= 0;
1921 /* Nonzero if we saw an escape sequence specifying
1922 a single-byte character. */
1923 int force_singlebyte
= 0;
1927 while ((c
= READCHAR
) >= 0
1930 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1932 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1933 p
+= new - read_buffer
;
1934 read_buffer
+= new - read_buffer
;
1935 end
= read_buffer
+ read_buffer_size
;
1940 c
= read_escape (readcharfun
, 1);
1942 /* C is -1 if \ newline has just been seen */
1945 if (p
== read_buffer
)
1950 /* If an escape specifies a non-ASCII single-byte character,
1951 this must be a unibyte string. */
1952 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_META
))
1953 && ! ASCII_BYTE_P (c
))
1954 force_singlebyte
= 1;
1957 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_META
)))
1959 unsigned char workbuf
[4];
1960 unsigned char *str
= workbuf
;
1963 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
1965 force_multibyte
= 1;
1967 bcopy (str
, p
, length
);
1972 /* Allow `\C- ' and `\C-?'. */
1973 if (c
== (CHAR_CTL
| ' '))
1975 else if (c
== (CHAR_CTL
| '?'))
1979 /* Move the meta bit to the right place for a string. */
1980 c
= (c
& ~CHAR_META
) | 0x80;
1982 error ("Invalid modifier in string");
1987 return Fsignal (Qend_of_file
, Qnil
);
1989 /* If purifying, and string starts with \ newline,
1990 return zero instead. This is for doc strings
1991 that we are really going to find in etc/DOC.nn.nn */
1992 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
1993 return make_number (0);
1995 if (force_multibyte
)
1996 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
1997 else if (force_singlebyte
)
1998 nchars
= p
- read_buffer
;
1999 else if (load_convert_to_unibyte
)
2002 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2003 if (p
- read_buffer
!= nchars
)
2005 string
= make_multibyte_string (read_buffer
, nchars
,
2007 return Fstring_make_unibyte (string
);
2010 else if (EQ (readcharfun
, Qget_file_char
)
2011 || EQ (readcharfun
, Qlambda
))
2012 /* Nowadays, reading directly from a file
2013 is used only for compiled Emacs Lisp files,
2014 and those always use the Emacs internal encoding.
2015 Meanwhile, Qlambda is used for reading dynamic byte code
2016 (compiled with byte-compile-dynamic = t). */
2017 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2019 /* In all other cases, if we read these bytes as
2020 separate characters, treat them as separate characters now. */
2021 nchars
= p
- read_buffer
;
2024 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2026 || (p
- read_buffer
!= nchars
)));
2027 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2029 || (p
- read_buffer
!= nchars
)));
2034 #ifdef LISP_FLOAT_TYPE
2035 /* If a period is followed by a number, then we should read it
2036 as a floating point number. Otherwise, it denotes a dotted
2038 int next_char
= READCHAR
;
2041 if (! (next_char
>= '0' && next_char
<= '9'))
2048 /* Otherwise, we fall through! Note that the atom-reading loop
2049 below will now loop at least once, assuring that we will not
2050 try to UNREAD two characters in a row. */
2054 if (c
<= 040) goto retry
;
2056 register char *p
= read_buffer
;
2060 register char *end
= read_buffer
+ read_buffer_size
;
2063 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2064 || c
== '(' || c
== ')'
2065 #ifndef LISP_FLOAT_TYPE
2066 /* If we have floating-point support, then we need
2067 to allow <digits><dot><digits>. */
2069 #endif /* not LISP_FLOAT_TYPE */
2070 || c
== '[' || c
== ']' || c
== '#'
2073 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
2075 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2076 p
+= new - read_buffer
;
2077 read_buffer
+= new - read_buffer
;
2078 end
= read_buffer
+ read_buffer_size
;
2086 if (! SINGLE_BYTE_CHAR_P (c
))
2088 unsigned char workbuf
[4];
2089 unsigned char *str
= workbuf
;
2092 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
2094 bcopy (str
, p
, length
);
2105 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2106 p
+= new - read_buffer
;
2107 read_buffer
+= new - read_buffer
;
2108 /* end = read_buffer + read_buffer_size; */
2115 if (!quoted
&& !uninterned_symbol
)
2118 register Lisp_Object val
;
2120 if (*p1
== '+' || *p1
== '-') p1
++;
2121 /* Is it an integer? */
2124 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2125 #ifdef LISP_FLOAT_TYPE
2126 /* Integers can have trailing decimal points. */
2127 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2130 /* It is an integer. */
2132 #ifdef LISP_FLOAT_TYPE
2136 if (sizeof (int) == sizeof (EMACS_INT
))
2137 XSETINT (val
, atoi (read_buffer
));
2138 else if (sizeof (long) == sizeof (EMACS_INT
))
2139 XSETINT (val
, atol (read_buffer
));
2145 #ifdef LISP_FLOAT_TYPE
2146 if (isfloat_string (read_buffer
))
2148 /* Compute NaN and infinities using 0.0 in a variable,
2149 to cope with compilers that think they are smarter
2155 /* Negate the value ourselves. This treats 0, NaNs,
2156 and infinity properly on IEEE floating point hosts,
2157 and works around a common bug where atof ("-0.0")
2159 int negative
= read_buffer
[0] == '-';
2161 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2162 returns 1, is if the input ends in e+INF or e+NaN. */
2169 value
= zero
/ zero
;
2172 value
= atof (read_buffer
+ negative
);
2176 return make_float (negative
? - value
: value
);
2181 if (uninterned_symbol
)
2182 return make_symbol (read_buffer
);
2184 return intern (read_buffer
);
2190 /* List of nodes we've seen during substitute_object_in_subtree. */
2191 static Lisp_Object seen_list
;
2194 substitute_object_in_subtree (object
, placeholder
)
2196 Lisp_Object placeholder
;
2198 Lisp_Object check_object
;
2200 /* We haven't seen any objects when we start. */
2203 /* Make all the substitutions. */
2205 = substitute_object_recurse (object
, placeholder
, object
);
2207 /* Clear seen_list because we're done with it. */
2210 /* The returned object here is expected to always eq the
2212 if (!EQ (check_object
, object
))
2213 error ("Unexpected mutation error in reader");
2216 /* Feval doesn't get called from here, so no gc protection is needed. */
2217 #define SUBSTITUTE(get_val, set_val) \
2219 Lisp_Object old_value = get_val; \
2220 Lisp_Object true_value \
2221 = substitute_object_recurse (object, placeholder,\
2224 if (!EQ (old_value, true_value)) \
2231 substitute_object_recurse (object
, placeholder
, subtree
)
2233 Lisp_Object placeholder
;
2234 Lisp_Object subtree
;
2236 /* If we find the placeholder, return the target object. */
2237 if (EQ (placeholder
, subtree
))
2240 /* If we've been to this node before, don't explore it again. */
2241 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2244 /* If this node can be the entry point to a cycle, remember that
2245 we've seen it. It can only be such an entry point if it was made
2246 by #n=, which means that we can find it as a value in
2248 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2249 seen_list
= Fcons (subtree
, seen_list
);
2251 /* Recurse according to subtree's type.
2252 Every branch must return a Lisp_Object. */
2253 switch (XTYPE (subtree
))
2255 case Lisp_Vectorlike
:
2258 int length
= Flength(subtree
);
2259 for (i
= 0; i
< length
; i
++)
2261 Lisp_Object idx
= make_number (i
);
2262 SUBSTITUTE (Faref (subtree
, idx
),
2263 Faset (subtree
, idx
, true_value
));
2270 SUBSTITUTE (Fcar_safe (subtree
),
2271 Fsetcar (subtree
, true_value
));
2272 SUBSTITUTE (Fcdr_safe (subtree
),
2273 Fsetcdr (subtree
, true_value
));
2277 #ifdef USE_TEXT_PROPERTIES
2280 /* Check for text properties in each interval.
2281 substitute_in_interval contains part of the logic. */
2283 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2284 Lisp_Object arg
= Fcons (object
, placeholder
);
2286 traverse_intervals (root_interval
, 1, 0,
2287 &substitute_in_interval
, arg
);
2291 #endif /* defined USE_TEXT_PROPERTIES */
2293 /* Other types don't recurse any further. */
2299 /* Helper function for substitute_object_recurse. */
2301 substitute_in_interval (interval
, arg
)
2305 Lisp_Object object
= Fcar (arg
);
2306 Lisp_Object placeholder
= Fcdr (arg
);
2308 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2312 #ifdef LISP_FLOAT_TYPE
2329 if (*cp
== '+' || *cp
== '-')
2332 if (*cp
>= '0' && *cp
<= '9')
2335 while (*cp
>= '0' && *cp
<= '9')
2343 if (*cp
>= '0' && *cp
<= '9')
2346 while (*cp
>= '0' && *cp
<= '9')
2349 if (*cp
== 'e' || *cp
== 'E')
2353 if (*cp
== '+' || *cp
== '-')
2357 if (*cp
>= '0' && *cp
<= '9')
2360 while (*cp
>= '0' && *cp
<= '9')
2363 else if (cp
== start
)
2365 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2370 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2376 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2377 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2378 || state
== (DOT_CHAR
|TRAIL_INT
)
2379 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2380 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2381 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2383 #endif /* LISP_FLOAT_TYPE */
2386 read_vector (readcharfun
, bytecodeflag
)
2387 Lisp_Object readcharfun
;
2392 register Lisp_Object
*ptr
;
2393 register Lisp_Object tem
, item
, vector
;
2394 register struct Lisp_Cons
*otem
;
2397 tem
= read_list (1, readcharfun
);
2398 len
= Flength (tem
);
2399 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2401 size
= XVECTOR (vector
)->size
;
2402 ptr
= XVECTOR (vector
)->contents
;
2403 for (i
= 0; i
< size
; i
++)
2406 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2407 bytecode object, the docstring containing the bytecode and
2408 constants values must be treated as unibyte and passed to
2409 Fread, to get the actual bytecode string and constants vector. */
2410 if (bytecodeflag
&& load_force_doc_strings
)
2412 if (i
== COMPILED_BYTECODE
)
2414 if (!STRINGP (item
))
2415 error ("invalid byte code");
2417 /* Delay handling the bytecode slot until we know whether
2418 it is lazily-loaded (we can tell by whether the
2419 constants slot is nil). */
2420 ptr
[COMPILED_CONSTANTS
] = item
;
2423 else if (i
== COMPILED_CONSTANTS
)
2425 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2429 /* Coerce string to unibyte (like string-as-unibyte,
2430 but without generating extra garbage and
2431 guaranteeing no change in the contents). */
2432 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2433 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2435 item
= Fread (bytestr
);
2437 error ("invalid byte code");
2439 otem
= XCONS (item
);
2440 bytestr
= XCONS (item
)->car
;
2441 item
= XCONS (item
)->cdr
;
2445 /* Now handle the bytecode slot. */
2446 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2449 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2457 /* FLAG = 1 means check for ] to terminate rather than ) and .
2458 FLAG = -1 means check for starting with defun
2459 and make structure pure. */
2462 read_list (flag
, readcharfun
)
2464 register Lisp_Object readcharfun
;
2466 /* -1 means check next element for defun,
2467 0 means don't check,
2468 1 means already checked and found defun. */
2469 int defunflag
= flag
< 0 ? -1 : 0;
2470 Lisp_Object val
, tail
;
2471 register Lisp_Object elt
, tem
;
2472 struct gcpro gcpro1
, gcpro2
;
2473 /* 0 is the normal case.
2474 1 means this list is a doc reference; replace it with the number 0.
2475 2 means this list is a doc reference; replace it with the doc string. */
2476 int doc_reference
= 0;
2478 /* Initialize this to 1 if we are reading a list. */
2479 int first_in_list
= flag
<= 0;
2488 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2493 /* While building, if the list starts with #$, treat it specially. */
2494 if (EQ (elt
, Vload_file_name
)
2496 && !NILP (Vpurify_flag
))
2498 if (NILP (Vdoc_file_name
))
2499 /* We have not yet called Snarf-documentation, so assume
2500 this file is described in the DOC-MM.NN file
2501 and Snarf-documentation will fill in the right value later.
2502 For now, replace the whole list with 0. */
2505 /* We have already called Snarf-documentation, so make a relative
2506 file name for this file, so it can be found properly
2507 in the installed Lisp directory.
2508 We don't use Fexpand_file_name because that would make
2509 the directory absolute now. */
2510 elt
= concat2 (build_string ("../lisp/"),
2511 Ffile_name_nondirectory (elt
));
2513 else if (EQ (elt
, Vload_file_name
)
2515 && load_force_doc_strings
)
2524 Fsignal (Qinvalid_read_syntax
,
2525 Fcons (make_string (") or . in a vector", 18), Qnil
));
2533 XCONS (tail
)->cdr
= read0 (readcharfun
);
2535 val
= read0 (readcharfun
);
2536 read1 (readcharfun
, &ch
, 0);
2540 if (doc_reference
== 1)
2541 return make_number (0);
2542 if (doc_reference
== 2)
2544 /* Get a doc string from the file we are loading.
2545 If it's in saved_doc_string, get it from there. */
2546 int pos
= XINT (XCONS (val
)->cdr
);
2547 /* Position is negative for user variables. */
2548 if (pos
< 0) pos
= -pos
;
2549 if (pos
>= saved_doc_string_position
2550 && pos
< (saved_doc_string_position
2551 + saved_doc_string_length
))
2553 int start
= pos
- saved_doc_string_position
;
2556 /* Process quoting with ^A,
2557 and find the end of the string,
2558 which is marked with ^_ (037). */
2559 for (from
= start
, to
= start
;
2560 saved_doc_string
[from
] != 037;)
2562 int c
= saved_doc_string
[from
++];
2565 c
= saved_doc_string
[from
++];
2567 saved_doc_string
[to
++] = c
;
2569 saved_doc_string
[to
++] = 0;
2571 saved_doc_string
[to
++] = 037;
2574 saved_doc_string
[to
++] = c
;
2577 return make_string (saved_doc_string
+ start
,
2580 /* Look in prev_saved_doc_string the same way. */
2581 else if (pos
>= prev_saved_doc_string_position
2582 && pos
< (prev_saved_doc_string_position
2583 + prev_saved_doc_string_length
))
2585 int start
= pos
- prev_saved_doc_string_position
;
2588 /* Process quoting with ^A,
2589 and find the end of the string,
2590 which is marked with ^_ (037). */
2591 for (from
= start
, to
= start
;
2592 prev_saved_doc_string
[from
] != 037;)
2594 int c
= prev_saved_doc_string
[from
++];
2597 c
= prev_saved_doc_string
[from
++];
2599 prev_saved_doc_string
[to
++] = c
;
2601 prev_saved_doc_string
[to
++] = 0;
2603 prev_saved_doc_string
[to
++] = 037;
2606 prev_saved_doc_string
[to
++] = c
;
2609 return make_string (prev_saved_doc_string
+ start
,
2613 return get_doc_string (val
, 0, 0);
2618 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2620 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2622 tem
= (read_pure
&& flag
<= 0
2623 ? pure_cons (elt
, Qnil
)
2624 : Fcons (elt
, Qnil
));
2626 XCONS (tail
)->cdr
= tem
;
2631 defunflag
= EQ (elt
, Qdefun
);
2632 else if (defunflag
> 0)
2637 Lisp_Object Vobarray
;
2638 Lisp_Object initial_obarray
;
2640 /* oblookup stores the bucket number here, for the sake of Funintern. */
2642 int oblookup_last_bucket_number
;
2644 static int hash_string ();
2645 Lisp_Object
oblookup ();
2647 /* Get an error if OBARRAY is not an obarray.
2648 If it is one, return it. */
2651 check_obarray (obarray
)
2652 Lisp_Object obarray
;
2654 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2656 /* If Vobarray is now invalid, force it to be valid. */
2657 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2659 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2664 /* Intern the C string STR: return a symbol with that name,
2665 interned in the current obarray. */
2672 int len
= strlen (str
);
2673 Lisp_Object obarray
;
2676 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2677 obarray
= check_obarray (obarray
);
2678 tem
= oblookup (obarray
, str
, len
, len
);
2681 return Fintern (make_string (str
, len
), obarray
);
2684 /* Create an uninterned symbol with name STR. */
2690 int len
= strlen (str
);
2692 return Fmake_symbol ((!NILP (Vpurify_flag
)
2693 ? make_pure_string (str
, len
, len
, 0)
2694 : make_string (str
, len
)));
2697 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2698 "Return the canonical symbol whose name is STRING.\n\
2699 If there is none, one is created by this function and returned.\n\
2700 A second optional argument specifies the obarray to use;\n\
2701 it defaults to the value of `obarray'.")
2703 Lisp_Object string
, obarray
;
2705 register Lisp_Object tem
, sym
, *ptr
;
2707 if (NILP (obarray
)) obarray
= Vobarray
;
2708 obarray
= check_obarray (obarray
);
2710 CHECK_STRING (string
, 0);
2712 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2713 XSTRING (string
)->size
,
2714 STRING_BYTES (XSTRING (string
)));
2715 if (!INTEGERP (tem
))
2718 if (!NILP (Vpurify_flag
))
2719 string
= Fpurecopy (string
);
2720 sym
= Fmake_symbol (string
);
2721 XSYMBOL (sym
)->obarray
= obarray
;
2723 if ((XSTRING (string
)->data
[0] == ':')
2724 && EQ (obarray
, initial_obarray
))
2725 XSYMBOL (sym
)->value
= sym
;
2727 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2729 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2731 XSYMBOL (sym
)->next
= 0;
2736 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2737 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
2738 A second optional argument specifies the obarray to use;\n\
2739 it defaults to the value of `obarray'.")
2741 Lisp_Object string
, obarray
;
2743 register Lisp_Object tem
;
2745 if (NILP (obarray
)) obarray
= Vobarray
;
2746 obarray
= check_obarray (obarray
);
2748 CHECK_STRING (string
, 0);
2750 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2751 XSTRING (string
)->size
,
2752 STRING_BYTES (XSTRING (string
)));
2753 if (!INTEGERP (tem
))
2758 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2759 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2760 The value is t if a symbol was found and deleted, nil otherwise.\n\
2761 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2762 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2763 OBARRAY defaults to the value of the variable `obarray'.")
2765 Lisp_Object name
, obarray
;
2767 register Lisp_Object string
, tem
;
2770 if (NILP (obarray
)) obarray
= Vobarray
;
2771 obarray
= check_obarray (obarray
);
2774 XSETSTRING (string
, XSYMBOL (name
)->name
);
2777 CHECK_STRING (name
, 0);
2781 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2782 XSTRING (string
)->size
,
2783 STRING_BYTES (XSTRING (string
)));
2786 /* If arg was a symbol, don't delete anything but that symbol itself. */
2787 if (SYMBOLP (name
) && !EQ (name
, tem
))
2790 XSYMBOL (tem
)->obarray
= Qnil
;
2792 hash
= oblookup_last_bucket_number
;
2794 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2796 if (XSYMBOL (tem
)->next
)
2797 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2799 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2803 Lisp_Object tail
, following
;
2805 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2806 XSYMBOL (tail
)->next
;
2809 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2810 if (EQ (following
, tem
))
2812 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2821 /* Return the symbol in OBARRAY whose names matches the string
2822 of SIZE characters (SIZE_BYTE bytes) at PTR.
2823 If there is no such symbol in OBARRAY, return nil.
2825 Also store the bucket number in oblookup_last_bucket_number. */
2828 oblookup (obarray
, ptr
, size
, size_byte
)
2829 Lisp_Object obarray
;
2831 int size
, size_byte
;
2835 register Lisp_Object tail
;
2836 Lisp_Object bucket
, tem
;
2838 if (!VECTORP (obarray
)
2839 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2841 obarray
= check_obarray (obarray
);
2842 obsize
= XVECTOR (obarray
)->size
;
2844 /* This is sometimes needed in the middle of GC. */
2845 obsize
&= ~ARRAY_MARK_FLAG
;
2846 /* Combining next two lines breaks VMS C 2.3. */
2847 hash
= hash_string (ptr
, size_byte
);
2849 bucket
= XVECTOR (obarray
)->contents
[hash
];
2850 oblookup_last_bucket_number
= hash
;
2851 if (XFASTINT (bucket
) == 0)
2853 else if (!SYMBOLP (bucket
))
2854 error ("Bad data in guts of obarray"); /* Like CADR error message */
2856 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2858 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2859 && XSYMBOL (tail
)->name
->size
== size
2860 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2862 else if (XSYMBOL (tail
)->next
== 0)
2865 XSETINT (tem
, hash
);
2870 hash_string (ptr
, len
)
2874 register unsigned char *p
= ptr
;
2875 register unsigned char *end
= p
+ len
;
2876 register unsigned char c
;
2877 register int hash
= 0;
2882 if (c
>= 0140) c
-= 40;
2883 hash
= ((hash
<<3) + (hash
>>28) + c
);
2885 return hash
& 07777777777;
2889 map_obarray (obarray
, fn
, arg
)
2890 Lisp_Object obarray
;
2891 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2895 register Lisp_Object tail
;
2896 CHECK_VECTOR (obarray
, 1);
2897 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2899 tail
= XVECTOR (obarray
)->contents
[i
];
2904 if (XSYMBOL (tail
)->next
== 0)
2906 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2912 mapatoms_1 (sym
, function
)
2913 Lisp_Object sym
, function
;
2915 call1 (function
, sym
);
2918 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2919 "Call FUNCTION on every symbol in OBARRAY.\n\
2920 OBARRAY defaults to the value of `obarray'.")
2922 Lisp_Object function
, obarray
;
2926 if (NILP (obarray
)) obarray
= Vobarray
;
2927 obarray
= check_obarray (obarray
);
2929 map_obarray (obarray
, mapatoms_1
, function
);
2933 #define OBARRAY_SIZE 1511
2938 Lisp_Object oblength
;
2942 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2944 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2945 Vobarray
= Fmake_vector (oblength
, make_number (0));
2946 initial_obarray
= Vobarray
;
2947 staticpro (&initial_obarray
);
2948 /* Intern nil in the obarray */
2949 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2950 /* These locals are to kludge around a pyramid compiler bug. */
2951 hash
= hash_string ("nil", 3);
2952 /* Separate statement here to avoid VAXC bug. */
2953 hash
%= OBARRAY_SIZE
;
2954 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2957 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2958 XSYMBOL (Qnil
)->function
= Qunbound
;
2959 XSYMBOL (Qunbound
)->value
= Qunbound
;
2960 XSYMBOL (Qunbound
)->function
= Qunbound
;
2963 XSYMBOL (Qnil
)->value
= Qnil
;
2964 XSYMBOL (Qnil
)->plist
= Qnil
;
2965 XSYMBOL (Qt
)->value
= Qt
;
2967 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2970 Qvariable_documentation
= intern ("variable-documentation");
2971 staticpro (&Qvariable_documentation
);
2973 read_buffer_size
= 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM
;
2974 read_buffer
= (char *) malloc (read_buffer_size
);
2979 struct Lisp_Subr
*sname
;
2982 sym
= intern (sname
->symbol_name
);
2983 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2986 #ifdef NOTDEF /* use fset in subr.el now */
2988 defalias (sname
, string
)
2989 struct Lisp_Subr
*sname
;
2993 sym
= intern (string
);
2994 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2998 /* Define an "integer variable"; a symbol whose value is forwarded
2999 to a C variable of type int. Sample call: */
3000 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3002 defvar_int (namestring
, address
)
3006 Lisp_Object sym
, val
;
3007 sym
= intern (namestring
);
3008 val
= allocate_misc ();
3009 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
3010 XINTFWD (val
)->intvar
= address
;
3011 XSYMBOL (sym
)->value
= val
;
3014 /* Similar but define a variable whose value is T if address contains 1,
3015 NIL if address contains 0 */
3017 defvar_bool (namestring
, address
)
3021 Lisp_Object sym
, val
;
3022 sym
= intern (namestring
);
3023 val
= allocate_misc ();
3024 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
3025 XBOOLFWD (val
)->boolvar
= address
;
3026 XSYMBOL (sym
)->value
= val
;
3029 /* Similar but define a variable whose value is the Lisp Object stored
3030 at address. Two versions: with and without gc-marking of the C
3031 variable. The nopro version is used when that variable will be
3032 gc-marked for some other reason, since marking the same slot twice
3033 can cause trouble with strings. */
3035 defvar_lisp_nopro (namestring
, address
)
3037 Lisp_Object
*address
;
3039 Lisp_Object sym
, val
;
3040 sym
= intern (namestring
);
3041 val
= allocate_misc ();
3042 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3043 XOBJFWD (val
)->objvar
= address
;
3044 XSYMBOL (sym
)->value
= val
;
3048 defvar_lisp (namestring
, address
)
3050 Lisp_Object
*address
;
3052 defvar_lisp_nopro (namestring
, address
);
3053 staticpro (address
);
3058 /* Similar but define a variable whose value is the Lisp Object stored in
3059 the current buffer. address is the address of the slot in the buffer
3060 that is current now. */
3063 defvar_per_buffer (namestring
, address
, type
, doc
)
3065 Lisp_Object
*address
;
3069 Lisp_Object sym
, val
;
3071 extern struct buffer buffer_local_symbols
;
3073 sym
= intern (namestring
);
3074 val
= allocate_misc ();
3075 offset
= (char *)address
- (char *)current_buffer
;
3077 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3078 XBUFFER_OBJFWD (val
)->offset
= offset
;
3079 XSYMBOL (sym
)->value
= val
;
3080 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
3081 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
3082 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
3083 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3084 slot of buffer_local_flags */
3088 #endif /* standalone */
3090 /* Similar but define a variable whose value is the Lisp Object stored
3091 at a particular offset in the current kboard object. */
3094 defvar_kboard (namestring
, offset
)
3098 Lisp_Object sym
, val
;
3099 sym
= intern (namestring
);
3100 val
= allocate_misc ();
3101 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3102 XKBOARD_OBJFWD (val
)->offset
= offset
;
3103 XSYMBOL (sym
)->value
= val
;
3106 /* Record the value of load-path used at the start of dumping
3107 so we can see if the site changed it later during dumping. */
3108 static Lisp_Object dump_path
;
3114 int turn_off_warning
= 0;
3116 #ifdef HAVE_SETLOCALE
3117 /* Make sure numbers are parsed as we expect. */
3118 setlocale (LC_NUMERIC
, "C");
3119 #endif /* HAVE_SETLOCALE */
3121 /* Compute the default load-path. */
3123 normal
= PATH_LOADSEARCH
;
3124 Vload_path
= decode_env_path (0, normal
);
3126 if (NILP (Vpurify_flag
))
3127 normal
= PATH_LOADSEARCH
;
3129 normal
= PATH_DUMPLOADSEARCH
;
3131 /* In a dumped Emacs, we normally have to reset the value of
3132 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3133 uses ../lisp, instead of the path of the installed elisp
3134 libraries. However, if it appears that Vload_path was changed
3135 from the default before dumping, don't override that value. */
3138 if (! NILP (Fequal (dump_path
, Vload_path
)))
3140 Vload_path
= decode_env_path (0, normal
);
3141 if (!NILP (Vinstallation_directory
))
3143 /* Add to the path the lisp subdir of the
3144 installation dir, if it exists. */
3145 Lisp_Object tem
, tem1
;
3146 tem
= Fexpand_file_name (build_string ("lisp"),
3147 Vinstallation_directory
);
3148 tem1
= Ffile_exists_p (tem
);
3151 if (NILP (Fmember (tem
, Vload_path
)))
3153 turn_off_warning
= 1;
3154 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3158 /* That dir doesn't exist, so add the build-time
3159 Lisp dirs instead. */
3160 Vload_path
= nconc2 (Vload_path
, dump_path
);
3162 /* Add leim under the installation dir, if it exists. */
3163 tem
= Fexpand_file_name (build_string ("leim"),
3164 Vinstallation_directory
);
3165 tem1
= Ffile_exists_p (tem
);
3168 if (NILP (Fmember (tem
, Vload_path
)))
3169 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3172 /* Add site-list under the installation dir, if it exists. */
3173 tem
= Fexpand_file_name (build_string ("site-lisp"),
3174 Vinstallation_directory
);
3175 tem1
= Ffile_exists_p (tem
);
3178 if (NILP (Fmember (tem
, Vload_path
)))
3179 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3182 /* If Emacs was not built in the source directory,
3183 and it is run from where it was built, add to load-path
3184 the lisp, leim and site-lisp dirs under that directory. */
3186 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3190 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3191 Vinstallation_directory
);
3192 tem1
= Ffile_exists_p (tem
);
3194 /* Don't be fooled if they moved the entire source tree
3195 AFTER dumping Emacs. If the build directory is indeed
3196 different from the source dir, src/Makefile.in and
3197 src/Makefile will not be found together. */
3198 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3199 Vinstallation_directory
);
3200 tem2
= Ffile_exists_p (tem
);
3201 if (!NILP (tem1
) && NILP (tem2
))
3203 tem
= Fexpand_file_name (build_string ("lisp"),
3206 if (NILP (Fmember (tem
, Vload_path
)))
3207 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3209 tem
= Fexpand_file_name (build_string ("leim"),
3212 if (NILP (Fmember (tem
, Vload_path
)))
3213 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3215 tem
= Fexpand_file_name (build_string ("site-lisp"),
3218 if (NILP (Fmember (tem
, Vload_path
)))
3219 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3227 /* NORMAL refers to the lisp dir in the source directory. */
3228 /* We used to add ../lisp at the front here, but
3229 that caused trouble because it was copied from dump_path
3230 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3231 It should be unnecessary. */
3232 Vload_path
= decode_env_path (0, normal
);
3233 dump_path
= Vload_path
;
3238 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3239 almost never correct, thereby causing a warning to be printed out that
3240 confuses users. Since PATH_LOADSEARCH is always overridden by the
3241 EMACSLOADPATH environment variable below, disable the warning on NT. */
3243 /* Warn if dirs in the *standard* path don't exist. */
3244 if (!turn_off_warning
)
3246 Lisp_Object path_tail
;
3248 for (path_tail
= Vload_path
;
3250 path_tail
= XCONS (path_tail
)->cdr
)
3252 Lisp_Object dirfile
;
3253 dirfile
= Fcar (path_tail
);
3254 if (STRINGP (dirfile
))
3256 dirfile
= Fdirectory_file_name (dirfile
);
3257 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3258 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3259 XCONS (path_tail
)->car
);
3263 #endif /* WINDOWSNT */
3265 /* If the EMACSLOADPATH environment variable is set, use its value.
3266 This doesn't apply if we're dumping. */
3268 if (NILP (Vpurify_flag
)
3269 && egetenv ("EMACSLOADPATH"))
3271 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3275 load_in_progress
= 0;
3276 Vload_file_name
= Qnil
;
3278 load_descriptor_list
= Qnil
;
3280 Vstandard_input
= Qt
;
3283 /* Print a warning, using format string FORMAT, that directory DIRNAME
3284 does not exist. Print it on stderr and put it in *Message*. */
3287 dir_warning (format
, dirname
)
3289 Lisp_Object dirname
;
3292 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3294 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3295 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3296 /* Don't log the warning before we've initialized!! */
3298 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3305 defsubr (&Sread_from_string
);
3307 defsubr (&Sintern_soft
);
3308 defsubr (&Sunintern
);
3310 defsubr (&Seval_buffer
);
3311 defsubr (&Seval_region
);
3312 defsubr (&Sread_char
);
3313 defsubr (&Sread_char_exclusive
);
3314 defsubr (&Sread_event
);
3315 defsubr (&Sget_file_char
);
3316 defsubr (&Smapatoms
);
3318 DEFVAR_LISP ("obarray", &Vobarray
,
3319 "Symbol table for use by `intern' and `read'.\n\
3320 It is a vector whose length ought to be prime for best results.\n\
3321 The vector's contents don't make sense if examined from Lisp programs;\n\
3322 to find all the symbols in an obarray, use `mapatoms'.");
3324 DEFVAR_LISP ("values", &Vvalues
,
3325 "List of values of all expressions which were read, evaluated and printed.\n\
3326 Order is reverse chronological.");
3328 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3329 "Stream for read to get input from.\n\
3330 See documentation of `read' for possible values.");
3331 Vstandard_input
= Qt
;
3333 DEFVAR_LISP ("load-path", &Vload_path
,
3334 "*List of directories to search for files to load.\n\
3335 Each element is a string (directory name) or nil (try default directory).\n\
3336 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3337 otherwise to default specified by file `epaths.h' when Emacs was built.");
3339 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3340 "Non-nil iff inside of `load'.");
3342 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3343 "An alist of expressions to be evalled when particular files are loaded.\n\
3344 Each element looks like (FILENAME FORMS...).\n\
3345 When `load' is run and the file-name argument is FILENAME,\n\
3346 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3347 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3348 with no directory specified, since that is how `load' is normally called.\n\
3349 An error in FORMS does not undo the load,\n\
3350 but does prevent execution of the rest of the FORMS.");
3351 Vafter_load_alist
= Qnil
;
3353 DEFVAR_LISP ("load-history", &Vload_history
,
3354 "Alist mapping source file names to symbols and features.\n\
3355 Each alist element is a list that starts with a file name,\n\
3356 except for one element (optional) that starts with nil and describes\n\
3357 definitions evaluated from buffers not visiting files.\n\
3358 The remaining elements of each list are symbols defined as functions\n\
3359 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3360 Vload_history
= Qnil
;
3362 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3363 "Full name of file being loaded by `load'.");
3364 Vload_file_name
= Qnil
;
3366 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3367 "File name, including directory, of user's initialization file.");
3368 Vuser_init_file
= Qnil
;
3370 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3371 "Used for internal purposes by `load'.");
3372 Vcurrent_load_list
= Qnil
;
3374 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3375 "Function used by `load' and `eval-region' for reading expressions.\n\
3376 The default is nil, which means use the function `read'.");
3377 Vload_read_function
= Qnil
;
3379 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3380 "Function called in `load' for loading an Emacs lisp source file.\n\
3381 This function is for doing code conversion before reading the source file.\n\
3382 If nil, loading is done without any code conversion.\n\
3383 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3384 FULLNAME is the full name of FILE.\n\
3385 See `load' for the meaning of the remaining arguments.");
3386 Vload_source_file_function
= Qnil
;
3388 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3389 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3390 This is useful when the file being loaded is a temporary copy.");
3391 load_force_doc_strings
= 0;
3393 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3394 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3395 This is normally used in `load-with-code-conversion'\n\
3396 for loading non-compiled files.");
3397 load_convert_to_unibyte
= 0;
3399 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3400 "Directory in which Emacs sources were found when Emacs was built.\n\
3401 You cannot count on them to still be there!");
3403 = Fexpand_file_name (build_string ("../"),
3404 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3406 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3407 "List of files that were preloaded (when dumping Emacs).");
3408 Vpreloaded_file_list
= Qnil
;
3410 /* Vsource_directory was initialized in init_lread. */
3412 load_descriptor_list
= Qnil
;
3413 staticpro (&load_descriptor_list
);
3415 Qcurrent_load_list
= intern ("current-load-list");
3416 staticpro (&Qcurrent_load_list
);
3418 Qstandard_input
= intern ("standard-input");
3419 staticpro (&Qstandard_input
);
3421 Qread_char
= intern ("read-char");
3422 staticpro (&Qread_char
);
3424 Qget_file_char
= intern ("get-file-char");
3425 staticpro (&Qget_file_char
);
3427 Qbackquote
= intern ("`");
3428 staticpro (&Qbackquote
);
3429 Qcomma
= intern (",");
3430 staticpro (&Qcomma
);
3431 Qcomma_at
= intern (",@");
3432 staticpro (&Qcomma_at
);
3433 Qcomma_dot
= intern (",.");
3434 staticpro (&Qcomma_dot
);
3436 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3437 staticpro (&Qinhibit_file_name_operation
);
3439 Qascii_character
= intern ("ascii-character");
3440 staticpro (&Qascii_character
);
3442 Qfunction
= intern ("function");
3443 staticpro (&Qfunction
);
3445 Qload
= intern ("load");
3448 Qload_file_name
= intern ("load-file-name");
3449 staticpro (&Qload_file_name
);
3451 staticpro (&dump_path
);
3453 staticpro (&read_objects
);
3454 read_objects
= Qnil
;
3455 staticpro (&seen_list
);